From 34f54018df100f57c72791e777b68c68960a88b9 Mon Sep 17 00:00:00 2001 From: Andrea Diotallevi Date: Mon, 2 Sep 2024 13:09:44 +0300 Subject: [PATCH 1/2] feat: remove hard-coded invoice template IDs --- .../com/gu/invoicing/common/ZuoraAuth.scala | 6 ------ src/main/scala/com/gu/invoicing/pdf/Impl.scala | 13 +------------ .../scala/com/gu/invoicing/pdf/Program.scala | 18 +----------------- 3 files changed, 2 insertions(+), 35 deletions(-) diff --git a/src/main/scala/com/gu/invoicing/common/ZuoraAuth.scala b/src/main/scala/com/gu/invoicing/common/ZuoraAuth.scala index 36f0d26..4fd7430 100644 --- a/src/main/scala/com/gu/invoicing/common/ZuoraAuth.scala +++ b/src/main/scala/com/gu/invoicing/common/ZuoraAuth.scala @@ -24,12 +24,6 @@ object ZuoraAuth extends JsonSupport { case "PROD" => "https://rest.zuora.com" } - lazy val GNMAustralia_InvoiceTemplateID: String = - stage match { - case "CODE" => "2c92c0f85ecc47e5015ee7360d602757" - case "PROD" => "2c92a0fd5ecce80c015ee71028643020" - } // GNM Australia Pty Ltd - /** Because list invoices is hit frequently JVM is kept warm and val access token would seem to persist across lambda * executions which meant the token would expire after one hour and because it was val it would not be requested * again. Hence now we periodically refreshes the token (making it def would have performance penalty) diff --git a/src/main/scala/com/gu/invoicing/pdf/Impl.scala b/src/main/scala/com/gu/invoicing/pdf/Impl.scala index 0fefba5..bb5134b 100644 --- a/src/main/scala/com/gu/invoicing/pdf/Impl.scala +++ b/src/main/scala/com/gu/invoicing/pdf/Impl.scala @@ -1,6 +1,6 @@ package com.gu.invoicing.pdf -import com.gu.invoicing.common.ZuoraAuth.{accessToken, zuoraApiHost, GNMAustralia_InvoiceTemplateID} +import com.gu.invoicing.common.ZuoraAuth.{accessToken, zuoraApiHost} import com.gu.invoicing.pdf.Model._ import com.gu.invoicing.common.Http import scala.util.chaining._ @@ -23,17 +23,6 @@ object Impl { .body .pipe(read[PutResponse](_)) - def setGNMAustraliaInvoiceTemplateId(accountId: String): PutResponse = { - Http(s"$zuoraApiHost/v1/object/account/$accountId") - .header("Authorization", s"Bearer $accessToken") - .put( - s"""{"InvoiceTemplateId":"$GNMAustralia_InvoiceTemplateID"}""", - ) - .asString - .body - .pipe(read[PutResponse](_)) - } - def getAccount(accountId: String): Account = Http(s"$zuoraApiHost/v1/accounts/$accountId") .header("Authorization", s"Bearer $accessToken") diff --git a/src/main/scala/com/gu/invoicing/pdf/Program.scala b/src/main/scala/com/gu/invoicing/pdf/Program.scala index 72b66f3..8f31495 100644 --- a/src/main/scala/com/gu/invoicing/pdf/Program.scala +++ b/src/main/scala/com/gu/invoicing/pdf/Program.scala @@ -3,7 +3,6 @@ package com.gu.invoicing.pdf import com.gu.invoicing.pdf.Model._ import com.gu.invoicing.pdf.Impl._ import com.gu.invoicing.common.Retry._ -import com.gu.invoicing.common.ZuoraAuth.{GNMAustralia_InvoiceTemplateID} import java.lang.System.getenv @@ -18,21 +17,6 @@ object Program { identityId == account.basicInfo.IdentityId__c, s"Requested invoice id: $invoiceId appears to belong to different identity: ${account.basicInfo.IdentityId__c}", ) - if (repairRequired(account)) { - setGNMAustraliaInvoiceTemplateId(invoice.AccountId) - regenerateInvoice(invoice.Id) - getInvoice(invoice.Id).Body - } else { - invoice.Body - } + invoice.Body } - - // If the sold to country is Australia, the currency is AUD but the invoice template ID is not the correct one, - // then repair things by setting the correct invoice template ID, regenerating the PDF, and re-getting the PDF body. - private def repairRequired(account: Account): Boolean = { - account.soldToContact.country == "Australia" && - account.billingAndPayment.currency == "AUD" && - account.basicInfo.invoiceTemplateId != GNMAustralia_InvoiceTemplateID - } - } From f0e66bd7d5b4072fec761a8481ea8cd3824a1d35 Mon Sep 17 00:00:00 2001 From: Andrea Diotallevi Date: Mon, 2 Sep 2024 14:33:04 +0300 Subject: [PATCH 2/2] feat: remove hard-coded invoice template IDs --- .gitignore | 1 + src/main/scala/com/gu/invoicing/pdf/Model.scala | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 53b0e28..eca89e9 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ project/boot/ project/plugins/project/ metals.sbt .sc +.metals \ No newline at end of file diff --git a/src/main/scala/com/gu/invoicing/pdf/Model.scala b/src/main/scala/com/gu/invoicing/pdf/Model.scala index 7cf0c23..5a37212 100644 --- a/src/main/scala/com/gu/invoicing/pdf/Model.scala +++ b/src/main/scala/com/gu/invoicing/pdf/Model.scala @@ -16,7 +16,7 @@ object Model extends JsonSupport { AccountId: String, Body: String, /* Base64 encoded PDF */ ) - case class BasicInfo(IdentityId__c: String, invoiceTemplateId: String) + case class BasicInfo(IdentityId__c: String) case class BillingAndPayment(currency: String) case class SoldToContact(country: String) case class Account(