Skip to content

Commit

Permalink
feat: capturePspReference attribute for paypal auth flow
Browse files Browse the repository at this point in the history
  • Loading branch information
dcardos committed Nov 22, 2024
1 parent 8c31bd1 commit 589bc1f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
2 changes: 2 additions & 0 deletions force-app/main/default/classes/AdyenRefundHelper.cls
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ 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
if (String.isNotBlank(payment.PaymentAuthorization.Adyen_Payment_Method_Variant__c)) {
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
26 changes: 26 additions & 0 deletions force-app/main/default/classes/AdyenRefundHelperTest.cls
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
3 changes: 2 additions & 1 deletion manifest/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<members>PaymentLinkGenerateActionTest</members>
<members>OrderSummaryCreatedEventHandler</members>
<members>OrderSummaryCreatedEventHandlerTest</members>
<members>AdyenRefundHelperTest</members>
<name>ApexClass</name>
</types>
<types>
Expand Down Expand Up @@ -111,5 +112,5 @@
<members>Payment_Link__c</members>
<name>CustomTab</name>
</types>
<version>61.0</version>
<version>62.0</version>
</Package>

0 comments on commit 589bc1f

Please sign in to comment.