#Robert de Nuiro-subscriptions
1 messages ยท Page 1 of 1 (latest)
Thank you for taking my problem into consideration
are you using checkout?
I am using the payment element from stripe
I use react for the front
I don't use the checkout page hosted by stripe
ok
I have followed this tutorial from stripe documentation :
https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
there's a new parameter
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
it would do that without having to rely on webhooks
Ok nice, so I have to set the var default_payment_method while creating the subscription ?
no you don't, it will do it for you once the first invoice is paid
by setting this param when creating the subscription
ok so I don't have to change anything in my code ?
The problem is that I create the subscription before the customer has finished paying
you do have to do two small things, 1- remove the webhook code for that event, 2- set the save_default_payment_method to true when creating the subscription
all the rest of the flow would still be the same
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [{
price: priceId,
}],
default_payment_method: "",
payment_behavior: 'default_incomplete',
expand: ['latest_invoice.payment_intent'],
});`
"payment_settings.save_default_payment_method optional enum
Either off, or on_subscription. With on_subscription Stripe updates subscription.default_payment_method when a subscription payment succeeds."
Ok so I'll put payment_settings: {save_default_payment_method:"on_subscription"}
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [{
price: priceId,
}],
default_payment_method: "",
payment_behavior: 'default_incomplete',
expand: ['latest_invoice.payment_intent'],
payment_settings: {
save_default_payment_method: "on_subscription"
}
});
Sorry for the inconvenience, your api is really great
perfect
sorry, it's a new feature we just added last week, I'm still not on top of it a 100%
I thought it was a boolean ๐
Haha no problem, I find it already incredible the help you bring on discord and the speed at which you answer
let me know if you need any more help
I'm sorry to bother you again but I feel like it doesn't set the default payment method when I added save_default_ payment_method: "on_subscription"
I did remove the webhook, here is my code :
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [{
price: priceId,
}],
payment_behavior: 'default_incomplete',
expand: ['latest_invoice.payment_intent'],
payment_settings: {
save_default_payment_method: "on_subscription"
}
});
customer id : cus_Lk2FdMg3qQFQF6
payment id : pm_1L2YCEHe8JvDQ9Zm4HDC01ZN
subscription id : sub_1L2YBFHe8JvDQ9ZmyYL5qO3i
Oh ok thank you
I don't see the payment method in the customers tab
And when I want to change the billing period (monthly to annual) I get a 400 with this error message: "This customer has no attached payment source or default payment method. Please consider adding a default payment method."
yep because it sets the default on the subscription object, not at the customer level
that's because for some reason you are unsetting the default payment method in your request, you should not do that
not at all! it's complicated