#phu_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/1370095661554335856
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi! This actually changed recently, and you now need to expand latest_invoice.payments.data.payment.payment_intent to get the Payment Intent.
I am trying this right now I will get back to you in a minute!
here is the error we have (the function is also included):
function:
const createSubscriptionWithPaymentIntent = async (customerId, priceId, userId, spaceId, quantity = 1) => {
try {
// Create the subscription with expand parameter to get the payment intent directly
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [
{
price: priceId,
quantity: quantity,
},
],
metadata: {
user_id: userId,
space_id: spaceId
},
payment_behavior: 'default_incomplete',
collection_method: 'charge_automatically',
payment_settings: {
save_default_payment_method: 'on_subscription',
payment_method_types: ['card']
},
expand: ['latest_invoice.payments.data.payment.payment_intent']
});
Yup, gimme a sec.
hello!
I think it is to retrieve the client_secret and return it to the client so we can process the payment
Gotcha, you want to use the confirmation_secret.client_secret for that: https://docs.stripe.com/api/invoices/object#invoice_object-confirmation_secret-client_secret
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So you only need to expand latest_invoice here
here is the updated function:
const createSubscriptionWithPaymentIntent = async (customerId, priceId, userId, spaceId, quantity = 1) => {
try {
// Create the subscription with expand parameter to get the payment intent directly
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [
{
price: priceId,
quantity: quantity,
},
],
metadata: {
user_id: userId,
space_id: spaceId
},
payment_behavior: 'default_incomplete',
collection_method: 'charge_automatically',
payment_settings: {
save_default_payment_method: 'on_subscription',
payment_method_types: ['card']
},
expand: ['latest_invoice']
});
if (!subscription.latest_invoice || !subscription.latest_invoice.confirmation_secret) {
throw new Error('No confirmation secret was found on the latest invoice');
}
const clientSecret = subscription.latest_invoice.confirmation_secret.client_secret;
if (!clientSecret) {
throw new Error('No client secret was found in the confirmation secret');
}
// Return the client secret from the payment intent
return {
subscriptionId: subscription.id,
clientSecret: clientSecret
};
} catch (error) {
console.error('Error creating subscription with payment intent:', error);
throw error;
}
};
And here is the new error:
Error creating subscription with payment intent: Error: No confirmation secret was found on the latest invoice
at Object.createSubscriptionWithPaymentIntent (/Users/arvihaxhillari/Documents/Code/mention/backend/services/stripeService.js:214:13)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async createSubscription (/Users/arvihaxhillari/Documents/Code/mention/backend/controllers/billing/billingController.js:46:20)
We keep getting stuck 😅
What API version are you using here?
And can you share the request ID from your test?
If you are not on the newest API version then you would just use latest_invoice.payment_intent.client_secret
This changed quite recently, see: https://docs.stripe.com/changelog/basil/2025-03-31/add-support-for-multiple-partial-payments-on-invoices
the version is : 18.0.0
That looks to be a SDK version
You are using the node SDK though it looks like
Which did PIN to that new API version mentioned above: https://github.com/stripe/stripe-node/blob/master/CHANGELOG.md#1800---2025-04-01
Can you share the Subscription ID that you created here in your test?
the stripe version is 2025-03-31.basil
we are getting the other ids
here is the subscription id: sub_1RMZjqGKpk2qFBnGk1NvO6eg
Thanks, give me a sec
we think this is the requestId: req_r9iXYtcCFika3O