33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
55import { Inject , Injectable , Logger , type LoggerService } from '@nestjs/common' ;
6- import { ChurnInterventionManager } from '@fxa/payments/cart' ;
6+ import {
7+ ChurnInterventionConfig ,
8+ ChurnInterventionManager ,
9+ } from '@fxa/payments/cart' ;
710import {
811 ChurnInterventionByProductIdResultUtil ,
912 ProductConfigurationManager ,
@@ -22,6 +25,18 @@ import {
2225 ChurnInterventionProductIdentifierMissingError ,
2326 ChurnSubscriptionCustomerMismatchError ,
2427} from './churn-intervention.error' ;
28+ export enum Enum_Churnintervention_Churntype {
29+ Cancel = 'cancel' ,
30+ StaySubscribed = 'stay_subscribed'
31+ }
32+
33+ export enum Enum_Churnintervention_Interval {
34+ Daily = 'daily' ,
35+ Halfyearly = 'halfyearly' ,
36+ Monthly = 'monthly' ,
37+ Weekly = 'weekly' ,
38+ Yearly = 'yearly'
39+ }
2540
2641@Injectable ( )
2742export class ChurnInterventionService {
@@ -34,9 +49,14 @@ export class ChurnInterventionService {
3449 private profileClient : ProfileClient ,
3550 private subscriptionManager : SubscriptionManager ,
3651 @Inject ( StatsDService ) private statsd : StatsD ,
37- @Inject ( Logger ) private log : LoggerService
52+ @Inject ( Logger ) private log : LoggerService ,
53+ private churnInterventionConfig : ChurnInterventionConfig
3854 ) { }
3955
56+ private isFeatureEnabled ( ) : boolean {
57+ return this . churnInterventionConfig . enabled ?? false ;
58+ }
59+
4060 /**
4161 * Reload the customer data to reflect a change.
4262 * NOTE: This is currently duplicated in subscriptionManagement.service.ts
@@ -71,6 +91,10 @@ export class ChurnInterventionService {
7191 acceptLanguage ?: string ,
7292 selectedLanguage ?: string
7393 ) {
94+ if ( ! this . isFeatureEnabled ( ) ) {
95+ return { churnInterventions : [ ] } ;
96+ }
97+
7498 let util : ChurnInterventionByProductIdResultUtil ;
7599 if ( stripeProductId ) {
76100 util = await this . productConfigurationManager . getChurnIntervention (
@@ -105,6 +129,15 @@ export class ChurnInterventionService {
105129 acceptLanguage ?: string | null ,
106130 selectedLanguage ?: string
107131 ) {
132+ if ( ! this . isFeatureEnabled ( ) ) {
133+ return {
134+ isEligible : false ,
135+ reason : 'feature_disabled' ,
136+ cmsChurnInterventionEntry : null ,
137+ cmsOfferingContent : null ,
138+ } ;
139+ }
140+
108141 try {
109142 const cmsChurnResult =
110143 await this . productConfigurationManager . getChurnInterventionBySubscription (
@@ -245,6 +278,13 @@ export class ChurnInterventionService {
245278 acceptLanguage ?: string | null ,
246279 selectedLanguage ?: string
247280 ) {
281+ if ( ! this . isFeatureEnabled ( ) ) {
282+ return {
283+ redeemed : false ,
284+ errorCode : 'feature_disabled' ,
285+ } ;
286+ }
287+
248288 const eligibilityResult = await this . determineStaySubscribedEligibility (
249289 uid ,
250290 subscriptionId ,
@@ -330,6 +370,13 @@ export class ChurnInterventionService {
330370 acceptLanguage ?: string | null ;
331371 selectedLanguage ?: string ;
332372 } ) {
373+ if ( ! this . isFeatureEnabled ( ) ) {
374+ return {
375+ cancelChurnInterventionType : 'none' ,
376+ cmsOfferContent : null ,
377+ } ;
378+ }
379+
333380 try {
334381 const accountCustomer =
335382 await this . accountCustomerManager . getAccountCustomerByUid ( args . uid ) ;
@@ -422,6 +469,15 @@ export class ChurnInterventionService {
422469 acceptLanguage ?: string | null ;
423470 selectedLanguage ?: string ;
424471 } ) {
472+ if ( ! this . isFeatureEnabled ( ) ) {
473+ return {
474+ isEligible : false ,
475+ reason : 'feature_disabled' ,
476+ cmsOfferContent : null ,
477+ cmsOfferingContent : null ,
478+ } ;
479+ }
480+
425481 const upgradeInterval = SubplatInterval . Yearly ;
426482 const subscription = await this . subscriptionManager . retrieve (
427483 args . subscriptionId
@@ -566,6 +622,14 @@ export class ChurnInterventionService {
566622 acceptLanguage ?: string | null ;
567623 selectedLanguage ?: string ;
568624 } ) {
625+ if ( ! this . isFeatureEnabled ( ) ) {
626+ return {
627+ isEligible : false ,
628+ reason : 'feature_disabled' ,
629+ cmsChurnInterventionEntry : null ,
630+ } ;
631+ }
632+
569633 const cmsChurnResult =
570634 await this . productConfigurationManager . getChurnInterventionBySubscription (
571635 args . subscriptionId ,
0 commit comments