#jackson.bayor-subscription_schedule

1 messages · Page 1 of 1 (latest)

buoyant perch
#

hello! how can i help?

#

@modern shore heya

modern shore
#

Okay seen it

#

Hi all, please I need some help managing the subscription schedule that I have created. Here's my use case:

  • I create a subscription schedule with two phases. One for the first single charge of £400 that does not iterate and the second phase is for a monthly payment of £30 that iterates for 5 months.
  • At the first instance of creating the subscription schedule and successful payment, I want to send an email to the customer containing the details of their order. This email would require fields including
    — the order number I created for the subscription,
    — the amount the customer paid for the first phase
    — The iteration spread for the next phase
    — The price that will be charged for the next phase that is recurring
    — The amount due that’s left to be paid, that will be calculated based on how many cycles are left and how much is paid per month
    — The next payment date

From my analysis, I have to make multiple api calls and it’s just a lot.

Please help with an optimal way or a different way to structure this type of email.

See a sample below

#

the email template should show you what I wanna achieve better

buoyant perch
#

how long is the first phase?

#

or is it actually a flat fee?

modern shore
#

Let me send the object

#
const subscriptionScheduleObject = {
      customer: customerId,
      end_behavior: "cancel",
      start_date: "now",
      phases: [
        {
          items: [
            {
              price_data: {
                currency,
                product: stripe_productId,
                recurring: {
                  interval: "month",
                },
                unit_amount: price * 100,
              },
              quantity: 1,
            },
          ],
          iterations: 1,
        },
        {
          items: [
            {
              price_data: {
                currency,
                product: stripe_productId,
                recurring: {
                  interval: "month",
                },
                unit_amount: monthlyCharge * 100,
              },
              quantity: 1,
            },
          ],
          iterations: cycles,
        },
      ],
buoyant perch
#

so your first charge is $400 for month #1?

modern shore
#

Depends on the product price and some variables

#

So I use price_data to create dynamic prices

#

But yeah, for instance a product of $1000 with a deposit percentage of 40% will be converted into a subscription schedule of two phases

#

One for the one off 40% payment of $400 and the second phase for a monthly payment where the balance ($600) is spread across the number of cycles, e.g. 5 months meaning $120 per month for 5 months

#

Do you understand better?

#

The schedule is successfully created in the api. The problem is I dont get enough information from the webhook to create an email template with those details I mentioned

buoyant perch
#

Creating the Subscription Schedule is fairly straightforward in your instance. For the email - what specific issue do you have? From what I understand, you're going to need to perform all of these calculations yourself before creating the Subscription Schedule - so you should already have most of that info and save that to your DB.

modern shore
#

Everything works

#

Payment is successful

#

I get the different webhooks

#

I'm saying after a webhook is received for invoice.paid, I want to send an email that has those details. e.g the month it starts, next billing date, cycles/iterations etc... like what's in the email. The webhook doesnt provide that. So I have to make multiple api calls to pinpoint the data I need

#

I'm trying to see an optimal solution because my approach is clearly not optimal

buoyant perch
#

can you list down the api calls you're making to get the data you need?

modern shore
#

For instance, I get the invoice.paid webhook and I can fetch subscription ID from there.
I can then use this subscription ID to get its subscription. Object to access the start date and end date but I can’t get next due date or the date the next payment will be made.
I can’t seem to find cycles or monthly payment price etc

buoyant perch
#

you'll need to implement some logic to ensure that the next due date isn't when the Subscription Schedule ends

modern shore
#

If you see the dashboard, it's able to show it.

buoyant perch
#

monthly payment price should also be obtainable either from the Subscription or from the Subscription Schedule

modern shore
#

Wish there was a way to access data just as the dashboard displays

#

If you get what I mean

buoyant perch
#

the only problem would be when you are switching to a new phase

modern shore
#

okay

#

I'll have a deeper look

#

Regarding subscription schedules, do customers have to manually input card details before the next payment is made?

#

At the moment, the card details used at the initial payment does not get saved as the default payment method

buoyant perch
#

umm, why not?

modern shore
#

Not sure

buoyant perch
#

how do your customers make initial payment? are you using the Payment Element?

modern shore
#

Yes

#

Payment element

#

Do you notice that the payment method in customer portal is empty

buoyant perch
#

are you creating a subscription schedule first? or creating a subscription then creating a subscription schedule from the existing subscription?

modern shore
#

I create customer and then subscription schedule

#

Do dont create subscription seperately

buoyant perch
#

the customers don't have to manually input card details again

modern shore
buoyant perch
#

can you share an existing subscription schedule id?

modern shore
#

sub_sched_1LcJEjDUun9ImF4JT6mJGQY5

buoyant perch
#

hrm, gimme a while to test something

modern shore
#

Okay

#

I'll be off now

#

But kindly leave the thread open. Will respond to your findings once I'm back online. Thanks mate

buoyant perch
#

i'm guessing that these are the steps you're taking :

  1. create subscription schedule
  2. finalize invoice
  3. use PaymentIntent client_secret (from finalized invoice) to initialize Payment Element
  4. customer makes payment via Payment Element
#

this way, when the customer makes payment for that subscription's invoice, the PaymentMethod will automatically be saved as the default payment method