#stenaut_api

1 messages ¡ Page 1 of 1 (latest)

frank vortexBOT
#

👋 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/1346129050103447562

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

olive rose
#
// Session creation
...
const { priceId, priceType }: { priceId: string; priceType: Stripe.Price.Type } = await req.json();

const session = await stripe.checkout.sessions.create({
    mode: priceType === 'recurring' ? 'subscription' : 'payment',
    payment_method_types: ['card'],
    line_items: [{ price: priceId, quantity: 1 }],
    locale: 'fr',
    success_url: `${origin}/transformation-physique/success?session_id={CHECKOUT_SESSION_ID}`,
    cancel_url: `${origin}/transformation-physique`,
});
...
final valve
olive rose
#
// Webhook
...
case 'checkout.session.completed': {
    const session = event.data.object as Stripe.Checkout.Session;


    // For subscription mode, check if it's an installment plan
    if (session.mode === 'subscription' && session.subscription) {
        const subscriptionId = session.subscription as string;
        const subscription = await stripe.subscriptions.retrieve(subscriptionId, {
              expand: ['items.data.price'],
        });
        const price = subscription.items.data[0]?.price;

        // Check if the price has installments metadata
        if (price.metadata.installments) {
            // Set cancellation to occur after 2 months and 5 days
            const thirdPaymentDate = new Date();
            thirdPaymentDate.setMonth(thirdPaymentDate.getMonth() + 2);
            thirdPaymentDate.setDate(thirdPaymentDate.getDate() + 5);

            const cancelAtTimestamp = Math.floor(thirdPaymentDate.getTime() / 1000);

            // Update subscription to cancel after the third payment
            await stripe.subscriptions.update(subscriptionId, {
                cancel_at: cancelAtTimestamp,
            });
        }
    }
    break;
}
...
final valve
#

Your workaround here works sure

#

Did you have any specific questions on this?

olive rose
#

Thanks about the Subcription schedules. So here in my usecase, you mean with this feature I wouldn't need to do this Webhook workaround, I would just trigger the Subscription schedules for 3 months with my specified priceId ? (priceId that would be the 100$ recurring subscription)

My other concern was also that, when the customer will Checkout, they will see that it's a "subscription" and it might not reassure them, thinking it's a real subscription and not only 3 installments.
Compared to the one-time price, where the Checkout UI clearly shows it.

The workaround I found was either to do another "same" product but this time add "3 installments" in the description, and it would be shown in the Checkout UI (but still being a "subscription" visible)
Or I'll have to do my own UI and not rely on Stripe Checkout

And that's why I came here to be sure first !

final valve
#

I agree with you, adding "3 installments" in the description so it's clear what it is

If you're already using CheckoutSessions, I would say yes. You whould keep track of these on your end and cancel the subscription after the last installment payment

olive rose
#

I see thank you mate !