Skip to content

Commit

Permalink
Merge pull request #954 from guardian/ph-20231109-0722
Browse files Browse the repository at this point in the history
Align with Zuora period descriptions
  • Loading branch information
shtukas authored Nov 11, 2023
2 parents 926c2af + f9e10dc commit 03f06fd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,9 @@ object NotificationHandler extends CohortHandler {
.unit
}

val paymentFrequencyMapping = Map(
"Month" -> "Monthly",
"Quarter" -> "Quarterly",
"Semi_Annual" -> "Semiannually",
"Annual" -> "Annually"
)

private def paymentFrequency(billingPeriod: String) =
ZIO
.fromOption(paymentFrequencyMapping.get(billingPeriod))
.fromOption(BillingPeriod.notificationPaymentFrequencyMapping.get(billingPeriod))
.orElseFail(EmailSenderFailure(s"No payment frequency mapping found for billing period: $billingPeriod"))

private def updateCohortItemStatus(subscriptionNumber: String, processingStage: CohortTableFilter) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ object DigiSubs2023Migration {
targetRatePlanDetails.ratePlanId,
effectiveDate,
List(
ChargeOverride(targetRatePlanDetails.ratePlanChargeId, BillingPeriod.toString(billingPeriod), newPrice)
ChargeOverride(
targetRatePlanDetails.ratePlanChargeId,
BillingPeriod.toString(billingPeriod),
newPrice
)
)
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ object Annual extends BillingPeriod

object BillingPeriod {

// Note that `toString . fromString` is not the identity function
// on the set { "Month", "Quarterly", "Quarter", "Annual" }
val notificationPaymentFrequencyMapping = Map(
// This map is used to convert a CohortItem's billingPeriod in to the user friendly representation in letters
// and emails.
"Month" -> "Monthly",
"Quarter" -> "Quarterly",
"Quarterly" -> "Quarterly",
"Semi_Annual" -> "Semiannually",
"Annual" -> "Annually"
)

def toString(period: BillingPeriod): String = {
// For Zuora, the billingPeriod should be one of: Month, Quarter, Semi_Annual, Annual, Eighteen_Months,
// Two_Years, Three_Years, Five_Years, Specific_Months, Subscription_Term, Week, Specific_Weeks, Specific_Days

// We are only using Month, Quarter and Annual
period match {
case Monthly => "Month"
case Quarterly => "Quarterly"
case Quarterly => "Quarter"
case Annual => "Annual"
}
}
Expand All @@ -24,6 +35,8 @@ object BillingPeriod {
if (period == "Month") {
Monthly
} else if (period == "Quarterly" || period == "Quarter") {
// This function is used when reading a BillingPeriod from a CohortItem, and we have both
// strings, Quarterly and Quarter in the cohort tables.
Quarterly
} else if (period == "Annual") {
Annual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class DigiSubs2023MigrationTest extends munit.FunSuite {

assertEquals(
priceData(subscription).toOption.get,
PriceData("GBP", BigDecimal(35.95), BigDecimal(44.94), "Quarterly")
PriceData("GBP", BigDecimal(35.95), BigDecimal(44.94), "Quarter")
)

assertEquals(
Expand All @@ -336,7 +336,7 @@ class DigiSubs2023MigrationTest extends munit.FunSuite {
chargeOverrides = List(
ChargeOverride(
productRatePlanChargeId = "2c92a0fb4edd70c9014edeaa4fd42186",
billingPeriod = "Quarterly",
billingPeriod = "Quarter",
price = BigDecimal(44.94)
)
)
Expand Down

0 comments on commit 03f06fd

Please sign in to comment.