#oleg.moseiko

1 messages · Page 1 of 1 (latest)

visual aspenBOT
strong canyon
#

By set its invoice_settings.default_payment_method

copper talon
#

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?

#

?

strong canyon
#

Um so you are creating a Checkout Session?

copper talon
#

i create Checkout\Session 'mode' => 'setup',

#

to add card

strong canyon
#

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

copper talon
#

set the default by calling Update Customer API ---??

#

which parameter i need to use to set default

strong canyon
visual aspenBOT
copper talon
#

can i get it not from webhook?

thorny brook
#

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.

copper talon
#

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

#

?

thorny brook
#

That's possible, but what if the Customer closes the browser before you run your business logic?

copper talon
#

in this case he will add card again))

#

but how can i do it by CHECKOUT_SESSION_ID?

thorny brook
thorny brook
copper talon
#

my server check all requests

copper talon
#

if header has no auth token this request will be declined

#

how can i add my token to webhook request/event?

thorny brook
thorny brook
copper talon
#

that mean i need to create new server with duplication a lot of logic(work with DB, Models, validations)

thorny brook
#

But the success URL is not a good place for business logic. You will have problems with it down the road.

copper talon
#

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

thorny brook
visual aspenBOT