diff --git a/adyenocc/src/com/adyen/commerce/controllers/PaymentMethodsController.java b/adyenocc/src/com/adyen/commerce/controllers/PaymentMethodsController.java index 09fdc975..6acd1acc 100644 --- a/adyenocc/src/com/adyen/commerce/controllers/PaymentMethodsController.java +++ b/adyenocc/src/com/adyen/commerce/controllers/PaymentMethodsController.java @@ -7,6 +7,9 @@ import com.adyen.service.exception.ApiException; import com.adyen.v6.dto.CheckoutConfigDTO; import com.adyen.v6.facades.AdyenCheckoutFacade; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import de.hybris.platform.commerceservices.request.mapping.annotation.ApiVersion; import de.hybris.platform.webservicescommons.swagger.ApiBaseSiteIdUserIdAndCartIdParam; import io.swagger.v3.oas.annotations.Operation; @@ -24,6 +27,13 @@ @Tag(name = "Adyen") public class PaymentMethodsController { + protected static ObjectMapper objectMapper; + + static { + objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + } + @Autowired private AdyenCheckoutFacade adyenCheckoutFacade; @@ -32,7 +42,8 @@ public class PaymentMethodsController @Operation(operationId = "getCheckoutConfiguration", summary = "Get checkout configuration", description = "Returns configuration for Adyen dropin component") @ApiBaseSiteIdUserIdAndCartIdParam - public ResponseEntity getCheckoutConfiguration() throws ApiException { - return ResponseEntity.ok().body(adyenCheckoutFacade.getReactCheckoutConfig()); + public ResponseEntity getCheckoutConfiguration() throws ApiException, JsonProcessingException { + String response = objectMapper.writeValueAsString(adyenCheckoutFacade.getReactCheckoutConfig()); + return ResponseEntity.ok().body(response); } } diff --git a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/adyenLibrary.tag b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/adyenLibrary.tag index 7d2d3a73..0165a46a 100644 --- a/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/adyenLibrary.tag +++ b/adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/adyenLibrary.tag @@ -35,10 +35,6 @@ crossorigin="anonymous"> -<%----%> - diff --git a/adyenv6core/src/com/adyen/v6/actions/order/AdyenCheckAuthorizationAction.java b/adyenv6core/src/com/adyen/v6/actions/order/AdyenCheckAuthorizationAction.java index 91ace550..c17cc6db 100644 --- a/adyenv6core/src/com/adyen/v6/actions/order/AdyenCheckAuthorizationAction.java +++ b/adyenv6core/src/com/adyen/v6/actions/order/AdyenCheckAuthorizationAction.java @@ -23,6 +23,7 @@ import com.adyen.v6.actions.AbstractWaitableAction; import com.adyen.v6.factory.AdyenPaymentServiceFactory; import com.adyen.v6.service.AdyenCheckoutApiService; +import com.adyen.v6.util.AmountUtil; import de.hybris.platform.core.enums.OrderStatus; import de.hybris.platform.core.model.order.OrderModel; import de.hybris.platform.core.model.order.payment.PaymentInfoModel; @@ -92,7 +93,7 @@ protected String processOrderAuthorization(final OrderProcessModel process, fina return Transition.WAIT.toString(); } - BigDecimal remainingAmount = getAdyenPaymentService(order).calculateAmountWithTaxes(order); + BigDecimal remainingAmount = AmountUtil.calculateAmountWithTaxes(order); for (final PaymentTransactionModel paymentTransactionModel : order.getPaymentTransactions()) { if (!isTransactionAuthorized(paymentTransactionModel)) { //A single not authorized transaction means not authorized @@ -123,8 +124,4 @@ protected String processOrderAuthorization(final OrderProcessModel process, fina return Transition.OK.toString(); } - - public AdyenCheckoutApiService getAdyenPaymentService(final OrderModel orderModel) { - return adyenPaymentServiceFactory.createAdyenCheckoutApiService(orderModel.getStore()); - } } diff --git a/adyenv6core/src/com/adyen/v6/actions/order/AdyenCheckCaptureAction.java b/adyenv6core/src/com/adyen/v6/actions/order/AdyenCheckCaptureAction.java index 6d6905c7..fcadf88c 100644 --- a/adyenv6core/src/com/adyen/v6/actions/order/AdyenCheckCaptureAction.java +++ b/adyenv6core/src/com/adyen/v6/actions/order/AdyenCheckCaptureAction.java @@ -24,6 +24,7 @@ import com.adyen.v6.factory.AdyenPaymentServiceFactory; import com.adyen.v6.service.AdyenCheckoutApiService; import com.adyen.v6.service.AdyenTransactionService; +import com.adyen.v6.util.AmountUtil; import de.hybris.platform.core.enums.OrderStatus; import de.hybris.platform.core.model.order.OrderModel; import de.hybris.platform.orderprocessing.model.OrderProcessModel; @@ -76,7 +77,7 @@ public String execute(final OrderProcessModel process) { order.setStatus(OrderStatus.PAYMENT_NOT_CAPTURED); modelService.save(order); - BigDecimal remainingAmount = getAdyenPaymentService(order).calculateAmountWithTaxes(order); + BigDecimal remainingAmount = AmountUtil.calculateAmountWithTaxes(order); for (final PaymentTransactionModel paymentTransactionModel : order.getPaymentTransactions()) { boolean isRejected = AdyenTransactionService.getTransactionEntry( paymentTransactionModel, diff --git a/adyenv6core/src/com/adyen/v6/service/AbstractAdyenApiService.java b/adyenv6core/src/com/adyen/v6/service/AbstractAdyenApiService.java index 6e272c78..98a3d375 100644 --- a/adyenv6core/src/com/adyen/v6/service/AbstractAdyenApiService.java +++ b/adyenv6core/src/com/adyen/v6/service/AbstractAdyenApiService.java @@ -55,6 +55,7 @@ public AbstractAdyenApiService(final BaseStoreModel baseStore, final String merc } else { this.config.setEnvironment(Environment.LIVE); this.config.setTerminalApiCloudEndpoint(Client.TERMINAL_API_ENDPOINT_LIVE); + this.config.setLiveEndpointUrlPrefix(baseStore.getAdyenAPIEndpointPrefix()); } } diff --git a/adyenv6core/src/com/adyen/v6/service/AdyenCheckoutApiService.java b/adyenv6core/src/com/adyen/v6/service/AdyenCheckoutApiService.java index 377320e0..c7a4cfc3 100644 --- a/adyenv6core/src/com/adyen/v6/service/AdyenCheckoutApiService.java +++ b/adyenv6core/src/com/adyen/v6/service/AdyenCheckoutApiService.java @@ -108,9 +108,6 @@ public interface AdyenCheckoutApiService { */ TerminalAPIResponse sendSyncPosStatusRequest(CartData cartData, String serviceId) throws Exception; - - BigDecimal calculateAmountWithTaxes(final AbstractOrderModel abstractOrderModel); - CreateCheckoutSessionResponse getPaymentSessionData(final CartData cartData) throws IOException, ApiException; CreateCheckoutSessionResponse getPaymentSessionData(final Amount amount) throws IOException, ApiException; diff --git a/adyenv6core/src/com/adyen/v6/service/DefaultAdyenCheckoutApiService.java b/adyenv6core/src/com/adyen/v6/service/DefaultAdyenCheckoutApiService.java index ebec3485..79355cd7 100644 --- a/adyenv6core/src/com/adyen/v6/service/DefaultAdyenCheckoutApiService.java +++ b/adyenv6core/src/com/adyen/v6/service/DefaultAdyenCheckoutApiService.java @@ -365,15 +365,4 @@ public TerminalAPIResponse sendSyncPosStatusRequest(CartData cartData, String or LOG.debug(TerminalAPIGsonBuilder.create().toJson(terminalApiResponse)); return terminalApiResponse; } - - @Override - public BigDecimal calculateAmountWithTaxes(final AbstractOrderModel abstractOrderModel) { - final Double totalPrice = abstractOrderModel.getTotalPrice(); - final Double totalTax = Boolean.TRUE.equals(abstractOrderModel.getNet()) ? abstractOrderModel.getTotalTax() : Double.valueOf(0d); - final BigDecimal totalPriceWithoutTaxBD = BigDecimal.valueOf(totalPrice == null ? 0d : totalPrice).setScale(2, - RoundingMode.HALF_EVEN); - return BigDecimal.valueOf(totalTax == null ? 0d : totalTax) - .setScale(2, RoundingMode.HALF_EVEN).add(totalPriceWithoutTaxBD); - } - } diff --git a/adyenv6core/src/com/adyen/v6/service/DefaultAdyenTransactionService.java b/adyenv6core/src/com/adyen/v6/service/DefaultAdyenTransactionService.java index fd08f052..267b1aa7 100644 --- a/adyenv6core/src/com/adyen/v6/service/DefaultAdyenTransactionService.java +++ b/adyenv6core/src/com/adyen/v6/service/DefaultAdyenTransactionService.java @@ -23,6 +23,7 @@ import com.adyen.model.checkout.PaymentDetailsResponse; import com.adyen.v6.factory.AdyenPaymentServiceFactory; import com.adyen.v6.model.AdyenNotificationModel; +import com.adyen.v6.util.AmountUtil; import de.hybris.platform.core.model.c2l.CurrencyModel; import de.hybris.platform.core.model.order.AbstractOrderModel; import de.hybris.platform.payment.dto.TransactionStatus; @@ -204,7 +205,7 @@ protected PaymentTransactionEntryModel createAuthorizationPaymentTransactionEntr transactionEntryModel.setTime(DateTime.now().toDate()); transactionEntryModel.setTransactionStatus(TransactionStatus.ACCEPTED.name()); transactionEntryModel.setTransactionStatusDetails(TransactionStatusDetails.SUCCESFULL.name()); - transactionEntryModel.setAmount(getAdyenPaymentService().calculateAmountWithTaxes(abstractOrderModel)); + transactionEntryModel.setAmount(AmountUtil.calculateAmountWithTaxes(abstractOrderModel)); transactionEntryModel.setCurrency(abstractOrderModel.getCurrency()); return transactionEntryModel; @@ -225,7 +226,7 @@ protected PaymentTransactionModel createPaymentTransaction(final String merchant paymentTransactionModel.setOrder(abstractOrderModel); paymentTransactionModel.setCurrency(abstractOrderModel.getCurrency()); paymentTransactionModel.setInfo(abstractOrderModel.getPaymentInfo()); - paymentTransactionModel.setPlannedAmount(getAdyenPaymentService().calculateAmountWithTaxes(abstractOrderModel)); + paymentTransactionModel.setPlannedAmount(AmountUtil.calculateAmountWithTaxes(abstractOrderModel)); return paymentTransactionModel; } @@ -291,7 +292,7 @@ protected PaymentTransactionEntryModel createPaymentTransactionEntryModelFromRes transactionEntryModel.setTime(DateTime.now().toDate()); transactionEntryModel.setTransactionStatus(getTransactionStatusForResultCode(resultCode)); transactionEntryModel.setTransactionStatusDetails("ResultCode: " + resultCode.getValue()); - transactionEntryModel.setAmount(getAdyenPaymentService().calculateAmountWithTaxes(abstractOrderModel)); + transactionEntryModel.setAmount(AmountUtil.calculateAmountWithTaxes(abstractOrderModel)); transactionEntryModel.setCurrency(abstractOrderModel.getCurrency()); return transactionEntryModel; @@ -314,7 +315,7 @@ protected String getTransactionStatusForResultCode(PaymentDetailsResponse.Result } protected boolean isPartialPayment(AdyenNotificationModel notificationItemModel, AbstractOrderModel abstractOrderModel) { - BigDecimal totalOrderAmount = getAdyenPaymentService().calculateAmountWithTaxes(abstractOrderModel); + BigDecimal totalOrderAmount = AmountUtil.calculateAmountWithTaxes(abstractOrderModel); BigDecimal notificationAmount = notificationItemModel.getAmountValue(); if (notificationAmount == null) { return false; @@ -322,10 +323,6 @@ protected boolean isPartialPayment(AdyenNotificationModel notificationItemModel, return totalOrderAmount.compareTo(notificationAmount) > 0; } - public AdyenCheckoutApiService getAdyenPaymentService() { - return adyenPaymentServiceFactory.createAdyenCheckoutApiService(baseStoreService.getCurrentBaseStore()); - } - public ModelService getModelService() { return modelService; } diff --git a/adyenv6core/src/com/adyen/v6/util/AmountUtil.java b/adyenv6core/src/com/adyen/v6/util/AmountUtil.java index 8ab8cd73..7d501def 100644 --- a/adyenv6core/src/com/adyen/v6/util/AmountUtil.java +++ b/adyenv6core/src/com/adyen/v6/util/AmountUtil.java @@ -1,10 +1,12 @@ package com.adyen.v6.util; import com.adyen.model.checkout.Amount; +import de.hybris.platform.core.model.order.AbstractOrderModel; import org.apache.commons.lang3.StringUtils; import org.springframework.util.Assert; import java.math.BigDecimal; +import java.math.RoundingMode; public class AmountUtil { @@ -13,9 +15,49 @@ public static Amount createAmount(BigDecimal value, String currency) { Assert.isTrue(StringUtils.isNotBlank(currency), "Currency cannot be null or empty"); Amount amount = new Amount(); amount.setCurrency(currency); - amount.setValue(value.movePointRight(2).longValue()); + int scale = getDecimalPlaces(currency); + amount.setValue(BigDecimal.TEN.pow(scale).multiply(value.setScale(scale, RoundingMode.HALF_UP)).longValue()); return amount; } + public static int getDecimalPlaces(String currency) { + switch (currency) { + case "CVE": + case "DJF": + case "GNF": + case "IDR": + case "JPY": + case "KMF": + case "KRW": + case "PYG": + case "RWF": + case "UGX": + case "VND": + case "VUV": + case "XAF": + case "XOF": + case "XPF": + return 0; + case "BHD": + case "IQD": + case "JOD": + case "KWD": + case "LYD": + case "OMR": + case "TND": + return 3; + default: + return 2; + } + } + + public static BigDecimal calculateAmountWithTaxes(final AbstractOrderModel abstractOrderModel) { + final Double totalPrice = abstractOrderModel.getTotalPrice(); + final Double totalTax = Boolean.TRUE.equals(abstractOrderModel.getNet()) ? abstractOrderModel.getTotalTax() : Double.valueOf(0d); + final BigDecimal totalPriceWithoutTaxBD = BigDecimal.valueOf(totalPrice == null ? 0d : totalPrice).setScale(2, + RoundingMode.HALF_EVEN); + return BigDecimal.valueOf(totalTax == null ? 0d : totalTax) + .setScale(2, RoundingMode.HALF_EVEN).add(totalPriceWithoutTaxBD); + } } diff --git a/adyenv6core/testsrc/com/adyen/v6/actions/order/AdyenCheckAuthorizationActionTest.java b/adyenv6core/testsrc/com/adyen/v6/actions/order/AdyenCheckAuthorizationActionTest.java index 5686ba76..56c29c14 100644 --- a/adyenv6core/testsrc/com/adyen/v6/actions/order/AdyenCheckAuthorizationActionTest.java +++ b/adyenv6core/testsrc/com/adyen/v6/actions/order/AdyenCheckAuthorizationActionTest.java @@ -83,11 +83,9 @@ public void setUp() { adyenCheckAuthorizationAction = new AdyenCheckAuthorizationAction(adyenPaymentServiceFactoryMock, baseStoreServiceMock); adyenCheckAuthorizationAction.setModelService(modelServiceMock); - when(adyenCheckAuthorizationAction.getAdyenPaymentService(orderModelMock)).thenReturn(adyenCheckoutApiServiceMock); when(baseStoreServiceMock.getCurrentBaseStore()).thenReturn(baseStoreModelMock); when(adyenPaymentServiceFactoryMock.createAdyenCheckoutApiService(baseStoreModelMock)).thenReturn(adyenCheckoutApiServiceMock); - when(adyenCheckoutApiServiceMock.calculateAmountWithTaxes(orderModelMock)).thenReturn(new BigDecimal(10)); } @After diff --git a/adyenv6core/testsrc/com/adyen/v6/actions/order/AdyenCheckCaptureActionTest.java b/adyenv6core/testsrc/com/adyen/v6/actions/order/AdyenCheckCaptureActionTest.java index 3a8be315..4a5e666d 100644 --- a/adyenv6core/testsrc/com/adyen/v6/actions/order/AdyenCheckCaptureActionTest.java +++ b/adyenv6core/testsrc/com/adyen/v6/actions/order/AdyenCheckCaptureActionTest.java @@ -91,7 +91,7 @@ public void setUp() { when(baseStoreServiceMock.getCurrentBaseStore()).thenReturn(baseStoreModelMock); when(adyenPaymentServiceFactoryMock.createAdyenCheckoutApiService(baseStoreModelMock)).thenReturn(adyenCheckoutApiServiceMock); - when(adyenCheckoutApiServiceMock.calculateAmountWithTaxes(orderModelMock)).thenReturn(new BigDecimal(10)); + } @After diff --git a/adyenv6core/testsrc/com/adyen/v6/facades/AdyenCheckoutFacadeTest.java b/adyenv6core/testsrc/com/adyen/v6/facades/AdyenCheckoutFacadeTest.java index 52cf88fe..0382ccb6 100644 --- a/adyenv6core/testsrc/com/adyen/v6/facades/AdyenCheckoutFacadeTest.java +++ b/adyenv6core/testsrc/com/adyen/v6/facades/AdyenCheckoutFacadeTest.java @@ -261,7 +261,6 @@ public void setUp() { when(configurationServiceMock.getConfiguration()).thenReturn(configurationMock); when(baseStoreServiceMock.getCurrentBaseStore()).thenReturn(baseStoreModelMock); when(adyenPaymentServiceFactoryMock.createAdyenCheckoutApiService(baseStoreModelMock)).thenReturn(adyenCheckoutApiServiceMock); - when(adyenCheckoutApiServiceMock.calculateAmountWithTaxes(orderModel)).thenReturn(new BigDecimal(10)); } @Test diff --git a/adyenv6core/testsrc/com/adyen/v6/service/AdyenTransactionServiceTest.java b/adyenv6core/testsrc/com/adyen/v6/service/AdyenTransactionServiceTest.java index 1f0bd6a6..018288a5 100644 --- a/adyenv6core/testsrc/com/adyen/v6/service/AdyenTransactionServiceTest.java +++ b/adyenv6core/testsrc/com/adyen/v6/service/AdyenTransactionServiceTest.java @@ -90,7 +90,6 @@ public void setUp() { when(modelServiceMock.create(PaymentTransactionEntryModel.class)).thenReturn(new PaymentTransactionEntryModel()); when(baseStoreServiceMock.getCurrentBaseStore()).thenReturn(baseStoreModelMock); when(adyenPaymentServiceFactoryMock.createAdyenCheckoutApiService(baseStoreModelMock)).thenReturn(adyenCheckoutApiServiceMock); - when(adyenTransactionService.getAdyenPaymentService()).thenReturn(adyenCheckoutApiServiceMock); when(paymentTransactionModel.getEntries()).thenReturn(new ArrayList<>()); when(modelServiceMock.create(PaymentTransactionModel.class)).thenReturn(paymentTransactionModel); @@ -135,7 +134,6 @@ public void testCreateCapturedTransactionFromNotification() { @Test public void testAuthorizeOrderModel() { OrderModel orderModel = createDummyOrderModel(); - when(adyenCheckoutApiServiceMock.calculateAmountWithTaxes(orderModel)).thenReturn(new BigDecimal(10)); PaymentTransactionModel paymentTransactionModel = adyenTransactionService.authorizeOrderModel(orderModel, MERCHANT_REFERENCE, PSP_REFERENCE); diff --git a/adyenwebcommons/src/com/adyen/commerce/util/ErrorMessageUtil.java b/adyenwebcommons/src/com/adyen/commerce/util/ErrorMessageUtil.java index 14ee6fad..59f57abf 100644 --- a/adyenwebcommons/src/com/adyen/commerce/util/ErrorMessageUtil.java +++ b/adyenwebcommons/src/com/adyen/commerce/util/ErrorMessageUtil.java @@ -26,6 +26,6 @@ public static String getErrorMessageByRefusalReason(String refusalReason) { return CHECKOUT_ERROR_AUTHORIZATION_PAYMENT_REFUSED; } } - return ""; + return CHECKOUT_ERROR_AUTHORIZATION_PAYMENT_REFUSED; } }