Skip to content

Commit

Permalink
Added rounding logic and moved string literals to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamk67 committed Sep 23, 2024
1 parent fa973b9 commit b10da50
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions force-app/main/default/classes/AdyenAuthorisationHelper.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 6 additions & 0 deletions force-app/main/default/classes/AdyenOMSConstants.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
12 changes: 6 additions & 6 deletions force-app/main/default/classes/AdyenPaymentHelper.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<String, String> additionalData = new Map<String, String> {
'pblId' => paymentLinkResponse.id
AdyenOMSConstants.PBL_ID_KEY => paymentLinkResponse.id
};
postAuthRequest.additionalData = additionalData;

Expand All @@ -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;
Expand All @@ -190,7 +190,7 @@ public with sharing class AdyenPaymentHelper {
public String currencyIsoCode;

@InvocableVariable(required=true)
public Double amount;
public Decimal amount;
}

public class PBLPostAuthResponse {
Expand Down

0 comments on commit b10da50

Please sign in to comment.