#paul_customer-defaultpm
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1220146154113859746
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello @woeful radish ! I'm sorry I don't really understand what your question means.
One sec
Let me elaborate
What are possible options using back-end server code to set Customers payment method to be default
Once payment default is enabled I can add additional subscription or one off payments
https://docs.stripe.com/billing/subscriptions/payment-methods-setting we have this which explains how it works for Invoices and Subscriptions
It doesn't work for one-time payments though
Note these Items are added by customer... But we have a bit complex flow we want to enable for cutomer to add additional products
Hmm this is for existing subscription..
Does this work for Existing Customer ?
not a subscription
I'm sorry this is really vague so it's hard to help without focusing on our exact product(s) or APIs that you use. You didn't really give me much yet
Oh
Sure
np Let me share
val params: SessionCreateParams = SessionCreateParams.builder()
//Required for Subscription
.setMode(SessionCreateParams.Mode.PAYMENT)
.setSuccessUrl("http://localhost:4242/success?session_id={CHECKOUT_SESSION_ID}")
.setCancelUrl("http://localhost:4242/cancel?session_id={CHECKOUT_SESSION_ID}")
//Save payment Method Details
//Cant use payment Intend in Subscription Mode
.setPaymentIntentData(
SessionCreateParams.PaymentIntentData.builder().setSetupFutureUsage(
//NEED MORE TESTING THIS MAY NOT WORK 100
//https://docs.stripe.com/payments/payment-intents#future-usage
SessionCreateParams.PaymentIntentData.SetupFutureUsage.OFF_SESSION
).build()
)
//Enable customer creation as part of the session
// Not allowed when in Subscription Mode
.setCustomerCreation(SessionCreateParams.CustomerCreation.ALWAYS)
.addLineItem(
SessionCreateParams.LineItem.builder().setPrice("price_1OwXoHBZuRENdfSAewG3UzmA").setQuantity(1).build()
)
.build()
val session: Session = Session.create(params)
println("URL = "+session.url)
println(session.toJson())
The above can make a payment with Customer for Future usage
Create this king of customer
Having Id cus_Pm6Ext3WJwHPQ8
Okay so you are using Stripe Checkout to collect payment method details. Okay, so now what are you asking about that Customer?
Using code I want to set for given customer payment method as default
This allows me to add Another Subscription or One Off Payments using Invoice
Okay so what you would do is set invoice_settings[default_payment_method] on the Customer https://docs.stripe.com/api/customers/update#update_customer-invoice_settings-default_payment_method
paul_customer-defaultpm
use what I just linked above
val updateParms = CustomerUpdateParams.builder().setInvoiceSettings(
CustomerUpdateParams.InvoiceSettings.builder().setDefaultPaymentMethod("What do I put in here")
)
so there is above code what goes in there
Ah I get it now. The pm_123456 which is the PaymentMethod id that you want to make the default
Ohh
So this will pm_1OwWkkBZuRENdfSAuD9tKDkv Ok one sec
yes!
Perfect !!!! I got
@Test
fun `Test customer to update payment method to default`(){
val resource: Customer = Customer.retrieve("cus_Pm4u3QW9v2OL7N")
val updateParms = CustomerUpdateParams.builder().setInvoiceSettings(
CustomerUpdateParams.InvoiceSettings.builder().setDefaultPaymentMethod("pm_1OwWkkBZuRENdfSAuD9tKDkv").build()
).build()
val result = resource.update(updateParms)
println(result.toJson())
}
I got back
"invoice_settings": {
"custom_fields": null,
"default_payment_method": "pm_1OwWkkBZuRENdfSAuD9tKDkv",
"footer": null,
"rendering_options": null
},
Ok I then I am done
thank you
I am glad I reached out... as this was not that trivial thank you
over and out
Have a great day