@@ -401,63 +401,107 @@ export class ChurnInterventionService {
401401 async determineCancelInterstitialOfferEligibility ( args : {
402402 uid : string ;
403403 subscriptionId : string ;
404- offeringApiIdentifier : string ;
405- currentInterval : SubplatInterval ;
406- upgradeInterval : SubplatInterval ;
407404 acceptLanguage ?: string | null ;
408405 selectedLanguage ?: string ;
409406 } ) {
410- const cmsCancelInterstitialOffer =
411- await this . productConfigurationManager . getCancelInterstitialOffer (
412- args . offeringApiIdentifier ,
413- args . currentInterval ,
414- args . upgradeInterval ,
415- args . acceptLanguage || undefined ,
416- args . selectedLanguage
417- ) ;
407+ const upgradeInterval = SubplatInterval . Yearly ;
408+ const subscription = await this . subscriptionManager . retrieve (
409+ args . subscriptionId
410+ ) ;
418411
419- const cmsCancelInterstitialOfferResult =
420- cmsCancelInterstitialOffer . getTransformedResult ( ) ;
421- if ( ! cmsCancelInterstitialOfferResult ) {
412+ if ( ! subscription ) {
422413 this . statsd . increment ( 'cancel_intervention_decision' , {
423414 type : 'none' ,
424- reason : 'no_cancel_interstitial_offer_found ' ,
415+ reason : 'subscription_not_found ' ,
425416 } ) ;
426417 return {
427418 isEligible : false ,
428- reason : 'no_cancel_interstitial_offer_found ' ,
419+ reason : 'subscription_not_found ' ,
429420 cmsCancelInterstitialOfferResult : null ,
430421 } ;
431422 }
432423
433- const currentStripeInterval =
424+ const currentInterval =
434425 await this . productConfigurationManager . getSubplatIntervalBySubscription (
435- args . subscriptionId
426+ subscription
436427 ) ;
437- if (
438- ! currentStripeInterval ||
439- currentStripeInterval !== args . currentInterval
440- ) {
428+
429+ if ( ! currentInterval ) {
441430 this . statsd . increment ( 'cancel_intervention_decision' , {
442431 type : 'none' ,
443- reason : 'current_interval_mismatch ' ,
432+ reason : 'current_interval_not_found ' ,
444433 } ) ;
445434 return {
446435 isEligible : false ,
447- reason : 'current_interval_mismatch' ,
436+ reason : 'current_interval_not_found' ,
437+ cmsCancelInterstitialOfferResult : null ,
438+ } ;
439+ }
440+
441+ const stripePriceId = subscription . items . data . at ( 0 ) ?. price . id ;
442+
443+ if ( ! stripePriceId ) {
444+ this . statsd . increment ( 'cancel_intervention_decision' , {
445+ type : 'none' ,
446+ reason : 'stripe_price_id_not_found' ,
447+ } ) ;
448+ return {
449+ isEligible : false ,
450+ reason : 'stripe_price_id_not_found' ,
451+ cmsCancelInterstitialOfferResult : null ,
452+ } ;
453+ }
454+
455+ const result =
456+ await this . productConfigurationManager . getPageContentByPriceIds ( [
457+ stripePriceId ,
458+ ] ) ;
459+ const offeringId =
460+ result . purchaseForPriceId ( stripePriceId ) . offering ?. apiIdentifier ;
461+
462+ if ( ! offeringId ) {
463+ this . statsd . increment ( 'cancel_intervention_decision' , {
464+ type : 'none' ,
465+ reason : 'offering_id_not_found' ,
466+ } ) ;
467+ return {
468+ isEligible : false ,
469+ reason : 'offering_id_not_found' ,
470+ cmsCancelInterstitialOfferResult : null ,
471+ } ;
472+ }
473+
474+ const cmsCancelInterstitialOffer =
475+ await this . productConfigurationManager . getCancelInterstitialOffer (
476+ offeringId ,
477+ currentInterval ,
478+ upgradeInterval ,
479+ args . acceptLanguage || undefined ,
480+ args . selectedLanguage
481+ ) ;
482+ const cmsCancelInterstitialOfferResult =
483+ cmsCancelInterstitialOffer . getTransformedResult ( ) ;
484+
485+ if ( ! cmsCancelInterstitialOfferResult ) {
486+ this . statsd . increment ( 'cancel_intervention_decision' , {
487+ type : 'none' ,
488+ reason : 'no_cancel_interstitial_offer_found' ,
489+ } ) ;
490+ return {
491+ isEligible : false ,
492+ reason : 'no_cancel_interstitial_offer_found' ,
448493 cmsCancelInterstitialOfferResult : null ,
449494 } ;
450495 }
451496
452497 try {
453498 await this . productConfigurationManager . retrieveStripePrice (
454- args . offeringApiIdentifier ,
455- args . upgradeInterval
499+ offeringId ,
500+ upgradeInterval
456501 ) ;
457502 } catch {
458503 this . statsd . increment ( 'cancel_intervention_decision' , {
459- type : 'none' ,
460- reason : 'no_upgrade_plan_found' ,
504+ type : 'cancel_interstitial_offer' ,
461505 } ) ;
462506 return {
463507 isEligible : false ,
@@ -467,8 +511,8 @@ export class ChurnInterventionService {
467511 }
468512
469513 const eligibility = await this . eligibilityService . checkEligibility (
470- args . upgradeInterval ,
471- args . offeringApiIdentifier ,
514+ upgradeInterval ,
515+ offeringId ,
472516 args . uid ,
473517 args . subscriptionId
474518 ) ;
0 commit comments