#sarfaraj_82227

1 messages · Page 1 of 1 (latest)

azure thunderBOT
pseudo arch
#

hi!

it is not saving default card in stripe,
can you explain what that means? what are you expecteing to see that you don't see?

spare tartan
#

i means that when on frontend checkout page is opened and i put card for payment then i want that card to be saved as default on stripe to that customer for future refrerence

pseudo arch
#

well a first step would be to add 'payment_intent_data' => ['setup_future_usage'='off_session'], so the card is saved.

spare tartan
#

can you show me like where to change in my current code ?

pseudo arch
#

in the call to \Stripe\Checkout\Session::create you add that line I mentioned.

spare tartan
#

message
:
"syntax error, unexpected '=', expecting ']'"

pseudo arch
#

should be => not =

spare tartan
#

i have done this 'payment_intent_data' => ['setup_future_usage'=>'off_session'], and still not saving my card as default

pseudo arch
#

yep, because Checkout itself can not set it as the default.

#

but to clarify, with that change, are you now seeing that the card itself is being saved to the Customer and appears in the page for that Customer in the dashboard under their payment methods?

spare tartan
#

yeah when i check the payment details card is shown there ?

#

but that card is not saving as default

pseudo arch
#

yep, Checkout itself can not set it as the default.

#

can you clarify what you want to do with the card in future? Note while we have a concept of a "default payment method", that is only used for recurring subscription invoice payments. Is that what you're looking to do?

spare tartan
#

yes i am recurring the subscription on my hand i am not using stripe recurring so that's why i need default card so that i could use that for next payment

pseudo arch
#

What API do you use to process the next payment?

spare tartan
#

i have made whole recurring system on my backend where i calculate amount for next payment and then hit the checkout API of stripe for payment checkout for that i will be using this code ```try {
$customer = Customer::retrieve($customer_id);
$card = $customer->default_source;

        $charge = Charge::create([
            'customer' => $customer_id,
            'amount' => $amount,
            'currency' => $currency,
            'description' => $description,
            'source' => $card,
            'metadata' => [
                    'workspace_id' => $workspace_id,
                    'plan_id' => $plan_id,
            ],
        ]);```
pseudo arch
#

Ok. Well note that is wrong, you can't use the Charge API, you need to use the PaymentIntent API to charge the saved card.

spare tartan
#

ok but still i need default save card

pseudo arch
#

to make the call, you need to know the ID pm_xxx of the PaymentMethod you intend to charge. We do not have a default for that, you need to supply it in the API call. So the options are:

#
  • when handling the checkout.session.completed webhook event, save the pm_xxxx ID in your database, and then you can refer to that when making the API call later to charge the card with a PaymentIntent
  • when handling the checkout.session.completed webhook event, update the Customer to set https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method ; then you can read the value from there and pass it to the API call later to charge the card with a PaymentIntent