Cartalyst Stripe (PHP) advice required

57 views Asked by At

Everything I read seems to be about Laravel.

I am using Cartalyst v2 with PHP for a Stripe payment endpoint.

I have worked out I need to use paymentIntents in order to take payment, and then wait for the webhook to get fired. This makes sense.

However, what I am confused about, is where does the customer enter payment details? If I create a PaymentIntent object, how do I then redirect them to a payment form? I was originally collecting payment data and then used Stripe to create a charge, but I was told this isn't safe these days.

So, how do I get from the payment intent to the payment gateway?

Please. Thanks

1

There are 1 answers

2
Lucky2501 On BEST ANSWER

What you did before with Charges:
1 - Create and mount card element on frontend.
2 - When customer submits, create card Token using element from frontend.
3 - Create Charge with Token from backend.

What the official flow is with Payment Intents:
1 - Create Payment Intent from backend.
This gives you a client_secret.

2 - Create and mount element on frontend.
This could still be the card element, however Stripe would really like you to use their new payment element.

3 - When customer submits, confirm the Payment Intent using its client_secret from the frontend.
This confirmation (using confirmPayment for payment element / confirmCardPayment for card element) achieves three things:
-If the payment requires authentication, it performs it.
-It the attempt to charge the payment method collected with elements. -If the charge succeeds, the Payment Method object is also returned. If the Charge fails, you Payment Intent can be confirmed again to attempt a new Charge, without having to start the entire process over.

This flow does actions in more or less the opposite order than the old Charges API. While it's technically possible to process Payment Intents in the old order, this way is more optimal in case your payments need to be authenticated.

Finally, about this:

how do I then redirect them to a payment form?

That's not how Elements work - you design your own form.
What you're describing here sounds more like Stripe Checkout, which is nothing like Charges or Payment Intents with Elements:
https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout