#shubham_1306
1 messages · Page 1 of 1 (latest)
Hi, let me help you with this.
Hello
You can add one-time items when creating a Subscription object: https://stripe.com/docs/api/subscriptions/create#create_subscription-add_invoice_items
So I need to create a customer first?
Yes, however this is not related to the question that you asked initially.
Yeah I get it but my concern is that if the customer is created previously and we just hit the api for subscription payment will be directly deducted from the added account of customer without asking for confirmation or any client side secret?
It depends if you have a Payment Method set up for future payments.
But if you don't provide a payment method you can use the generated client_secret to collect the payment details on the frontend from the customer.
yeah thats sound better, so the client secret will be there in the same api?
I am not sure I understand the question. But you can follow this guide to better understand the flow: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
Like when I currently call a subscription for a user without any default payment methods this is what I get:
{
"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_fHFcjFPHmJr8uU?t=1698237589",
"type": "invalid_request_error"
}
}
These are the request params
let data = qs.stringify({
'items[0][price]': 'price_1NpUU7SFSc1Kz6ix7E8qkBis',
'items[0][quantity]': '1',
'customer': 'cus_OpNH5Kx2xWree9',
'add_invoice_items[0][price]': 'price_1NpUa5SFSc1Kz6ix2vN9BTu3',
'add_invoice_items[0][quantity]': '1'
});
You are missing:
...
payment_behavior: 'default_incomplete',
payment_settings: { save_default_payment_method: 'on_subscription' },
expand: ['latest_invoice.payment_intent'],
Oh OK thanks now it works
Happy to help.