#fabian_api

1 messages ¡ Page 1 of 1 (latest)

lone patioBOT
#

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

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

pine harborBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

flat delta
#

Subscription Schedules don't have a client secret

tired knot
#

Do I have to go this way?

    const subscription = await stripe.subscriptions.retrieve(
      scheduleSubscription?.subscription.id 
    );
```
#

Sorry:

    const subscription = await stripe.subscriptions.retrieve(
      scheduleSubscription?.subscription 
    );
#

Do I need the client_secret to finish the payment process?

flat delta
#

I'm not sure. Why would you need a client secret?

tired knot
#

My current flow: User enters InvoiceData => Server creates customer => Server creates subscription for customer => Return client_secret to handle checkout.

#

This works for a normal subscription. Now I would like to create a Subscription with 3 month monthly billing and annually billing afterwards.

flat delta
#

Wouldn't you already have a saved payment method in this case? Why do you need to handle checkout again?

tired knot
#

Its the first checkout

#

the subscription should have phases on its creation

flat delta
#

The client secret would be on a Payment Intent, so you need to get the Payment Intent or the Setup Intent depending on what you're using

tired knot
#

Isnt the payment intent created with the subscription?

#

Is there any example for a checkout process with a scheduledSubscription?

flat delta
#

Not necessarily. The Payment Intent is created once the Invoice on the Subscription is finalized

tired knot
#

Does this make sense:

    const scheduleSubscription = await stripe.subscriptionSchedules.create({
      customer: customerId,
      start_date: 'now',
      end_behavior: 'release',
      phases: phases,
    });

    const subscription = await stripe.subscriptions.retrieve(
      scheduleSubscription?.subscription as string,
    );

    const initialAmount = subscription.items.data[0].price?.unit_amount || 0;

    const paymentIntent = await stripe.paymentIntents.create({
      amount: initialAmount,
      currency: 'eur',
      customer: customerId,
      payment_method_types: ['card, sepa_debit'],
      metadata: {
        subscription_id: subscription.id,
        payment_behavior: 'default_incomplete',
      },
    });
flat delta
#

You can't create the Payment Intent for the Subscription. Stripe has to do that automatically

#

The Payment Intent will be created once the Invoice is moved to a finalized state

tired knot
#

When is the invoice created?

#

How can I adjust my code to make this work

flat delta
#

It depends on your subscription flow and a number of factors. I would recommend creating a few test Subscriptions and inspecting each object to understand

tired knot
#

Why does it work if create a normal subscription

#

Is there some basic example for what I am trying to achieve?

flat delta
#

Unfortunately no, as this is not a simple integration.

How are you accepting payment method details right now? Payment Element?

tired knot
#

yes