@@ -2,6 +2,7 @@ import type { NextApiRequest } from "next";
2
2
3
3
import { getStripeCustomerIdFromUserId } from "@calcom/app-store/stripepayment/lib/customer" ;
4
4
import stripe from "@calcom/app-store/stripepayment/lib/server" ;
5
+ import { getDubCustomer } from "@calcom/features/auth/lib/dub" ;
5
6
import { IS_PRODUCTION } from "@calcom/lib/constants" ;
6
7
import { IS_TEAM_BILLING_ENABLED , WEBAPP_URL } from "@calcom/lib/constants" ;
7
8
import { HttpError } from "@calcom/lib/http-error" ;
@@ -192,11 +193,26 @@ const generateTeamCheckoutSession = async ({
192
193
pendingPaymentTeamId : number ;
193
194
ownerId : number ;
194
195
} ) => {
195
- const customer = await getStripeCustomerIdFromUserId ( ownerId ) ;
196
+ const [ customer , dubCustomer ] = await Promise . all ( [
197
+ getStripeCustomerIdFromUserId ( ownerId ) ,
198
+ getDubCustomer ( ownerId . toString ( ) ) ,
199
+ ] ) ;
200
+
196
201
const session = await stripe . checkout . sessions . create ( {
197
202
customer,
198
203
mode : "subscription" ,
199
- allow_promotion_codes : true ,
204
+ ...( dubCustomer ?. discount ?. couponId
205
+ ? {
206
+ discounts : [
207
+ {
208
+ coupon :
209
+ process . env . NODE_ENV !== "production" && dubCustomer . discount . couponTestId
210
+ ? dubCustomer . discount . couponTestId
211
+ : dubCustomer . discount . couponId ,
212
+ } ,
213
+ ] ,
214
+ }
215
+ : { allow_promotion_codes : true } ) ,
200
216
success_url : `${ WEBAPP_URL } /api/teams/api/create?session_id={CHECKOUT_SESSION_ID}` ,
201
217
cancel_url : `${ WEBAPP_URL } /settings/my-account/profile` ,
202
218
line_items : [
0 commit comments