#oleg.moseiko
1 messages · Page 1 of 1 (latest)
By set its invoice_settings.default_payment_method
ok i check $stripeCustomer->invoice_settings['default_payment_method']
if it is null
i run it
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'mode' => 'setup',
'customer' => $stripeCustomer->id,
'success_url' => $successUrl . '?session_id={CHECKOUT_SESSION_ID}&price_id=' . $priceId,
'cancel_url' => $referer_cancel,
]);
return $this->redirect()->toUrl($session->url);
user create card but after that i check $stripeCustomer->invoice_settings['default_payment_method']
and it is NULL
what is wrong?
?
Um so you are creating a Checkout Session?
That will only save the Payment Method to the Customer. You would need to listen to setup_intent.succeeded webhook event and set the default by calling Update Customer API
set the default by calling Update Customer API ---??
which parameter i need to use to set default
Call this API and set this parameter: https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
can i get it not from webhook?
Hi! I'm taking over my colleague. Please, give me a moment to catch up.
When you get the webhook, you need to take the new Payment Method ID and update the Customer's invoice_settings.default_payment_method. It is not set by default.
There's a difference between a Payment Method being attached to a Customer (there can be multiple) and the only one PM that's used by default.
can i do it not by webhook
i do it
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'mode' => 'setup',
'customer' => $stripeCustomer->id,
'success_url' => $successUrl . '?session_id={CHECKOUT_SESSION_ID}&price_id=' . $priceId,
'cancel_url' => $referer_cancel,
]);
can i use 'success_url' to update new Payment Method ID for customer?
maybe i can retrieve it by CHECKOUT_SESSION_ID
?
That's possible, but what if the Customer closes the browser before you run your business logic?
But from their point of view they completed the Checkout successfully. Why would they do it again?
Why don't you want to use webhooks?
my server check all requests
You can see the example here: https://stripe.com/docs/payments/checkout/custom-success-page#create-success-page
if header has no auth token this request will be declined
how can i add my token to webhook request/event?
Can you make your server not check this one endpoint?
You can't
that mean i need to create new server with duplication a lot of logic(work with DB, Models, validations)
But the success URL is not a good place for business logic. You will have problems with it down the road.
really i just need switch my user from freePlan to new payment plan
i can't do Subscription::update because:
This customer has no attached payment source or default payment method. Please consider adding a default payment method.
and i can't use \Stripe\Checkout\Session::create( with new price because in this case user ADD new payment plan but i need also remove old free plan
Did you set the invoice_settings.default_payment_method for the Customer?