Skip to content

Commit

Permalink
add test for annual subscription (with contribution)
Browse files Browse the repository at this point in the history
  • Loading branch information
shtukas committed Jul 18, 2023
1 parent f63f42f commit cc0d094
Show file tree
Hide file tree
Showing 7 changed files with 15,034 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,42 @@ object SupporterRevenue2023V1V2 {
}
}

def subscriptionRatePlanCharge(
def subscriptionRatePlanCharges(
subscription: ZuoraSubscription,
ratePlan: ZuoraRatePlan
): Either[AmendmentDataFailure, ZuoraRatePlanCharge] = {
ratePlan.ratePlanCharges.headOption match {
case None => {
): Either[AmendmentDataFailure, List[ZuoraRatePlanCharge]] = {

ratePlan.ratePlanCharges match {
case Nil => {
// Although not enforced by the signature of the function, for this error message to make sense we expect that
// the rate plan belongs to the currency
Left(
AmendmentDataFailure(s"Subscription ${subscription.subscriptionNumber} has a rate plan, but with no charge")
)
}
case Some(ratePlanCharge) => Right(ratePlanCharge)
case _ => Right(ratePlan.ratePlanCharges)
}
}

def getOldPrice(
subscription: ZuoraSubscription,
ratePlanCharge: ZuoraRatePlanCharge
ratePlanCharges: List[ZuoraRatePlanCharge]
): Either[AmendmentDataFailure, BigDecimal] = {
ratePlanCharge.price match {
case None => {
ratePlanCharges match {
case Nil => {
// Although not enforced by the signature of the function, for this error message to make sense we expect that
// the rate plan charge belongs to the currency
Left(
AmendmentDataFailure(
s"Subscription ${subscription.subscriptionNumber} has a rate plan charge, but with no currency"
s"Subscription ${subscription.subscriptionNumber} has no rate plan charges"
)
)
}
case Some(price) => Right(price)
case _ => {
Right(ratePlanCharges.map(x => x.price).filter(p => p.isDefined).map(p => p.get).fold(BigDecimal(0)) { (z, i) =>
z + i
})
}
}
}

Expand Down Expand Up @@ -176,9 +181,9 @@ object SupporterRevenue2023V1V2 {
): Either[AmendmentDataFailure, PriceData] = {
for {
ratePlan <- subscriptionRatePlan(subscription)
ratePlanCharge <- subscriptionRatePlanCharge(subscription, ratePlan)
currency = ratePlanCharge.currency
oldPrice <- getOldPrice(subscription, ratePlanCharge)
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"basicInfo" : {
"id" : "8a12873f89548834018958ae044c2954",
"name" : "0015I00000jOTrtQAG",
"accountNumber" : "A01849400",
"notes" : null,
"status" : "Active",
"crmId" : "0015I00000jOTrtQAG",
"batch" : "Batch1",
"invoiceTemplateId" : "2c92a0fb49377eae014951ca848e074b",
"communicationProfileId" : null,
"purchaseOrderNumber" : null,
"customerServiceRepName" : null,
"IdentityId__c" : "109093815",
"sfContactId__c" : "0035I00000dGEJRQA4",
"CCURN__c" : null,
"SpecialDeliveryInstructions__c" : null,
"NonStandardDataReason__c" : null,
"ProcessingAdvice__c" : "NoAdvice",
"CreatedRequestId__c" : "6dc651e4-9ca4-d64c-0000-000000030ab6",
"RetryStatus__c" : null,
"salesRep" : null,
"sequenceSetId" : null
},
"billingAndPayment" : {
"billCycleDay" : 15,
"currency" : "EUR",
"paymentTerm" : "Due Upon Receipt",
"paymentGateway" : "Stripe PaymentIntents GNM Membership",
"defaultPaymentMethodId" : "8a12873f89548834018958ae04822974",
"invoiceDeliveryPrefsPrint" : false,
"invoiceDeliveryPrefsEmail" : false,
"autoPay" : true,
"additionalEmailAddresses" : [ ]
},
"metrics" : {
"balance" : 0.000000000,
"totalInvoiceBalance" : 0.000000000,
"creditBalance" : 0.000000000,
"contractedMrr" : 10.000000000
},
"billToContact" : {
"accountId" : "8a12873f89548834018958ae044c2954",
"accountNumber" : "A01849400",
"address1" : null,
"address2" : null,
"city" : null,
"country" : "Cyprus",
"county" : null,
"fax" : null,
"firstName" : "Barbara",
"homePhone" : null,
"id" : "8a12873f89548834018958ae046d2957",
"lastName" : "J.",
"mobilePhone" : null,
"nickname" : null,
"otherPhone" : null,
"otherPhoneType" : null,
"personalEmail" : null,
"state" : null,
"taxRegion" : null,
"workEmail" : "barbara@ualalliance.com",
"workPhone" : null,
"zipCode" : null,
"Company_Name__c" : null,
"SpecialDeliveryInstructions__c" : null,
"Title__c" : null,
"contactDescription" : null
},
"soldToContact" : {
"accountId" : "8a12873f89548834018958ae044c2954",
"accountNumber" : "A01849400",
"address1" : null,
"address2" : null,
"city" : null,
"country" : "Cyprus",
"county" : null,
"fax" : null,
"firstName" : "Barbara",
"homePhone" : null,
"id" : "8a12873f89548834018958ae046d2957",
"lastName" : "J.",
"mobilePhone" : null,
"nickname" : null,
"otherPhone" : null,
"otherPhoneType" : null,
"personalEmail" : null,
"state" : null,
"taxRegion" : null,
"workEmail" : "barbara@ualalliance.com",
"workPhone" : null,
"zipCode" : null,
"Company_Name__c" : null,
"SpecialDeliveryInstructions__c" : null,
"Title__c" : null,
"contactDescription" : null
},
"taxInfo" : {
"exemptStatus" : "No",
"exemptCertificateId" : null,
"exemptCertificateType" : null,
"exemptIssuingJurisdiction" : null,
"exemptEffectiveDate" : null,
"exemptExpirationDate" : null,
"exemptDescription" : null,
"exemptEntityUseCode" : null,
"companyCode" : null,
"VATId" : null
},
"success" : true
}
Loading

0 comments on commit cc0d094

Please sign in to comment.