#alphatings

1 messages · Page 1 of 1 (latest)

ember domeBOT
fiery current
#
    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

grand sedge
#

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?

fiery current
#

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?

grand sedge
#

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

fiery current
#

Should I setup webhooks before trying the test clocks or just send it with the test clocks?

grand sedge
#

Up to you. You don't need to

#

You can see all the events generated in the dashboard

fiery current
#

Sounds good, thanks for the input!

#

Also another quick question

#

for automatic taxes based on their location, am I able to set this up via a subscription schedule or do I just update it via the subscription itself?