From 589bc1f4f5897d7510f64858216d867d295eada1 Mon Sep 17 00:00:00 2001 From: Danilo Cardoso Date: Fri, 22 Nov 2024 14:06:01 +0100 Subject: [PATCH] feat: capturePspReference attribute for paypal auth flow --- .../classes/AdyenPaymentUtility.cls-meta.xml | 2 +- .../default/classes/AdyenRefundHelper.cls | 2 ++ .../classes/AdyenRefundHelper.cls-meta.xml | 2 +- .../default/classes/AdyenRefundHelperTest.cls | 26 +++++++++++++++++++ .../AdyenRefundHelperTest.cls-meta.xml | 5 ++++ manifest/package.xml | 3 ++- 6 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 force-app/main/default/classes/AdyenRefundHelperTest.cls create mode 100644 force-app/main/default/classes/AdyenRefundHelperTest.cls-meta.xml diff --git a/force-app/main/default/classes/AdyenPaymentUtility.cls-meta.xml b/force-app/main/default/classes/AdyenPaymentUtility.cls-meta.xml index 651b172..998805a 100644 --- a/force-app/main/default/classes/AdyenPaymentUtility.cls-meta.xml +++ b/force-app/main/default/classes/AdyenPaymentUtility.cls-meta.xml @@ -1,5 +1,5 @@ - 61.0 + 62.0 Active diff --git a/force-app/main/default/classes/AdyenRefundHelper.cls b/force-app/main/default/classes/AdyenRefundHelper.cls index 6deccd5..7e43e10 100644 --- a/force-app/main/default/classes/AdyenRefundHelper.cls +++ b/force-app/main/default/classes/AdyenRefundHelper.cls @@ -33,6 +33,7 @@ public with sharing class AdyenRefundHelper { return processRefundResponse(refundResponse, refundRequest.amount); } + @TestVisible private static CheckoutRefundRequest createRefundRequest(CommercePayments.ReferencedRefundRequest refundRequest, Payment payment, Adyen_Adapter__mdt adyenAdapter) { CheckoutRefundRequest modRequest = (CheckoutRefundRequest)AdyenPaymentUtility.createModificationRequest(refundRequest, payment.CurrencyIsoCode, adyenAdapter); //Only for Paypal Refunds - Capture reference must be a substring of refund reference @@ -40,6 +41,7 @@ public with sharing class AdyenRefundHelper { if (payment.PaymentAuthorization.Adyen_Payment_Method_Variant__c.equalsIgnoreCase('Paypal') && String.isNotBlank(payment.GatewayRefDetails)) { String refundReference = modRequest.getReference() + payment.GatewayRefDetails; modRequest.setReference(refundReference); + modRequest.capturePspReference = payment.GatewayRefNumber; } } // Line items required for partial refunds for Open Invoice methods diff --git a/force-app/main/default/classes/AdyenRefundHelper.cls-meta.xml b/force-app/main/default/classes/AdyenRefundHelper.cls-meta.xml index f5e18fd..998805a 100644 --- a/force-app/main/default/classes/AdyenRefundHelper.cls-meta.xml +++ b/force-app/main/default/classes/AdyenRefundHelper.cls-meta.xml @@ -1,5 +1,5 @@ - 60.0 + 62.0 Active diff --git a/force-app/main/default/classes/AdyenRefundHelperTest.cls b/force-app/main/default/classes/AdyenRefundHelperTest.cls new file mode 100644 index 0000000..31cecb7 --- /dev/null +++ b/force-app/main/default/classes/AdyenRefundHelperTest.cls @@ -0,0 +1,26 @@ +@IsTest +private class AdyenRefundHelperTest { + @IsTest + static void createPaypalAuthRefundRequestTest() { + // Given + Account acct = TestDataFactory.createAccount(); + insert acct; + CardPaymentMethod cardPayMeth = TestDataFactory.createCardPaymentMethod(); + insert cardPayMeth; + PaymentAuthorization payAuth = TestDataFactory.createPaymentAuthorization(acct.Id, cardPayMeth.Id, null, null, TestDataFactory.TEST_PSP_REFERENCE); + payAuth.Adyen_Payment_Method_Variant__c = 'paypal'; + insert payAuth; + Payment payment = TestDataFactory.createPayment(acct.Id, cardPayMeth.Id, null, payAuth.Id, null); + payment.GatewayRefDetails = 'FO_007'; + insert payment; + payment.PaymentAuthorization = [SELECT Adyen_Payment_Method_Variant__c FROM PaymentAuthorization WHERE Id = :payAuth.Id]; + CommercePayments.ReferencedRefundRequest refundRequest = new CommercePayments.ReferencedRefundRequest(TestDataFactory.TEST_PRICE_AMOUNT, payment.Id); + + // Then + CheckoutRefundRequest modificationRequest = AdyenRefundHelper.createRefundRequest(refundRequest, payment, AdyenPaymentUtility.chooseAdapterWithFallBack(null)); + + // When + Assert.isNotNull(modificationRequest.capturePspReference); + Assert.areEqual(TestDataFactory.TEST_PSP_REFERENCE, modificationRequest.capturePspReference); + } +} diff --git a/force-app/main/default/classes/AdyenRefundHelperTest.cls-meta.xml b/force-app/main/default/classes/AdyenRefundHelperTest.cls-meta.xml new file mode 100644 index 0000000..998805a --- /dev/null +++ b/force-app/main/default/classes/AdyenRefundHelperTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 62.0 + Active + diff --git a/manifest/package.xml b/manifest/package.xml index ac3703e..5386da5 100644 --- a/manifest/package.xml +++ b/manifest/package.xml @@ -30,6 +30,7 @@ PaymentLinkGenerateActionTest OrderSummaryCreatedEventHandler OrderSummaryCreatedEventHandlerTest + AdyenRefundHelperTest ApexClass @@ -111,5 +112,5 @@ Payment_Link__c CustomTab - 61.0 + 62.0