Skip to content

Commit

Permalink
Merge pull request #904 from guardian/ph-20230720-1149-curious-case
Browse files Browse the repository at this point in the history
supporter plus, resolving a curious-case
  • Loading branch information
shtukas authored Jul 20, 2023
2 parents 9cf3b0f + f93ad3b commit 1dbfc35
Show file tree
Hide file tree
Showing 7 changed files with 14,804 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object SupporterPlus2023V1V2 {
)

def subscriptionRatePlan(subscription: ZuoraSubscription): Either[AmendmentDataFailure, ZuoraRatePlan] = {
subscription.ratePlans.headOption match {
subscription.ratePlans.filter(rp => rp.productName == "Supporter Plus").headOption match {
case None =>
Left(AmendmentDataFailure(s"Subscription ${subscription.subscriptionNumber} doesn't have any rate plan"))
case Some(ratePlan) => Right(ratePlan)
Expand Down Expand Up @@ -177,14 +177,33 @@ object SupporterPlus2023V1V2 {
nextServiceDate: LocalDate,
cohortSpec: CohortSpec
): Either[AmendmentDataFailure, PriceData] = {
for {
val result = (for {
ratePlan <- subscriptionRatePlan(subscription)
ratePlanCharges <- subscriptionRatePlanCharges(subscription, ratePlan)
currency = ratePlanCharges.head.currency
oldPrice <- getOldPrice(subscription, ratePlanCharges)
billingP <- billingPeriod(account, catalogue, subscription, invoiceList, nextServiceDate)
newPrice <- currencyToNewPrice(billingP, currency: String)
} yield PriceData(currency, oldPrice, newPrice, billingP)
} yield {
PriceData(currency, oldPrice, newPrice, billingP)
})
result match {
case Left(_) => result
case Right(priceData) => {
if (priceData.newPrice <= priceData.oldPrice) {
Right(priceData)
} else {
// I this case the new price is higher than the old price. (Meaning that the v2 rate plan is higher than the)
// old rate plan charge plus whichever extra contribution the subscription was paying.
// We would want to know about that and investigate.
Left(
AmendmentDataFailure(
s"[SupporterPlus2023V1V2] Possibly incorrect pricing for subscription ${subscription.subscriptionNumber}. The new price, ${priceData.newPrice}, is higher than the old price, ${priceData.oldPrice}."
)
)
}
}
}
}

def updateOfRatePlanToCurrentMonth(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"basicInfo" : {
"id" : "ACCOUNT-ID",
"name" : "0010J00001qxpcAQAQ",
"accountNumber" : "ACCOUNT-NUMBER",
"notes" : null,
"status" : "Active",
"crmId" : "0010J00001qxpcAQAQ",
"batch" : "Batch1",
"invoiceTemplateId" : "2c92a0fb49377eae014951ca848e074b",
"communicationProfileId" : null,
"purchaseOrderNumber" : null,
"customerServiceRepName" : null,
"IdentityId__c" : "IDENTITY-ID-C",
"sfContactId__c" : "SF-CONTACT-ID-C",
"CCURN__c" : null,
"SpecialDeliveryInstructions__c" : null,
"NonStandardDataReason__c" : null,
"ProcessingAdvice__c" : null,
"CreatedRequestId__c" : null,
"RetryStatus__c" : null,
"salesRep" : null,
"sequenceSetId" : null
},
"billingAndPayment" : {
"billCycleDay" : 20,
"currency" : "GBP",
"paymentTerm" : "Due Upon Receipt",
"paymentGateway" : "PayPal Express",
"defaultPaymentMethodId" : "2c92a0fd61b08db60161b28c0e7448c2",
"invoiceDeliveryPrefsPrint" : false,
"invoiceDeliveryPrefsEmail" : false,
"autoPay" : true,
"additionalEmailAddresses" : [ ]
},
"metrics" : {
"balance" : 0.000000000,
"totalInvoiceBalance" : 0.000000000,
"creditBalance" : 0.000000000,
"contractedMrr" : 10.000000000
},
"billToContact" : null,
"soldToContact" : null,
"taxInfo" : null,
"success" : true
}
Loading

0 comments on commit 1dbfc35

Please sign in to comment.