I have a tiny rails application. Currently, the subscriptions are active with my application with Stripe & Pay Gem, Which is pretty straightforward. But now I am having an issue or I don't know how I can add some custom action after successful payment.
So here is what I want to do.
I have a model called Theme & the Model has a file field. Now I want after the payment user will get an email with the link of the file.
Anyone here can give me some direction on how can I do it?
Update:
I have got some codes from pay documentation But don't know how to implement them.
Pay::Webhooks.delegator.subscribe "stripe.checkout.session.completed", FulfillCheckout.new
Pay::Webhooks.delegator.subscribe "stripe.checkout.session.async_payment_succeeded", FulfillCheckout.new
class FulfillCheckout
def call(event)
object = event.data.object
if object.payment_status == "paid"
# Handle fulfillment
end
end
end
If anyone can guide me through this?
Thanks
CodePudding user response:
I haven't used the Pay Gem before, but in the docs, there's a description as to what needs to be done after getting a successful payment:
Fulfilling orders after Checkout completed
For one-time payments, you'll need to add a webhook listener for the Checkout stripe.checkout.session.completed and stripe.checkout.session.async_payment_succeeded events. Some payment methods are delayed so you need to verify the payment_status == "paid". The async payment succeeded event fires when delayed payments are complete.
So based on that, in your webhook listener, you would trigger an SMTP or some other way of emailing and have a link to the theme.file_name
. This is handled differently based on how you are delivering emails to your users.
CodePudding user response:
Managed to solve it by adding
Pay::Webhooks.delegator.subscribe "stripe.checkout.session.completed", FulfillCheckout.new Pay::Webhooks.delegator.subscribe "stripe.checkout.session.async_payment_succeeded", FulfillCheckout.new
to Pay Initializer file