Skip to content

Commit

Permalink
Merge remote-tracking branch 'adyen-origin/develop' into feature/AD-291b
Browse files Browse the repository at this point in the history
# Conflicts:
#	adyenv6b2ccheckoutaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/adyenLibrary.tag
  • Loading branch information
kpieloch committed Oct 21, 2024
2 parents 207f10b + 1f01785 commit 7a4d801
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -32,7 +42,8 @@ public class PaymentMethodsController
@Operation(operationId = "getCheckoutConfiguration", summary = "Get checkout configuration", description =
"Returns configuration for Adyen dropin component")
@ApiBaseSiteIdUserIdAndCartIdParam
public ResponseEntity<CheckoutConfigDTO> getCheckoutConfiguration() throws ApiException {
return ResponseEntity.ok().body(adyenCheckoutFacade.getReactCheckoutConfig());
public ResponseEntity<String> getCheckoutConfiguration() throws ApiException, JsonProcessingException {
String response = objectMapper.writeValueAsString(adyenCheckoutFacade.getReactCheckoutConfig());
return ResponseEntity.ok().body(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
crossorigin="anonymous">
</script>

<%--<script type="text/javascript"
src="https://${checkoutShopperHost}/checkoutshopper/assets/js/datacollection/datacollection.js">
</script>--%>

<c:if test="${showDefaultCss eq true}">
<link rel="stylesheet" href="https://${checkoutShopperHost}/checkoutshopper/css/chckt-default-v1.css"/>
</c:if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -314,18 +315,14 @@ 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;
}
return totalOrderAmount.compareTo(notificationAmount) > 0;
}

public AdyenCheckoutApiService getAdyenPaymentService() {
return adyenPaymentServiceFactory.createAdyenCheckoutApiService(baseStoreService.getCurrentBaseStore());
}

public ModelService getModelService() {
return modelService;
}
Expand Down
44 changes: 43 additions & 1 deletion adyenv6core/src/com/adyen/v6/util/AmountUtil.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public static String getErrorMessageByRefusalReason(String refusalReason) {
return CHECKOUT_ERROR_AUTHORIZATION_PAYMENT_REFUSED;
}
}
return "";
return CHECKOUT_ERROR_AUTHORIZATION_PAYMENT_REFUSED;
}
}

0 comments on commit 7a4d801

Please sign in to comment.