Files
MatchLiveTv/backend/app/controllers/webhooks/stripe_controller.rb
Emiliano Frascaro bba6df52c0 Initial commit: monorepo Match Live TV.
Rails API, app Flutter, infrastruttura Docker/MediaMTX, sito marketing e documentazione di deploy.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-26 17:45:37 +02:00

33 lines
907 B
Ruby

module Webhooks
class StripeController < ActionController::API
def create
payload = request.body.read
sig_header = request.env["HTTP_STRIPE_SIGNATURE"]
unless MatchLiveTv.stripe_webhook_secret.present?
Rails.logger.info("[Stripe webhook] ignored — STRIPE_WEBHOOK_SECRET not set")
return head :ok
end
event = ::Stripe::Webhook.construct_event(
payload, sig_header, MatchLiveTv.stripe_webhook_secret
)
Billing::Stripe::WebhookHandler.call(event)
head :ok
rescue JSON::ParserError, ::Stripe::SignatureVerificationError => e
Rails.logger.warn("[Stripe webhook] #{e.message}")
head :bad_request
end
private
def stripe_object_from_hash(hash)
OpenStruct.new(hash.transform_keys(&:to_s).transform_values do |v|
v.is_a?(Hash) ? stripe_object_from_hash(v) : v
end)
end
end
end