#gunwant_dev-Subscription Schedules

1 messages · Page 1 of 1 (latest)

rapid harbor
#

👋 happy to help

cosmic lichen
#

Hello

rapid harbor
cosmic lichen
#

Ya sure.
subscription schedule id : sub_1L80QNHWMWhDPqNoBO2qW4lw

rapid harbor
#

this is the subscription id

#

no worries I will find it

#

fyi, it's sub_sched_1L80QNHWMWhDPqNoz6ZDWMMI

cosmic lichen
#

Ohhh sorry.

#

sub_sched_1L80QNHWMWhDPqNoz6ZDWMMI

#

Yes

#

Hey, actually I want client_secret when the subscription schedule is created.
Can you please help me how can i get?

#

Hello, Are you there?

rapid harbor
#

yes sorry I'm still looking into it

cosmic lichen
#

Okay.
Take your time.

tropic plank
#

Hey, taking over here! The resulting invoice is still a draft. The PI will be created once finalised

cosmic lichen
#

Okay

#

Let me check it.

#

Hello
can you please check it?
Is it an excellent way to get client_secret.

  try {
    const schedule = await stripe.subscriptionSchedules.create({
      customer,
      start_date: 'now',
      end_behavior: 'cancel',
      phases: [
        {
          items: [
            {
              price: priceId,
              quantity: 1
            }
          ],
          iterations: 3
        },
      ],
      expand: ['subscription', 'subscription.latest_invoice', 'subscription.latest_invoice.payment_intent']
    });
    console.log('Schedule Info', JSON.stringify(schedule, null, 2));
    const subscription = await stripe.subscriptions.update(
      schedule.subscription.id,
      {
        expand: ['latest_invoice.payment_intent'],
        payment_settings: {
          payment_method_types: ['card', 'us_bank_account']
        },
      }
    );
    console.log('subscription', JSON.stringify(subscription, null, 2));
    const invoice = await stripe.invoices.finalizeInvoice(
      subscription.latest_invoice.id
    );
    console.log('invoice', JSON.stringify(invoice, null, 2));
    const paymentIntent = await stripe.paymentIntents.retrieve(
      invoice.payment_intent
    );
    console.log('paymentIntent', JSON.stringify(paymentIntent, null, 2));
    res.send({
      subscriptionId: subscription.id,
      clientSecret: paymentIntent.client_secret,
    });
  } catch (error) {
    console.error('error', error);
    return res.status(400).send({ error: { message: error.message } });
  }
tropic plank
#
const invoice = await stripe.invoices.finalizeInvoice(
      subscription.latest_invoice.id
    );

You can expand the payment_intent field here

#

Prevents having the additional API call to retrieve the PI

cosmic lichen
#

Okay.
But It shows only a single payment method.

tropic plank
#

I'm not sure what that means?

cosmic lichen
#

I have added two payment_method_types.
payment_method_types: ['card', 'us_bank_account']
But when I have initialized the stripe payment element using client_secret it shows only the card payment element.

tropic plank
#

Can you share the pi_xxx ID?

cosmic lichen
#

pi_3L81AvHWMWhDPqNo1kDTZOuQ

tropic plank
#

i.e. located in USA?

#

I only see:

payment_method_types: [
    "card"
  ],
cosmic lichen
#

Please look this code:

  try {
    const schedule = await stripe.subscriptionSchedules.create({
      customer,
      start_date: 'now',
      end_behavior: 'cancel',
      phases: [
        {
          items: [
            {
              price: priceId,
              quantity: 1
            }
          ],
          iterations: 3
        },
      ],
      expand: ['subscription', 'subscription.latest_invoice', 'subscription.latest_invoice.payment_intent']
    });
    console.log('Schedule Info', JSON.stringify(schedule, null, 2));
    const subscription = await stripe.subscriptions.update(
      schedule.subscription.id,
      {
        expand: ['latest_invoice.payment_intent'],
        payment_settings: {
          payment_method_types: ['card', 'us_bank_account']
        },
      }
    );
    console.log('subscription', JSON.stringify(subscription, null, 2));
    const invoice = await stripe.invoices.finalizeInvoice(
      subscription.latest_invoice.id,{
        expand: ['payment_intent'],
      }
    );
    console.log('invoice', JSON.stringify(invoice, null, 2));
    res.send({
      subscriptionId: subscription.id,
      clientSecret: invoice.payment_intent.client_secret,
    });
  } catch (error) {
    console.error('error', error);
    return res.status(400).send({ error: { message: error.message } });
  }

After subscription schedule I have updated subscription payment method.

analog cairn
cosmic lichen
#

ACH enabled in my stripe dashboard payment method.

analog cairn
#

on the specific page I linked though?

#

there are two separate places in the dashboard settings for payment methods unfortunately, Invoices have their own page and settings

cosmic lichen
#

Okay.
Let me check it

analog cairn
#

I checked and it's not enabled there

#

so I'd give that a try quickly and see if it helps

cosmic lichen
analog cairn
#

nope not that page

#

ah, you do have it enabled there

cosmic lichen
#

Okay

analog cairn
#

hmm, I really don't know then

cosmic lichen
#

Now. Its working

#

Thank you

analog cairn
#

ah, great(I guess you enabled it just now)

cosmic lichen
#

Yes.