#alphatings
1 messages · Page 1 of 1 (latest)
const createOrgResult = await Organization.createOrganization({
email,
name,
ownerId,
});
const createdCustomer = await stripe.customers.create({
email,
name,
metadata: { DB_OrganizationId: `${createOrgResult._id.valueOf()}` },
});
const proPrice = await stripe.prices.list({
lookup_keys: [`ProfessionalBasePriceV1`],
});
const proPriceID = proPrice.data[0].id;
// get thirty days from now in unix time
const thirtyDaysFromNow = new Date();
thirtyDaysFromNow.setDate(thirtyDaysFromNow.getDate() + 30);
thirtyDaysFromNow.setHours(0, 0, 0, 0);
const thirtyDaysFromNowUnix = Math.floor(thirtyDaysFromNow.getTime() / 1000);
// get the first of the month in unix time from the ThirtyDaysFromNow variable
const firstOfTheMonth = new Date(thirtyDaysFromNow.getFullYear(), thirtyDaysFromNow.getMonth(), 1);
firstOfTheMonth.setHours(0, 0, 0, 0);
const firstOfTheMonthUnix = Math.floor(firstOfTheMonth.getTime() / 1000);
const subscriptionsSchedule = await stripe.subscriptionSchedules.create({
customer: createdCustomer.id,
start_date: "now",
end_behavior: "release",
phases: [
{
items: [
{
price: proPriceID,
quantity: 1,
},
],
end_date: thirtyDaysFromNowUnix,
trial_end: thirtyDaysFromNowUnix,
trial_start: "now",
iterations: 1,
},
{
items: [
{
price: proPriceID,
quantity: 1,
},
],
start_date: thirtyDaysFromNowUnix,
end_date: firstOfTheMonthUnix,
proration_behavior: 'create_prorations',
billing_cycle_anchor: firstOfTheMonthUnix,
},
],
});
^ my code for refrence
You shouldn't need a subscription schedule for this
You should just be able to create a normal subscription with a trial
Why do you use a schedule?
I want the user to be billed on the 1st of every month after their trial,
use case:
User joins our platform on today 9/14/2023
The trial goes until 10/14/2023
I want them to be prorated from 10/14/2023 to 10/31/2023 and then from then on always be billed on the 1st of the month
Can I do that with just a trail subscription?
Ah got it
That makes sense. No a schedule is right for that
So if the customer doesn't provide payment info then payment will just fail. The behavior depends on your subscription settings
Recomend you use test clocks to try this out: https://stripe.com/docs/billing/testing/test-clocks. That way you can test what the behavior will look like fully
Should I setup webhooks before trying the test clocks or just send it with the test clocks?