From b10da50536a5c00d9162c3ecfd40c65f93a7dc70 Mon Sep 17 00:00:00 2001 From: Shubham Kumar Date: Mon, 23 Sep 2024 14:14:22 +0200 Subject: [PATCH] Added rounding logic and moved string literals to constants --- .../default/classes/AdyenAuthorisationHelper.cls | 6 +++--- force-app/main/default/classes/AdyenOMSConstants.cls | 6 ++++++ .../main/default/classes/AdyenPaymentHelper.cls | 12 ++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/force-app/main/default/classes/AdyenAuthorisationHelper.cls b/force-app/main/default/classes/AdyenAuthorisationHelper.cls index a0efd06..8304c18 100644 --- a/force-app/main/default/classes/AdyenAuthorisationHelper.cls +++ b/force-app/main/default/classes/AdyenAuthorisationHelper.cls @@ -163,13 +163,13 @@ public with sharing class AdyenAuthorisationHelper { public static CommercePayments.GatewayResponse createPostAuthResponse(CommercePayments.PostAuthorizationRequest postAuthRequest) { CommercePayments.PostAuthorizationResponse postAuthorizationResponse = new CommercePayments.PostAuthorizationResponse(); - String pblId = postAuthRequest.additionalData?.get('pblId'); + String pblId = postAuthRequest.additionalData?.get(AdyenOMSConstants.PBL_ID_KEY); if (postAuthRequest.amount != null) { postAuthorizationResponse.setAmount(postAuthRequest.amount); } - postAuthorizationResponse.setGatewayResultCode('success'); - postAuthorizationResponse.setGatewayResultCodeDescription('Transaction Normal'); + postAuthorizationResponse.setGatewayResultCode(AdyenOMSConstants.GATEWAY_RESULT_SUCCESS); + postAuthorizationResponse.setGatewayResultCodeDescription(AdyenOMSConstants.GATEWAY_RESULT_SUCCESS_DESCRIPTION); postAuthorizationResponse.setGatewayReferenceNumber(pblId); postAuthorizationResponse.setSalesforceResultCodeInfo(AdyenConstants.SUCCESS_SALESFORCE_RESULT_CODE_INFO); postAuthorizationResponse.setGatewayDate(System.now()); diff --git a/force-app/main/default/classes/AdyenOMSConstants.cls b/force-app/main/default/classes/AdyenOMSConstants.cls index fbfd5c6..89bdb6b 100644 --- a/force-app/main/default/classes/AdyenOMSConstants.cls +++ b/force-app/main/default/classes/AdyenOMSConstants.cls @@ -23,4 +23,10 @@ public with sharing class AdyenOMSConstants { AdyenConstants.NOTIFICATION_REQUEST_TYPE_REFUND_FAILED, AdyenConstants.NOTIFICATION_REQUEST_TYPE_CANCEL }; + + public static final String PBL_GATEWAY_TOKEN_DETAILS = 'PBL Id'; + public static final String PBL_PAYMENT_METHOD_NAME = 'pbl'; + public static final String PBL_ID_KEY = 'pblId'; + public static final String GATEWAY_RESULT_SUCCESS = 'success'; + public static final String GATEWAY_RESULT_SUCCESS_DESCRIPTION = 'Transaction Normal'; } \ No newline at end of file diff --git a/force-app/main/default/classes/AdyenPaymentHelper.cls b/force-app/main/default/classes/AdyenPaymentHelper.cls index aea33f9..3c71085 100644 --- a/force-app/main/default/classes/AdyenPaymentHelper.cls +++ b/force-app/main/default/classes/AdyenPaymentHelper.cls @@ -129,7 +129,7 @@ public with sharing class AdyenPaymentHelper { Adyen_Adapter__mdt adyenAdapter = AdyenPaymentUtility.retrieveAdapterByDeveloperName(AdyenConstants.DEFAULT_ADAPTER_NAME); Amount amount = new Amount(); - amount.value = (postAuthRequestInput.amount * AdyenPaymentUtility.getAmountMultiplier(postAuthRequestInput.currencyIsoCode)).intValue(); + amount.value = (postAuthRequestInput.amount * AdyenPaymentUtility.getAmountMultiplier(postAuthRequestInput.currencyIsoCode)).round(System.RoundingMode.HALF_UP); amount.currency_x = postAuthRequestInput.currencyIsoCode; PaymentLinkRequest paymentLinkRequest = AdyenPBLHelper.buildPaymentLinkRequest(adyenAdapter, amount, postAuthRequestInput.accountId); @@ -145,17 +145,17 @@ public with sharing class AdyenPaymentHelper { ConnectApi.AlternativePaymentMethod apmRequest = new ConnectApi.AlternativePaymentMethod(); apmRequest.gatewayToken = paymentLinkResponse.id; - apmRequest.gatewayTokenDetails = 'PBL Id'; + apmRequest.gatewayTokenDetails = AdyenOMSConstants.PBL_GATEWAY_TOKEN_DETAILS; postAuthRequest.paymentMethod.alternativePaymentMethod = apmRequest; postAuthRequest.paymentMethod.alternativePaymentMethod.accountId = postAuthRequestInput.accountId; - postAuthRequest.paymentMethod.alternativePaymentMethod.name = 'pbl'; + postAuthRequest.paymentMethod.alternativePaymentMethod.name = AdyenOMSConstants.PBL_PAYMENT_METHOD_NAME; postAuthRequest.paymentGroup = new ConnectApi.PaymentGroupRequest(); postAuthRequest.paymentGroup.createPaymentGroup = true; postAuthRequest.paymentGroup.currencyIsoCode = postAuthRequestInput.currencyIsoCode; Map additionalData = new Map { - 'pblId' => paymentLinkResponse.id + AdyenOMSConstants.PBL_ID_KEY => paymentLinkResponse.id }; postAuthRequest.additionalData = additionalData; @@ -173,7 +173,7 @@ public with sharing class AdyenPaymentHelper { private static ConnectApi.PostAuthorizationResponse mockPostAuthResponse() { ConnectApi.PostAuthorizationResponse postAuthorizationResponse = new ConnectApi.PostAuthorizationResponse(); postAuthorizationResponse.gatewayResponse = new ConnectApi.PostAuthGatewayResponse(); - postAuthorizationResponse.gatewayResponse.gatewayResultCode = 'success'; + postAuthorizationResponse.gatewayResponse.gatewayResultCode = AdyenOMSConstants.GATEWAY_RESULT_SUCCESS; postAuthorizationResponse.paymentGroup = new ConnectApi.PaymentGroupResponse(); postAuthorizationResponse.paymentMethod = new ConnectApi.PaymentMethodResponse(); return postAuthorizationResponse; @@ -190,7 +190,7 @@ public with sharing class AdyenPaymentHelper { public String currencyIsoCode; @InvocableVariable(required=true) - public Double amount; + public Decimal amount; } public class PBLPostAuthResponse {