#krishna-awate_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/1234464982201139210
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello
You want to collect the payment method using the client secret on a Subscirption with 1 month trial ?
Yes without cliend secret my chekout will not be loaded.
const recurringProduct = await stripe.products.create(product_name, {
stripeAccount: stripeAcId,
});
const recurringPrice = await stripe.prices.create(
{
unit_amount: planAmount,
currency: currency.toLowerCase(),
recurring: { interval: "month", interval_count: 3 },
product: recurringProduct.id,
},
{
stripeAccount: stripeAcId,
}
);
const subscription = await stripe.subscriptions.create(
{
customer: customer.id,
items: [{ price: recurringPrice.id }],
trial_end: trial_end,
payment_behavior: "default_incomplete",
payment_settings: {
save_default_payment_method: "on_subscription",
},
expand: ["latest_invoice.payment_intent"],
cancel_at: sub_end_date,
description: org?.organization_name,
// application_fee_percent: +service_fee,
},
{
stripeAccount: stripeAcId,
}
);
clientSecret = subscription.latest_invoice.payment_intent.client_secret;
Payment intent getting null here
Hii
Are you there?
Yes, sorry, discord is a bit busy, I'm with you
You should have a SetupIntnt attached to the Subscription
Which you can use it's client_secret in order to collect the payment method
How can I do that?
But I need to change stripe.confirmPayment in front end also.
No there is no payment to confirm if the subscription is on trial. You need to use confirmSetup instead
My other code is depend on stripe.confirmPayment
You just collect the payment method, you are not doing any payment attempts as the Subscription is in trial
You need to refactor your code to handle both methods
Hwo can I get client-secret from
const subscription = await stripe.subscriptions.create(
{
customer: customer.id,
items: [{ price: recurringPrice.id }],
trial_end: trial_end,
payment_behavior: "default_incomplete",
payment_settings: {
save_default_payment_method: "on_subscription",
},
expand: ["latest_invoice.payment_intent"],
cancel_at: sub_end_date,
description: org?.organization_name,
// application_fee_percent: +service_fee,
},
{
stripeAccount: stripeAcId,
}
);
clientSecret = subscription.latest_invoice.payment_intent.client_secret;
I don't understand the question. What is happening when you use the code?
clientSecret = subscription.latest_invoice.payment_intent.client_secret;
I am getting client secret from here
But Payment intent is null
It's because you're passing trial_end so there is no immediate payment. Instead there'll be a pending_setup_intent field on the Subscription response to expand
Use the client_secret from there
It is working
const confirmIntent = type === "setup" ? stripe.confirmSetup : stripe.confirmPayment;
I have used it for front end.
I have one more question sir, I want to make subscription time until user cancel.
Subscription should not cancel automatic until user cancel it.
How can I do it?
That's the default behaviour โ the subscription will renew automatically unless you set it to cancel
const subscription = await stripe.subscriptions.create(
{
customer: customer.id,
items: [{ price: price.id }],
trial_end: trial_end,
payment_behavior: "default_incomplete",
payment_settings: {
save_default_payment_method: "on_subscription",
},
expand: ["pending_setup_intent"],
cancel_at: sub_end_date,
description: org?.organization_name,
// expand: ["latest_invoice.payment_intent"],
// application_fee_percent: +service_fee,
},
{
stripeAccount: stripeAcId,
}
);
Shall I remove cancel_at?
Seems like a good idea yep
Okay I will try and check.
sub_1PAtY2DBfYojrB0W6phT3uRt
How can I check when it will end?
Depends what you mean by 'end'?
End means I have removed cancel_at property. So want to confirm will it be continued unitl user cancel it.
How can I check in dashboard.
It is showing like this.
Just want to cofirm will it be lifetime?
You can see there when the next invoice will be generated
I have set it monthly. So it will show next month.
Yep, and that's how it'll work. The current_period_end timestamp will reflect the end of the period when we generate a new invoice
There's no 'lifetime' subscription flag
Okay will check by advance time.
One more thing I want to active subscsription yearly
const price = await stripe.prices.create(
{
unit_amount: planAmount,
currency: currency.toLowerCase(),
recurring: { interval: "month" ,interval_count: 12},
product: product.id,
},
{
stripeAccount: stripeAcId,
}
);
Can I do that?
interval: "year" exists
Actually there is condition
let interval_count;
if (recurring_period === "quarterly") {
interval_count = 3;
} else if (recurring_period === "yearly") {
interval_count = 12;
}
No, that would just be interval: "month", interval_acount: 3
Can I use recurring: { interval: "month" ,interval_count: 12} for charge recurring once in a year?
Logic will be easy for me as I want quarterly also.
Or I have to use interval: "year" only?
Hi there ๐ jumping in as my teammate needs to step away soon. I don't think we force you to use year instead of 12xmonths. Do you encounter an error when you try to do so stating otherwise?