Hey there,
I’m integrating Stripe’s API into my app and I wanted to ask what would be the most effective way to accomplish the following:
I have a workflow that looks like this:
I want Step 3 onwards to only be triggered if the user has actually completed the payment in the Checkout session I created. Result of Step 1 does not return any success or failure value I could use, only has success URL and failure URL that are used to redirect the user depending on what happens in the checkout session.
Before this set up, I was using Stripe plugin and it was taking care of this on its own (workflow was terminating in case the user didn’t complete the payment). However, Stripe plugin does not handle automatic tax calculation, hence I’ve been forced to set this up manually and have more control over it.
One option I know I could pursue is set up a webhook that listens to charge.success and take it from there, but wanted to check here first whether there is a simpler way of achieving this?
Many thanks!
I’d use a webhook, and do it all on the backend.
I may not completely understand what you want to do, but this might be an option.
-
Move all of the steps you want to perform only if the payment is successful into a single custom event.
-
Call the custom event with the condition of whether the payment was captured or not.
Again, this may not work at all, but it’s the first thing I thought of.
Problem is that I need to pass on parameters to that backend workflow to make appropriate changes, but I don’t seem to be able to do so?
For example prior to the checkout screen, the user has provided inputs to create a new thing of type “Referral request”. I don’t want this referral request to be created unless the payment has been successful. So, how would I retrieve these inputs from the backend workflow so that I can create it from there?
- Move all of the steps you want to perform only if the payment is successful into a single custom event.
- Call the custom event with the condition of whether the payment was captured or not.
Problem is that Stripe’s checkout session does not return a “Success” or “Failure” response upon its completion, this only can be done via Webhooks. Therefore, I wouldn’t be able to create a Custom Event (because I wouldn’t have a trigger for it)… It’s something that would have to be done in the backend, but not sure how to pass on parameters to the webhook listener
For example prior to the checkout screen, the user has provided inputs to create a new thing of type “Referral request”. I don’t want this referral request to be created unless the payment has been successful. So, how would I retrieve these inputs from the backend workflow so that I can create it from there?
You need to pass the parameters into the Stripe API call (as metadata), so you can retrieve them from the webhook payload.
Personally, I would create the Referral request before redirecting the User to Stripe checkout - then you can just include the unique ID of that in the API call, and retrieve it on the back end. You can always delete it if the payment is not complete.
Alternatively, you can pass all the information you need as individual metadata parameters and then retrieve them on the backend to create your Referral request then.
Problem is that Stripe’s checkout session does not return a “Success” or “Failure” response upon its completion, this only can be done via Webhooks.
That’s not strictly true… you can include the Stripe Checkout ID in the success URL, then retrieve the checkout session from that, so you can do all the same thing on the front end.
It’s just not as reliable as using a webhook.
You need to pass the parameters into the Stripe API call (as metadata), so you can retrieve them from the webhook payload.
Personally, I would create the Referral request before redirecting the User to Stripe checkout - then you can just include the unique ID of that in the API call, and retrieve it on the back end. You can always delete it if the payment is not complete.
Thanks Adam, I quite like that approach, hadn’t use the metadata parameters until now, so I’m going to give it a try!
1 Like