#vincesanityy

1 messages ยท Page 1 of 1 (latest)

merry riverBOT
marsh mural
#

Can you clarify - is your issue just that you don't know how to set the default payment method for the customer?

woeful moat
#

no. i already set the default payment method for the customer.

#

but when i do checkout, i still need to define another payment method which is now added as a 2nd payment method.

#

checkout for creating a subscription.

marsh mural
#

Ah, your issue is that when using Checkout in subscription mode it always ask you for a new payment method, right?

woeful moat
#

i think checkout doesnt get the default payment?

#

yess

marsh mural
#

Yeah the only way around this would be to not use checkout for the subscription creation - instead you'd just create the Subscription through the API

#

and it'll automatically use whatever default they have set

woeful moat
#

but we are utilizing the billing portal we dont do it directly on our backend.

#

hmm so we cant do it on the checkout?

marsh mural
#

Actually one second I forgot there may be a way to do this

woeful moat
#

no. but i am using cashier and i think I already get the user thats why i dont pass customer params.

here is my implementation

    public function createSubscription($plan, $billing_method, $role_id): mixed
    {
        $user = auth()->user();

        $planDetails = $this->getSelectedPlanStripeID($plan, $billing_method);
        $subscription = $user->newSubscription(($role_id == RoleType::SPONSOR->value) ? 'sponsor' : 'creator', $planDetails);
        $checkoutSession = $subscription->checkout([
            'success_url' => route('checkout.success'),
            'cancel_url' => route('checkout.cancelled'),
            'metadata' => [
                'role_id' => $role_id,
                'type' => 'subscription',
                'plan_id' => $plan,
                'billing_method' => $billing_method
            ]
        ]);
        return $checkoutSession->url ?? null;
    }
marsh mural
#

That's why thery're not seeing their default payment method - you need to set customer when you create the checkout session to be able to use their default

woeful moat
#

so i need to pass customer on the checkout and thats the time it will get the default payment method?

marsh mural
woeful moat
#

okay let me check that one.

#

actually i tried it. i passed manually the customer_id but still it did not get the default payment method.

marsh mural
#

Can you share that checkout session ID so I can take a look?

woeful moat
#
        $checkoutSession = $subscription->checkout([
            'success_url' => route('checkout.success'),
            'cancel_url' => route('checkout.cancelled'),
            'customer' => 'cus_OEvkaIBITFOeTm',
            'metadata' => [
                'role_id' => $role_id,
                'type' => 'subscription',
                'plan_id' => $plan,
                'billing_method' => $billing_method
            ]
        ]);
        dd($checkoutSession);
#

ok this

#

cs_test_a1ElmvZKGOzf5CTrSAFiqYKzh5NIWhcTOANsexJNXiZHF1TVCa7IatkiGK

merry riverBOT
marsh mural
#

Ah, I forgot there were some specific rules about when the default payment method is displayed

woeful moat
#

hmmm

marsh mural
woeful moat
#

im confused.

#

๐Ÿ˜„

#

when setting up payment method. these are the only fields shown

#

i just redirect the customer to the portal when setting up payment method. is this not enough to get the default on the checkout session?

#

let me fillup the remaining fields.

hazy hawk
#

I do think the empty billing address is a factor here

marsh mural
#

I don't think updating those through the customer portal will do the trick - the surefire way of getting this to work would be update the PaymentMethod and set billing_details.email and billing_details.name

#

I need to head out, but I'll leave synthrider to help you ๐Ÿ‘

woeful moat
#

i filled completly the fields but still it doesnt get the default payment method

#

okay thanks @marsh mural

#

hello anyone here? ๐Ÿ™‚

marsh mural
#

You need to be updating billing_details on the PaymentMethod, not the Customer - as far as I can tell, I think you only set it on the customer

woeful moat
#

okay so i will set it on the backend? i thought it would be possible on the billing portal since we rely on the portal on our stripe transactions.

marsh mural
#

Yeah I know it can be a bit finicky - it works pretty seamlessly when the PaymentMethod was originally created through a previous Checkout Session (since it sets billing_details on the PaymentMethod), but since you were doing it through the billing portal it didn't set the exact things checkout needs

woeful moat
#

i dont know how to call it on the backend since we only redirect the customer to the billing portal if they set a payment method ๐Ÿ˜„

#

i mean what would be the process of doing it. im new to stripe

marsh mural
#

You'd listen for when the Payment Method was attached to the customer (with the payment_method.attached event) and then from there you can update it with the details you want

woeful moat
#

hmm i see.

#

let me try that one.

#

its kinda confusing @marsh mural. I tried it but when i am adding a payment method on the portal, it actually calls the create payment method intent.

#

but when i update the details below. its now updating the customer details.

hazy hawk
#

What do you mean, can you share specific IDs/requests?

#

As we understand it, those billign details must be set on the Payment Method and that request would be within your control

woeful moat
#

when i add a payment method. the billing details is empty. yes i understand since the only thing I input there are the card details.

#

but when I update the billing information below. the billing_details is still null since its webhook is customer.updated

hazy hawk
#

Can you share the specific update request you made?

woeful moat
#

i only added a new payment method. card number, cvc and expiry date. also country.

#

can you try to update the billing details on your end? here is the id pm_1NSmIxIRvJMoEzujXcVAnYYU

hazy hawk
#

No, you need to make that request

woeful moat
#

okay i am trying now

merry riverBOT
woeful moat
#

i think it works but what i directly implemented it. need to find a way for this to work.

        $a = $stripe->paymentMethods->update(
            'pm_1NSmIxIRvJMoEzujXcVAnYYU',
            [
                'billing_details' => [
                    'address' => [
                        'city' => 'Davao City',
                        'country' => 'PH',
                        'line1' => 'Davao City',
                        'line2' => null,
                        'postal_code' => '8000',
                        'state' => 'Agusan del Sur'
                    ],
                    'email' => 'vbustillo97@gmail.com',
                    'name' => 'Ronald Vincent Bustillo',
                    'phone' => '+639270277397'
                ]
            ]
        );
hazy hawk
#

Yep, setting those billing details on the PM is what I understand to be necessary here.

#

We're working on improving this use case, recognizing this is non-obvious as it works today

woeful moat
#

yes. if possible if i update the billing details on the portal it must be also update the billing details on the payment method.