#vincesanityy
1 messages ยท Page 1 of 1 (latest)
Can you clarify - is your issue just that you don't know how to set the default payment method for the customer?
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.
Ah, your issue is that when using Checkout in subscription mode it always ask you for a new payment method, right?
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
but we are utilizing the billing portal we dont do it directly on our backend.
hmm so we cant do it on the checkout?
Actually one second I forgot there may be a way to do this
When you're creating the Checkout Sessions are you sure you'd passing in customer when you create it? https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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;
}
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
so i need to pass customer on the checkout and thats the time it will get the default payment method?
Yup - we talk about that in the api reference link i sent you https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer
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.
Can you share that checkout session ID so I can take a look?
$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
Ah, I forgot there were some specific rules about when the default payment method is displayed
hmmm
I belive the default payment method needs billing_details to be populated (https://stripe.com/docs/api/payment_methods/object#payment_method_object-billing_details) in order to show up
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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.
I do think the empty billing address is a factor here
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 ๐
i filled completly the fields but still it doesnt get the default payment method
okay thanks @marsh mural
hello anyone here? ๐
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
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.
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
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
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
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.
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
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
Can you share the specific update request you made?
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
okay i am trying now
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'
]
]
);
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
yes. if possible if i update the billing details on the portal it must be also update the billing details on the payment method.