diff --git a/force-app/main/default/classes/AdyenOMSConstants.cls b/force-app/main/default/classes/AdyenOMSConstants.cls index 3bafc10..d41607b 100644 --- a/force-app/main/default/classes/AdyenOMSConstants.cls +++ b/force-app/main/default/classes/AdyenOMSConstants.cls @@ -15,7 +15,7 @@ public with sharing class AdyenOMSConstants { public static final String CARD_PAYMENT_METHOD_OBJECT = 'CardPaymentMethod'; public static final String ALTERNATIVE_PAYMENT_METHOD_OBJECT = 'AlternativePaymentMethod'; - public static final Set OPEN_INVOICE_METHODS = new Set{'klarna', 'afterpay', 'ratepay', 'facilypay', 'zip', 'affirm', 'atome', 'walley', 'clearpay'}; + public static final Set OPEN_INVOICE_METHODS = new Set{'klarna', 'afterpay', 'ratepay', 'facilypay', 'zip', 'affirm', 'atome', 'walley', 'clearpay', 'riverty'}; public static final Set VALID_NOTIFICATION_TYPES = new Set{ AdyenConstants.NOTIFICATION_REQUEST_TYPE_CAPTURE, diff --git a/force-app/main/default/classes/AdyenPaymentUtility.cls b/force-app/main/default/classes/AdyenPaymentUtility.cls index 0b50f04..0da1cfb 100644 --- a/force-app/main/default/classes/AdyenPaymentUtility.cls +++ b/force-app/main/default/classes/AdyenPaymentUtility.cls @@ -19,7 +19,7 @@ public with sharing class AdyenPaymentUtility { public static Payment retrievePayment(Id paymentId) { List payments = [ SELECT - Id, GatewayRefNumber, GatewayRefDetails, + Id, GatewayRefNumber, GatewayRefDetails, Adyen_Payment_Method_Variant__c, PaymentAuthorization.GatewayRefNumber, PaymentAuthorization.Adyen_Payment_Method_Variant__c, PaymentAuthorization.Adyen_Payment_Method__c,CurrencyIsoCode, OrderPaymentSummary.FullName, OrderPaymentSummary.OrderSummary.SalesChannel.AdyenMerchantID__c @@ -134,11 +134,26 @@ public with sharing class AdyenPaymentUtility { * @return Boolean denoting if the Authorization Id belongs to an Open Invoice payment method. */ public static Boolean checkIfOpenInvoiceFromAuthorization(PaymentAuthorization pa) { - if (pa != null && pa.Adyen_Payment_Method_Variant__c != null) { + return isOpenInvoicePaymentMethod(pa?.Adyen_Payment_Method_Variant__c); + } + + public static Boolean isOpenInvoicePayment(Payment payment) { + if (checkIfOpenInvoiceFromAuthorization(payment.PaymentAuthorization)) { + return true; + } + return checkIfOpenInvoiceFromPayment(payment); + } + + public static Boolean checkIfOpenInvoiceFromPayment(Payment payment) { + return isOpenInvoicePaymentMethod(payment?.Adyen_Payment_Method_Variant__c); + } + + private static Boolean isOpenInvoicePaymentMethod(String paymentMethodVariant) { + if (paymentMethodVariant != null) { for (String openInvoiceMethod : AdyenOMSConstants.OPEN_INVOICE_METHODS) { - if (pa.Adyen_Payment_Method_Variant__c.containsIgnoreCase(openInvoiceMethod)) { - return true; - } + if (paymentMethodVariant.containsIgnoreCase(openInvoiceMethod)) { + return true; + } } } return false; diff --git a/force-app/main/default/classes/AdyenPaymentUtilityTest.cls b/force-app/main/default/classes/AdyenPaymentUtilityTest.cls index 2bec831..0a5d8aa 100644 --- a/force-app/main/default/classes/AdyenPaymentUtilityTest.cls +++ b/force-app/main/default/classes/AdyenPaymentUtilityTest.cls @@ -193,6 +193,24 @@ private class AdyenPaymentUtilityTest { Assert.areEqual(ex.getMessage(), AdyenPaymentUtility.NO_ORDER_PAY_SUM_FOUND_BY_ID + acct.Id); } } + + @IsTest + static void checkIfOpenInvoiceWithoutPayAuthTest() { + // given + Account acct = TestDataFactory.createAccount(); + insert acct; + CardPaymentMethod paymentMethod = TestDataFactory.createCardPaymentMethod(); + insert paymentMethod; + Payment payment = TestDataFactory.createPayment(acct.Id, paymentMethod.Id, null, null, null); + payment.Adyen_Payment_Method_Variant__c = 'klarna_paynow'; + insert payment; + + // when + Boolean isOpenInvoice = AdyenPaymentUtility.isOpenInvoicePayment(payment); + + // then + Assert.isTrue(isOpenInvoice); + } private static OrderPaymentSummary createInvoiceAndRelatedRecords(Decimal price, Decimal taxValue) { Account acct = TestDataFactory.createAccount(); diff --git a/force-app/main/default/classes/AdyenRefundHelper.cls b/force-app/main/default/classes/AdyenRefundHelper.cls index 7e43e10..84f758e 100644 --- a/force-app/main/default/classes/AdyenRefundHelper.cls +++ b/force-app/main/default/classes/AdyenRefundHelper.cls @@ -37,7 +37,7 @@ public with sharing class AdyenRefundHelper { 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 (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); @@ -45,7 +45,7 @@ public with sharing class AdyenRefundHelper { } } // Line items required for partial refunds for Open Invoice methods - if (AdyenPaymentUtility.checkIfOpenInvoiceFromAuthorization(payment.PaymentAuthorization)) { + if (AdyenPaymentUtility.isOpenInvoicePayment(payment)) { modRequest.setLineItems(AdyenPaymentUtility.addCreditMemoData(payment.OrderPaymentSummary.OrderSummaryId)); }