|
|
@ -86,7 +86,7 @@ export class SubscriptionService { |
|
|
{ |
|
|
{ |
|
|
allowed_payment_method_types: ['card'], |
|
|
allowed_payment_method_types: ['card'], |
|
|
cancel_url: `${this.configurationService.get('ROOT_URL')}/${ |
|
|
cancel_url: `${this.configurationService.get('ROOT_URL')}/${ |
|
|
user.settings.settings.language |
|
|
user.settings?.settings?.language ?? DEFAULT_LANGUAGE_CODE |
|
|
}/account`,
|
|
|
}/account`,
|
|
|
client_reference_id: user.id, |
|
|
client_reference_id: user.id, |
|
|
line_items: [ |
|
|
line_items: [ |
|
|
@ -115,6 +115,10 @@ export class SubscriptionService { |
|
|
stripeCheckoutSessionCreateParams |
|
|
stripeCheckoutSessionCreateParams |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (!session.url) { |
|
|
|
|
|
throw new Error(`Stripe Checkout Session '${session.id}' is missing url`); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
sessionUrl: session.url |
|
|
sessionUrl: session.url |
|
|
}; |
|
|
}; |
|
|
@ -170,10 +174,16 @@ export class SubscriptionService { |
|
|
|
|
|
|
|
|
const durationExtension = subscriptionOffer?.durationExtension; |
|
|
const durationExtension = subscriptionOffer?.durationExtension; |
|
|
|
|
|
|
|
|
|
|
|
if (!session.client_reference_id) { |
|
|
|
|
|
throw new Error( |
|
|
|
|
|
`Stripe Checkout Session '${aCheckoutSessionId}' is missing client_reference_id` |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
await this.createSubscription({ |
|
|
await this.createSubscription({ |
|
|
durationExtension, |
|
|
durationExtension, |
|
|
price: session.amount_total / 100, |
|
|
price: (session.amount_total ?? 0) / 100, |
|
|
stripeCheckoutSessionId: session.id, |
|
|
stripeCheckoutSessionId: session.id, |
|
|
userId: session.client_reference_id |
|
|
userId: session.client_reference_id |
|
|
}); |
|
|
}); |
|
|
@ -214,11 +224,11 @@ export class SubscriptionService { |
|
|
|
|
|
|
|
|
let offerKey: SubscriptionOfferKey = price ? 'renewal' : 'default'; |
|
|
let offerKey: SubscriptionOfferKey = price ? 'renewal' : 'default'; |
|
|
|
|
|
|
|
|
if (isBefore(createdAt, parseDate('2023-01-01'))) { |
|
|
if (createdAt && isBefore(createdAt, parseDate('2023-01-01')!)) { |
|
|
offerKey = 'renewal-early-bird-2023'; |
|
|
offerKey = 'renewal-early-bird-2023'; |
|
|
} else if (isBefore(createdAt, parseDate('2024-01-01'))) { |
|
|
} else if (createdAt && isBefore(createdAt, parseDate('2024-01-01')!)) { |
|
|
offerKey = 'renewal-early-bird-2024'; |
|
|
offerKey = 'renewal-early-bird-2024'; |
|
|
} else if (isBefore(createdAt, parseDate('2025-12-01'))) { |
|
|
} else if (createdAt && isBefore(createdAt, parseDate('2025-12-01')!)) { |
|
|
offerKey = 'renewal-early-bird-2025'; |
|
|
offerKey = 'renewal-early-bird-2025'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -227,9 +237,9 @@ export class SubscriptionService { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
offer, |
|
|
|
|
|
subscribedAt, |
|
|
subscribedAt, |
|
|
expiresAt: isBefore(new Date(), expiresAt) ? expiresAt : undefined, |
|
|
expiresAt: isBefore(new Date(), expiresAt) ? expiresAt : undefined, |
|
|
|
|
|
offer: offer as SubscriptionOffer, |
|
|
type: isBefore(new Date(), expiresAt) |
|
|
type: isBefore(new Date(), expiresAt) |
|
|
? SubscriptionType.Premium |
|
|
? SubscriptionType.Premium |
|
|
: SubscriptionType.Basic |
|
|
: SubscriptionType.Basic |
|
|
@ -240,7 +250,7 @@ export class SubscriptionService { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
offer, |
|
|
offer: offer as SubscriptionOffer, |
|
|
type: SubscriptionType.Basic |
|
|
type: SubscriptionType.Basic |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
@ -250,7 +260,7 @@ export class SubscriptionService { |
|
|
key |
|
|
key |
|
|
}: { |
|
|
}: { |
|
|
key: SubscriptionOfferKey; |
|
|
key: SubscriptionOfferKey; |
|
|
}): Promise<SubscriptionOffer> { |
|
|
}): Promise<SubscriptionOffer | undefined> { |
|
|
if (!this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) { |
|
|
if (!this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) { |
|
|
return undefined; |
|
|
return undefined; |
|
|
} |
|
|
} |
|
|
@ -267,7 +277,7 @@ export class SubscriptionService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private getStripeLocale( |
|
|
private getStripeLocale( |
|
|
languageCode: string |
|
|
languageCode?: string |
|
|
): Stripe.Checkout.SessionCreateParams.Locale { |
|
|
): Stripe.Checkout.SessionCreateParams.Locale { |
|
|
const unsupportedLanguageCodes: Record< |
|
|
const unsupportedLanguageCodes: Record< |
|
|
Exclude< |
|
|
Exclude< |
|
|
@ -286,6 +296,7 @@ export class SubscriptionService { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if ( |
|
|
if ( |
|
|
|
|
|
languageCode && |
|
|
(SUPPORTED_LANGUAGE_CODES as readonly string[]).includes(languageCode) && |
|
|
(SUPPORTED_LANGUAGE_CODES as readonly string[]).includes(languageCode) && |
|
|
!(languageCode in unsupportedLanguageCodes) |
|
|
!(languageCode in unsupportedLanguageCodes) |
|
|
) { |
|
|
) { |
|
|
|