@@ -72,6 +72,7 @@ export const Route = createFileRoute("/api/checkout/paystack-verify")({
7272 const metadata = verification . data . metadata as {
7373 organizationId ?: string ;
7474 plan ?: string ;
75+ interval ?: "month" | "year" ;
7576 userId ?: string ;
7677 } ;
7778
@@ -82,7 +83,7 @@ export const Route = createFileRoute("/api/checkout/paystack-verify")({
8283 ) ;
8384 }
8485
85- const { organizationId, plan, userId } = metadata ;
86+ const { organizationId, plan, interval = "month" , userId } = metadata ;
8687
8788 // Verify that the transaction was initiated by the current user
8889 if ( userId !== session . user . id ) {
@@ -116,9 +117,13 @@ export const Route = createFileRoute("/api/checkout/paystack-verify")({
116117 const customerEmail = verification . data . customer . email ;
117118 const customerCode = verification . data . customer . customer_code ;
118119
119- // Calculate next billing date (1 month from now)
120+ // Calculate next billing date based on the checkout interval
120121 const currentPeriodEnd = new Date ( ) ;
121- currentPeriodEnd . setMonth ( currentPeriodEnd . getMonth ( ) + 1 ) ;
122+ if ( interval === "year" ) {
123+ currentPeriodEnd . setFullYear ( currentPeriodEnd . getFullYear ( ) + 1 ) ;
124+ } else {
125+ currentPeriodEnd . setMonth ( currentPeriodEnd . getMonth ( ) + 1 ) ;
126+ }
122127
123128 // Check if subscription exists
124129 const existingSubscription = await db
@@ -138,6 +143,7 @@ export const Route = createFileRoute("/api/checkout/paystack-verify")({
138143 paystackCustomerCode : customerCode ,
139144 paystackAuthorizationCode : authorization . authorization_code ,
140145 paystackEmail : customerEmail ,
146+ billingInterval : interval ,
141147 currentPeriodEnd,
142148 cancelAtPeriodEnd : false ,
143149 canceledAt : null ,
@@ -155,6 +161,7 @@ export const Route = createFileRoute("/api/checkout/paystack-verify")({
155161 paystackCustomerCode : customerCode ,
156162 paystackAuthorizationCode : authorization . authorization_code ,
157163 paystackEmail : customerEmail ,
164+ billingInterval : interval ,
158165 currentPeriodEnd,
159166 cancelAtPeriodEnd : false ,
160167 } ) ;
0 commit comments