Class: StripeController
Instance Method Summary
collapse
#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token
Instance Method Details
#checkout_session ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'app/controllers/stripe_controller.rb', line 7
def checkout_session
session_id = params[:session_id]
session = Stripe::Checkout::Session.retrieve({
id: session_id,
expand: ['customer']
})
render json: { session: session }
end
|
#webhooks ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'app/controllers/stripe_controller.rb', line 16
def webhooks
webhook_secret = '{{STRIPE_WEBHOOK_SECRET}}'
payload = request.body.read
if webhook_secret.empty?
data = JSON.parse(payload, symbolize_names: true)
event = Stripe::Event.construct_from(data)
else
= request.env['HTTP_STRIPE_SIGNATURE']
event = nil
begin
event = Stripe::Webhook.construct_event(
payload, , webhook_secret
)
rescue JSON::ParserError
status 400
return
rescue Stripe::SignatureVerificationError
puts '⚠️ Webhook signature verification failed.'
status 400
return
end
end
event_type = event['type']
data = event['data']
data['object']
case event_type
when 'checkout.session.completed'
when 'invoice.paid'
when 'invoice.payment_failed'
when 'customer.subscription.deleted'
else
puts "Unhandled event type: \#{event.type}"
end
status 200
end
|