#krishna-awate_api

1 messages ยท Page 1 of 1 (latest)

hexed laurelBOT
#

๐Ÿ‘‹ 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.

rich pumice
#

Hello

frosty idolBOT
spice heron
#

You want to collect the payment method using the client secret on a Subscirption with 1 month trial ?

rich pumice
#

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?

spice heron
#

Yes, sorry, discord is a bit busy, I'm with you

rich pumice
#

Okay no issue sir.

#

Can you please help me on above?

spice heron
#

You should have a SetupIntnt attached to the Subscription

#

Which you can use it's client_secret in order to collect the payment method

rich pumice
#

How can I do that?

rich pumice
#

But I need to change stripe.confirmPayment in front end also.

spice heron
#

You expand the field pending_setup_intent

spice heron
rich pumice
#

My other code is depend on stripe.confirmPayment

spice heron
#

You just collect the payment method, you are not doing any payment attempts as the Subscription is in trial

spice heron
rich pumice
#

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;

wispy cipher
#

I don't understand the question. What is happening when you use the code?

rich pumice
#

clientSecret = subscription.latest_invoice.payment_intent.client_secret;

I am getting client secret from here

#

But Payment intent is null

wispy cipher
#

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

rich pumice
#

Okay got it.

#

Give me few second I will check.

rich pumice
#

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?

wispy cipher
#

That's the default behaviour โ€“ the subscription will renew automatically unless you set it to cancel

rich pumice
#

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?

wispy cipher
#

Seems like a good idea yep

rich pumice
#

Okay I will try and check.

#

sub_1PAtY2DBfYojrB0W6phT3uRt

#

How can I check when it will end?

wispy cipher
#

Depends what you mean by 'end'?

rich pumice
#

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?

wispy cipher
#

You can see there when the next invoice will be generated

rich pumice
#

I have set it monthly. So it will show next month.

wispy cipher
#

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

rich pumice
#

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?

wispy cipher
#

interval: "year" exists

rich pumice
#

Actually there is condition

let interval_count;
if (recurring_period === "quarterly") {
interval_count = 3;
} else if (recurring_period === "yearly") {
interval_count = 12;
}

rich pumice
#

quarter.

wispy cipher
#

No, that would just be interval: "month", interval_acount: 3

rich pumice
#

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?

late zealot
#

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?

rich pumice
#

I have not tested yet. Let me check it.

#

There is no error it is working.

#

I will go ahed with this one.

#

Thank you so much for your help.

#

Have a nice to you all who helped me.