Skip to content

Commit

Permalink
echo existing contribution in ZuoraSubscriptionUpdate.add
Browse files Browse the repository at this point in the history
  • Loading branch information
shtukas committed Sep 12, 2024
1 parent 11d2a63 commit aa8dc03
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ object SupporterPlus2024Migration {
}
}

def supporterPlusContributionRatePlanCharge(
def getSupporterPlusContributionRatePlanCharge(
subscriptionNumber: String,
ratePlan: ZuoraRatePlan
): Either[AmendmentDataFailure, ZuoraRatePlanCharge] = {
Expand Down Expand Up @@ -191,7 +191,7 @@ object SupporterPlus2024Migration {
def contributionAmount(subscription: ZuoraSubscription): Either[Failure, Option[BigDecimal]] = {
for {
ratePlan <- getSupporterPlusV2RatePlan(subscription)
ratePlanCharge <- supporterPlusContributionRatePlanCharge(subscription.subscriptionNumber, ratePlan)
ratePlanCharge <- getSupporterPlusContributionRatePlanCharge(subscription.subscriptionNumber, ratePlan)
} yield ratePlanCharge.price
}

Expand Down Expand Up @@ -275,13 +275,23 @@ object SupporterPlus2024Migration {
subscription.subscriptionNumber,
existingRatePlan
)
existingContributionRatePlanCharge <- getSupporterPlusContributionRatePlanCharge(
subscription.subscriptionNumber,
existingRatePlan
)
existingContributionPrice <- existingContributionRatePlanCharge.price.toRight(
AmendmentDataFailure(
s"[22405076] Could not extract existing contribution price for subscription ${subscription.subscriptionNumber}"
)
)
billingPeriod <- ZuoraRatePlan
.ratePlanToBillingPeriod(existingRatePlan)
.toRight(
AmendmentDataFailure(
s"[17469705] Could not determine the billing period for subscription ${subscription.subscriptionNumber}"
)
)

} yield {
ZuoraSubscriptionUpdate(
add = List(
Expand All @@ -293,6 +303,11 @@ object SupporterPlus2024Migration {
productRatePlanChargeId = existingBaseRatePlanCharge.productRatePlanChargeId,
billingPeriod = BillingPeriod.toString(billingPeriod),
price = PriceCap.priceCapForNotification(oldPrice, estimatedNewPrice, priceCap)
),
ChargeOverride(
productRatePlanChargeId = existingContributionRatePlanCharge.productRatePlanChargeId,
billingPeriod = BillingPeriod.toString(billingPeriod),
price = existingContributionPrice
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
test("extracting `Supporter Plus V2` rate plan contribution charge (monthly)") {
val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/monthly/subscription.json")
assertEquals(
SupporterPlus2024Migration.supporterPlusContributionRatePlanCharge(
SupporterPlus2024Migration.getSupporterPlusContributionRatePlanCharge(
subscription.subscriptionNumber,
SupporterPlus2024Migration.getSupporterPlusV2RatePlan(subscription).toOption.get
),
Expand Down Expand Up @@ -404,7 +404,7 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
// read the right price from the subscription.
val subscription = Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/annual/subscription.json")
assertEquals(
SupporterPlus2024Migration.supporterPlusContributionRatePlanCharge(
SupporterPlus2024Migration.getSupporterPlusContributionRatePlanCharge(
subscription.subscriptionNumber,
SupporterPlus2024Migration.getSupporterPlusV2RatePlan(subscription).toOption.get
),
Expand Down Expand Up @@ -441,7 +441,7 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
val subscription =
Fixtures.subscriptionFromJson("Migrations/SupporterPlus2024/sub-without-LastChangeType/subscription.json")
assertEquals(
SupporterPlus2024Migration.supporterPlusContributionRatePlanCharge(
SupporterPlus2024Migration.getSupporterPlusContributionRatePlanCharge(
subscription.subscriptionNumber,
SupporterPlus2024Migration.getSupporterPlusV2RatePlan(subscription).toOption.get
),
Expand Down Expand Up @@ -743,7 +743,12 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
ChargeOverride(
productRatePlanChargeId = "8a128ed885fc6ded018602296af13eba", // base plan charge Id
billingPeriod = "Month",
price = 12.0
price = 12
),
ChargeOverride(
productRatePlanChargeId = "8a128d7085fc6dec01860234cd075270", // contribution charge Id
billingPeriod = "Month",
price = 0.0
)
)
)
Expand Down Expand Up @@ -775,6 +780,11 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
productRatePlanChargeId = "8a128ed885fc6ded01860228f7cb3d5f",
billingPeriod = "Annual",
price = 200.0
),
ChargeOverride(
productRatePlanChargeId = "8a12892d85fc6df4018602451322287f",
billingPeriod = "Annual",
price = 340.0
)
)
)
Expand Down Expand Up @@ -806,6 +816,11 @@ class SupporterPlus2024MigrationTest extends munit.FunSuite {
productRatePlanChargeId = "8a128ed885fc6ded01860228f7cb3d5f",
billingPeriod = "Annual",
price = 190.5
),
ChargeOverride(
productRatePlanChargeId = "8a12892d85fc6df4018602451322287f",
billingPeriod = "Annual",
price = 340.0
)
)
)
Expand Down

0 comments on commit aa8dc03

Please sign in to comment.