From cf0b8078e4c22c87fd85a4a6fbb08b8442b31895 Mon Sep 17 00:00:00 2001 From: Dotan Simha Date: Thu, 19 May 2022 15:15:20 +0300 Subject: [PATCH] Fix issues with Stripe billing cycle (#36) --- packages/services/stripe-billing/src/api.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/services/stripe-billing/src/api.ts b/packages/services/stripe-billing/src/api.ts index 940e91cce..f3495c6ae 100644 --- a/packages/services/stripe-billing/src/api.ts +++ b/packages/services/stripe-billing/src/api.ts @@ -3,7 +3,7 @@ import { z } from 'zod'; import { inferProcedureInput, inferProcedureOutput } from '@trpc/server'; import { createStorage } from '@hive/storage'; import { Stripe } from 'stripe'; -import { addMonths, startOfMonth } from 'date-fns'; +import { addDays, startOfMonth } from 'date-fns'; export type Context = { storage$: ReturnType; @@ -303,15 +303,16 @@ export const stripeBillingApiRouter = trpc const stripePrices = await ctx.stripeData$; const subscription = await ctx.stripe.subscriptions.create({ - trial_period_days: 14, metadata: { hive_subscription: 'true', }, coupon: input.couponCode || undefined, customer: customerId, default_payment_method: paymentMethodId, - billing_cycle_anchor: - startOfMonth(addMonths(new Date(), 1)).getTime() / 1000, + trial_end: Math.floor(addDays(new Date(), 14).getTime() / 1000), + backdate_start_date: Math.floor( + startOfMonth(new Date()).getTime() / 1000 + ), items: [ { price: stripePrices.basePrice.id,