#ethan_api
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/1385114119450918973
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
Code for creating subscription:
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [
{
price: priceId,
quantity: seatCount,
},
],
payment_behavior: 'default_incomplete',
payment_settings: { save_default_payment_method: 'on_subscription' },
expand: ['latest_invoice.confirmation_secret'],
});
Error:
{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "This customer has no attached payment source or default payment method. Please consider adding a default payment method. For more information, visit https://stripe.com/docs/billing/subscriptions/payment-methods-setting#payment-method-priority.",
"request_log_url": "https://dashboard.stripe.com/test/logs/req_HfDxGRNk1qK22K?t=1750306263",
"type": "invalid_request_error"
}
}
Request body according to Workbench - note missing payment_behaviour: "default_incomplete"
{
"collection_method": "charge_automatically",
"customer": "cus_SWbZYus5zJsfdG",
"items": {
"0": {
"price": "price_1RTb4Y4COiNjImo6sRG82E3F",
"quantity": "4"
}
}
}
payment_behavior only applies to subscriptions with collection_method=charge_automatically
When charging automatically, Stripe will attempt to pay this subscription at the end of the cycle using the default source attached to the customer [0]. Hence why we're returning the error.
I'm not specifying collection method though, and the default is charge_automatically correct?
So shouldn't it just create the subscription with status=incomplete?
Yes, the default is charge_automatically
This is the guide I'm following btw: https://docs.stripe.com/billing/subscriptions/build-subscriptions?platform=web&ui=elements#create-subscription
Double checking things on my end.
Ok, so I just went through the process and I was not able to replicate your issue. This is what I used on my end:
const subscription = await stripe.subscriptions.create({
customer: 'cus_SWe7O4z31Vpf2B',
items: [
{
price: 'price_1RbazQQKdNnoI2anyOi1Jfff',
},
],
metadata: {
description: "This is a subscription that was created via the API (https://docs.stripe.com/api/subscriptions/create)"
},
payment_behavior: 'default_incomplete',
//expand: ['latest_invoice.payment_intent'],
expand: ['latest_invoice.confirmation_secret']
});
And this is the request body per workbench
{
"customer": "cus_SWe7O4z31Vpf2B",
"expand": {
"0": "latest_invoice.confirmation_secret"
},
"items": {
"0": {
"price": "price_1RbazQQKdNnoI2anyOi1Jfff"
}
},
"metadata": {
"description": "This is a subscription that was created via the API (https://docs.stripe.com/api/subscriptions/create)"
},
"payment_behavior": "default_incomplete"
}
And your customer has no payment methods associated with them?
None
I recommend double checking your code, because it appears the following did not make it's way into the request that you sent:
payment_behavior: 'default_incomplete',
expand: ['latest_invoice.confirmation_secret'],
Yeah I'm aware ๐ค
Why would that be??
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [
{
price: priceId,
quantity: seatCount,
},
],
payment_behavior: 'default_incomplete',
payment_settings: { save_default_payment_method: 'on_subscription' },
expand: ['latest_invoice.confirmation_secret'],
});
This is my actual code haha
nothing omitted or added here
How are you sending the request?
Via a firebase function running in the firebase emulator
Which may have just given me a clue
Give me 5 minutes I'll check that it's building correctly etc
Sounds good.
Ah that was it haha
Dunno what happened but resetting my functions build dir fixed it
It's always the things you don't think to check ๐
Hahahaha. Glad that resolved it.