sercan
sercan

Reputation: 351

Laravel Cashier - Stripe Multiple Payment Method

I'm using Laravel Cashier with Stripe for my restaurant.

I want to use multiple payment methods that Stripe supports for my customers, but i couldn't find any information about using multiple payment methods with Stripe in the Laravel Cashier documentation.

The Accept a Payment document in Stripe's documentation is exactly what I need. Is there a way to implement the method described in this document with Laravel Cashier?

Upvotes: 0

Views: 1960

Answers (2)

yuting
yuting

Reputation: 1684

The SetupIntent created for collecting a payment method is default to accept card only. In addition, the frontend also only uses Card Element in the Laravel Cashier doc which is meant for collecting card information.

To accept other payment method types, you'll first create a SetupIntent with other payment_method_types at server, then pass to client secret to Payment Element instead of Card Element to render. Payment Element allows one or multiple payment methods. For more information, you can refer to the doc here: https://stripe.com/docs/payments/save-and-reuse

Please note that not all payment methods support SetupIntent (for future usage). You may refer to the doc here for the payment methods that support SetupIntent: https://stripe.com/docs/payments/payment-methods/integration-options#additional-api-supportability

Upvotes: 0

silver
silver

Reputation: 5311

this requires to run both php and js script to stripe,

its reference here

you first need a setup intent, which you have to call using

return $user->createSetupIntent();

and access the value on the front-end. on your card/payment page, you have to set-up the stripe js card elements. then capture and process the card elements like example below (uses axios)

const { setupIntent, error } = await stripe.confirmCardSetup(your_SETUP_INTENT, {
  payment_method: {
    card: your_card_object,
    billing_details: { name: 'Card Name' }
  }
})

if (error) {
  console.log(error)
} else {
  const { data } = await axios.post('/api/payment-method', { card: setupIntent.payment_method })
}

once the request to stripe is successful, you'll get payment method id, which you can push back to your server like the example above, then attach the payment back that user by calling addPaymentMethod

$user->addPaymentMethod( $request->input('card) );

Upvotes: 2

Related Questions