CherryPoppins
CherryPoppins

Reputation: 79

Stripe collect payment later workflow Node/Express/EJS

I am working on the payment portion of an app using Stripe and having trouble trying to figure out the best way to route customers. Essentially, the way the app is supposed to work is:

  1. Customer goes to site to enters payment details.
  2. Payment is broken into two parts the Fee and the Deposit.
  3. Customer submits payment details.
  4. If the funds are validated they are brought to a success page.
  5. If the funds are not validated they get an error page.
  6. Later, the funds are captured either with or without the deposit amount.

I have Stripe set up where I am creating the payment intent with capture_method: 'manual' set so I can capture the funds later. I am passing the client secret to the front via EJS, and using stripe.confirmCardPayment() to 'run' the card. All of that seems to be working fine and they are correctly showing up in my Stripe dashboard as uncaptured payments. So, from here what is the best way to route the user to the correct page after the card is 'run'. In other words, if the funds are there then route to success pages, otherwise route to an error page. There needs to be some validation on the server side otherwise the customer could just directly visit the success page route without paying. Thanks for any help and ideas!

Upvotes: 0

Views: 196

Answers (1)

hmunoz
hmunoz

Reputation: 3361

stripe.confirmCardPayment returns a Promise that resolves with result.error if there were errors (like the charge declined) or with result.paymentIntent if the PaymentIntent confirmation succeeds: https://stripe.com/docs/js/payment_intents/confirm_card_payment

Once your confirmCardPayment() Promise resolves, you can look at result.paymentIntent.status (which in your case would be requires_capture).

During this, you can make any arbitrary calls to your server (like pass the PaymentIntent/Customer ID and update your database) and then redirect your customer to the success/failure page accordingly.

Upvotes: 1

Related Questions