stripe-paymentslaravel-cashier

What is the best way of handling a new PaymentIntent in Laravel Cashier


Unless I'm missing something, I cannot see any Cashier wrapper to provide the creation of a PaymentIntent, does this exist?

While Cashier v10 added some content to handle SCA it doesn't work for me because I am handling payment details via a font-end element, so redirecting to a new route is messy.

I need to handle it as per this guide https://stripe.com/docs/payments/payment-intents/migration

Which requires the creation of a PaymentIntent like so:

$intent = \Stripe\PaymentIntent::create([
    'payment_method' => $json_obj->payment_method_id,
    'amount' => 1099,
    'currency' => 'gbp',
    'confirmation_method' => 'manual',
    'confirm' => true,
]);

I can of course do this directly from the Stripe sdk as shown here, but given I am likely to add more functionality that will likely make use of Cashier's other features it would keep it cleaner to go through Cashier for everything.

Can I create a PaymentIntent via Cashier or has that been missed off? If so, how? Or should I be handling this differently?


Solution

  • Having investigated this further, the answer is that the

    Laravel\Cashier\Billable->charge($amount,$method,$options)
    

    method does a \Stripe\PaymentIntent::create($options) under the covers.

    There are some things to be aware of:

    And finally, if you require SCA (which I did) then you must catch a \Laravel\Cashier\Exceptions\PaymentActionRequired exception and either redirect to the built-in Cashier page for this, or handle it in your front-end via your API request.