#jackson.bayor-subscription_schedule
1 messages · Page 1 of 1 (latest)
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
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,
},
],
so your first charge is $400 for month #1?
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
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.
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
can you list down the api calls you're making to get the data you need?
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
when you retrieve the Subscription, you can expand [0] the schedule parameter [1] on it and you should be able to get the cycles from the Subscrption Schedule object
[0] https://stripe.com/docs/api/expanding_objects
[1] https://stripe.com/docs/api/subscriptions/object#subscription_object-schedule
for the next due date - that would be on the subscription itself - https://stripe.com/docs/api/subscriptions/object#subscription_object-current_period_end
you'll need to implement some logic to ensure that the next due date isn't when the Subscription Schedule ends
If you see the dashboard, it's able to show it.
monthly payment price should also be obtainable either from the Subscription or from the Subscription Schedule
Wish there was a way to access data just as the dashboard displays
If you get what I mean
i don't really understand the problem. You can retrieve both the next invoice date - which is current_period_end and the amount [0] from the Subscription.
[0] https://stripe.com/docs/api/subscriptions/object#subscription_object-items-data-price-unit_amount
the only problem would be when you are switching to a new phase
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
umm, why not?
Not sure
how do your customers make initial payment? are you using the Payment Element?
Yes
Payment element
Do you notice that the payment method in customer portal is empty
are you creating a subscription schedule first? or creating a subscription then creating a subscription schedule from the existing subscription?
I create customer and then subscription schedule
Do dont create subscription seperately
then you're probably passing in default_settings.default_payment_method : https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-default_settings-default_payment_method
the customers don't have to manually input card details again
can you share an existing subscription schedule id?
sub_sched_1LcJEjDUun9ImF4JT6mJGQY5
hrm, gimme a while to test something
Okay
I'll be off now
But kindly leave the thread open. Will respond to your findings once I'm back online. Thanks mate
i'm guessing that these are the steps you're taking :
- create subscription schedule
- finalize invoice
- use PaymentIntent client_secret (from finalized invoice) to initialize Payment Element
- customer makes payment via Payment Element
what you can do is :
1.1 after creating the subscription schedule - and obtaining the subscription id.
1.2 update the subscription to payment_settings[save_default_payment_method]=on_subscription - https://stripe.com/docs/api/subscriptions/update#update_subscription-payment_settings-save_default_payment_method
this way, when the customer makes payment for that subscription's invoice, the PaymentMethod will automatically be saved as the default payment method