Skip to content

Commit

Permalink
Merge pull request #280 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 10.2.1
  • Loading branch information
saquibsayyad authored Feb 24, 2022
2 parents c6bf887 + a42c1ac commit 6b74596
Show file tree
Hide file tree
Showing 18 changed files with 205 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @rkewlani @martinsrenato @Aleffio @saquibsayyad
* @rkewlani @martinsrenato @saquibsayyad
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<%-- Configure components --%>
<c:when test="${selectedPaymentMethod eq 'paypal' && (not empty paypalMerchantId || environmentMode eq 'test')}">
var amountJS = {value: "${amount.value}", currency: "${amount.currency}"};
AdyenCheckoutHybris.initiatePaypal(amountJS, "${immediateCapture}", "${paypalMerchantId}", "hidden-xs");
AdyenCheckoutHybris.initiatePaypal(amountJS, "${immediateCapture}", "${paypalMerchantId}", "visible-xs");
AdyenCheckoutHybris.initiatePaypal(amountJS, ${immediateCapture}, "${paypalMerchantId}", "hidden-xs");
AdyenCheckoutHybris.initiatePaypal(amountJS, ${immediateCapture}, "${paypalMerchantId}", "visible-xs");
</c:when>
<c:when test="${selectedPaymentMethod eq 'mbway'}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var AdyenCheckoutHybris = (function () {
this.copyOneClickCardBrandData( recurringReference, oneClickCard.props.brand )
}
else {
this.copyOneClickCardData( recurringReference, oneClickCard.data.paymentMethod.encryptedSecurityCode );
this.copyOneClickCardData( recurringReference, oneClickCard.data.paymentMethod.encryptedSecurityCode, oneClickCard.props.brand );
}
}
$( 'input[name="txvariant"]' ).remove();
Expand Down Expand Up @@ -183,14 +183,19 @@ var AdyenCheckoutHybris = (function () {
if ( this.isDebitCard() ) {
$( 'input[name="cardBrand"]' ).val( this.convertCardBrand() );
$( 'input[name="cardType"]' ).val( this.getCardType() );
} else {
$( 'input[name="cardBrand"]' ).val(this.selectedCardBrand);
}
$( 'input[name="browserInfo"]' ).val( JSON.stringify( this.card.data.browserInfo ) );
},

copyOneClickCardData: function ( recurringReference, cvc ) {
copyOneClickCardData: function ( recurringReference, cvc, brand ) {
$( "#selectedReference" ).val( recurringReference );
$( 'input[name="encryptedSecurityCode"]' ).val( cvc );
$( 'input[name="browserInfo"]' ).val( JSON.stringify( this.card.data.browserInfo ) );
if (brand) {
$( 'input[name="cardBrand"]' ).val( brand );
}

},
copyOneClickCardBrandData: function ( recurringReference, brand ) {
Expand Down Expand Up @@ -369,8 +374,10 @@ var AdyenCheckoutHybris = (function () {
currency: amount.currency,
value: amount.value
},
intent: isImmediateCapture ? "capture" : "authorize",
merchantId: (this.checkout.options.environment === 'test') ? null : paypalMerchantId, // Your PayPal Merchant ID. Required for accepting live payments.
configuration: {
intent: isImmediateCapture ? "capture" : "authorize",
merchantId: (this.checkout.options.environment === 'test') ? null : paypalMerchantId, // Your PayPal Merchant ID. Required for accepting live payments.
},
onChange: function(state, component) {
if (!state.isValid) {
self.enablePlaceOrder(label);
Expand Down Expand Up @@ -414,7 +421,7 @@ var AdyenCheckoutHybris = (function () {
countryCode: countryCode,
configuration: {
merchantName: applePayMerchantName,
merchantIdentifier: applePayMerchantIdentifier
merchantId: applePayMerchantIdentifier
},
// Button config
buttonType: "plain",
Expand All @@ -429,7 +436,7 @@ var AdyenCheckoutHybris = (function () {
self.enablePlaceOrder(label);
return false;
}
state.makePayment(state.data.paymentMethod, component, self.handleResult, label);
self.makePayment(state.data.paymentMethod, component, self.handleResult, label);
},
onClick: function(resolve, reject) {
if (self.isTermsAccepted(label)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ module.name=platform-module
name=adyenv6b2ccheckoutaddon
releasedate=20170509 1903
vendor=adyen
version=10.2.0
version.api=10.2.0
version=10.2.1
version.api=10.2.1
4 changes: 2 additions & 2 deletions adyenv6backoffice/resources/adyenv6backoffice.build.number
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ module.name=platform-module
name=adyenv6backoffice
releasedate=20170509 1903
vendor=adyen
version=10.2.0
version.api=10.2.0
version=10.2.1
version.api=10.2.1
27 changes: 23 additions & 4 deletions adyenv6core/resources/adyenv6core-items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,23 @@
<persistence type="property"/>
</attribute>
<attribute qualifier="reason" type="java.lang.String">
<persistence type="property"/>
<persistence type="property">
<columntype database="oracle">
<value>CLOB</value>
</columntype>
<columntype database="sap">
<value>NCLOB</value>
</columntype>
<columntype database="mysql">
<value>TEXT</value>
</columntype>
<columntype database="sqlserver">
<value>TEXT</value>
</columntype>
<columntype>
<value>HYBRIS.LONG_STRING</value>
</columntype>
</persistence>
</attribute>
<attribute qualifier="success" type="java.lang.Boolean">
<persistence type="property"/>
Expand All @@ -130,12 +146,15 @@
<columntype database="sap">
<value>NCLOB</value>
</columntype>
<columntype>
<value>HYBRIS.LONG_STRING</value>
</columntype>
<columntype database="mysql">
<value>TEXT</value>
</columntype>
<columntype database="sqlserver">
<value>TEXT</value>
</columntype>
<columntype>
<value>HYBRIS.LONG_STRING</value>
</columntype>
</persistence>
</attribute>
<attribute qualifier="createdAt" type="java.util.Date">
Expand Down
4 changes: 2 additions & 2 deletions adyenv6core/resources/adyenv6core.build.number
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ group.id=com.adyen.v6
module.name=platform-module
name=adyenv6core
vendor=adyen
version=10.2.0
version.api=10.2.0
version=10.2.1
version.api=10.2.1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import de.hybris.platform.payment.model.PaymentTransactionModel;
import org.apache.log4j.Logger;

import java.math.BigDecimal;

/**
* Check if order is authorized
*/
Expand All @@ -56,28 +58,7 @@ public String execute(final OrderProcessModel process) {
return Transition.OK.toString();
}

//No transactions means that is not authorized yet
if (order.getPaymentTransactions().isEmpty()) {
LOG.debug("Process: " + process.getCode() + " Order Waiting");
return Transition.WAIT.toString();
}

boolean orderAuthorized = isOrderAuthorized(order);

//Continue if all transactions are authorised
if (orderAuthorized) {
LOG.debug("Process: " + process.getCode() + " Order Authorized");
order.setStatus(OrderStatus.PAYMENT_AUTHORIZED);
modelService.save(order);

return Transition.OK.toString();
}

LOG.debug("Process: " + process.getCode() + " Order Not Authorized");
order.setStatus(OrderStatus.PAYMENT_NOT_AUTHORIZED);
modelService.save(order);

return Transition.NOK.toString();
return processOrderAuthorization(process, order);
}

private boolean isTransactionAuthorized(final PaymentTransactionModel paymentTransactionModel) {
Expand All @@ -91,14 +72,42 @@ private boolean isTransactionAuthorized(final PaymentTransactionModel paymentTra
return false;
}

private boolean isOrderAuthorized(final OrderModel order) {
//A single not authorized transaction means not authorized
private String processOrderAuthorization(final OrderProcessModel process, final OrderModel order) {
//No transactions means that is not authorized yet
if (order.getPaymentTransactions() == null || order.getPaymentTransactions().isEmpty()) {
LOG.debug("Process: " + process.getCode() + " Order Waiting");
return Transition.WAIT.toString();
}

BigDecimal remainingAmount = BigDecimal.valueOf(order.getTotalPrice());
for (final PaymentTransactionModel paymentTransactionModel : order.getPaymentTransactions()) {
if (!isTransactionAuthorized(paymentTransactionModel)) {
return false;
//A single not authorized transaction means not authorized
LOG.debug("Process: " + process.getCode() + " Order Not Authorized");
order.setStatus(OrderStatus.PAYMENT_NOT_AUTHORIZED);
modelService.save(order);
return Transition.NOK.toString();
}

remainingAmount = remainingAmount.subtract(paymentTransactionModel.getPlannedAmount());
}

return true;
BigDecimal zero = BigDecimal.ZERO;
//Setting scale to 3, to avoid comparison issues on more than 3 decimal places
zero = zero.setScale(3, BigDecimal.ROUND_FLOOR);
remainingAmount = remainingAmount.setScale(3, BigDecimal.ROUND_FLOOR);

//Wait if there is still amount to be authorized
if (remainingAmount.compareTo(zero) > 0) {
LOG.debug("Process: " + process.getCode() + " Order Waiting remaining amount to be authorized");
return Transition.WAIT.toString();
}

//Return success if all transactions and total amount are authorised
LOG.debug("Process: " + process.getCode() + " Order Authorized");
order.setStatus(OrderStatus.PAYMENT_AUTHORIZED);
modelService.save(order);

return Transition.OK.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class Adyenv6coreConstants extends GeneratedAdyenv6coreConstants {
public static final String EXTENSIONNAME = "adyenv6core";

public static final String PLUGIN_NAME = "adyen-hybris";
public static final String PLUGIN_VERSION = "10.2.0";
public static final String PLUGIN_VERSION = "10.2.1";
public static final String PAYMENT_PROVIDER = "Adyen";
public static final String PAYMENT_METHOD ="paymentMethod";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public PerformResult perform(final CronJobModel cronJob) {
for (final NotificationItemModel notificationItemModel : nonProcessedNotifications) {
notificationItemModel.setProcessedAt(new Date());

boolean isDuplicate = notificationItemRepository.notificationProcessed(notificationItemModel.getPspReference(), notificationItemModel.getEventCode(), notificationItemModel.getSuccess());
LOG.debug("Processing event " + notificationItemModel.getEventCode() + " for order with code " + notificationItemModel.getMerchantReference());

LOG.debug("Processing order with code: " + notificationItemModel.getMerchantReference());

if (isDuplicate) {
NotificationItemModel processedNotification = notificationItemRepository.notificationProcessed(notificationItemModel.getPspReference(), notificationItemModel.getEventCode(), notificationItemModel.getSuccess());
if (processedNotification != null) {
notificationItemModel.setEventDate(processedNotification.getEventDate());
LOG.debug("Skipping duplicate notification");
} else {
boolean isOldNotification = notificationItemRepository.isNewerNotificationExists(notificationItemModel.getMerchantReference(),
Expand Down
10 changes: 6 additions & 4 deletions adyenv6core/src/com/adyen/v6/factory/AdyenRequestFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import com.adyen.model.terminal.SaleToAcquirerData;
import com.adyen.model.terminal.TerminalAPIRequest;
import com.adyen.util.Util;
import com.adyen.v6.enums.AdyenCardTypeEnum;
import com.adyen.v6.enums.RecurringContractMode;
import com.adyen.v6.model.RequestInfo;
import com.google.gson.Gson;
Expand All @@ -78,7 +77,6 @@
import javax.xml.datatype.XMLGregorianCalendar;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Currency;
import java.util.GregorianCalendar;
import java.util.HashMap;
Expand Down Expand Up @@ -113,7 +111,6 @@ public class AdyenRequestFactory {
private static final String IS_3DS2_ALLOWED_PROPERTY = "is3DS2allowed";
private static final String ALLOW_3DS2_PROPERTY = "allow3DS2";
private static final String OVERWRITE_BRAND_PROPERTY = "overwriteBrand";
private static final List<String> CVC_OPTIONAL_BRANDS = Arrays.asList(AdyenCardTypeEnum.BCMC.getCode(), AdyenCardTypeEnum.MAESTRO.getCode());

public PaymentRequest3d create3DAuthorizationRequest(final String merchantAccount, final HttpServletRequest request, final String md, final String paRes) {
return createBasePaymentRequest(new PaymentRequest3d(), request, merchantAccount).set3DRequestData(md, paRes);
Expand Down Expand Up @@ -214,7 +211,7 @@ else if (adyenPaymentMethod.indexOf(PAYMENT_METHOD_ONECLICK) == 0) {
if (selectedReference != null && ! selectedReference.isEmpty()) {
paymentsRequest.addOneClickData(selectedReference, cartData.getAdyenEncryptedSecurityCode());
String cardBrand = cartData.getAdyenCardBrand();
if (cardBrand != null && CVC_OPTIONAL_BRANDS.contains(cardBrand)) {
if (cardBrand != null) {
DefaultPaymentMethodDetails paymentMethodDetails = (DefaultPaymentMethodDetails) (paymentsRequest.getPaymentMethod());
paymentMethodDetails.setType(cardBrand);
paymentsRequest.setPaymentMethod(paymentMethodDetails);
Expand Down Expand Up @@ -402,6 +399,11 @@ private void updatePaymentRequestForCC(PaymentsRequest paymentsRequest, CartData
DefaultPaymentMethodDetails paymentMethodDetails = (DefaultPaymentMethodDetails) paymentsRequest.getPaymentMethod();
paymentMethodDetails.setStoreDetails(true);
}

// For Dual branded card set card brand as payment method type
if (!StringUtils.isEmpty(cartData.getAdyenCardBrand())) {
paymentsRequest.getPaymentMethod().setType(cartData.getAdyenCardBrand());
}
}

private void updatePaymentRequestForDC(PaymentsRequest paymentsRequest, CartData cartData, RecurringContractMode recurringContractMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,35 @@ public boolean isNewerNotificationExists(String merchantReference, Date eventDat
* @param success Notification success
* @return true|false
*/
public boolean notificationProcessed(String pspReference, String eventCode, boolean success) {
public NotificationItemModel notificationProcessed(String pspReference, String eventCode, boolean success) {
final Map<String, Object> queryParams = new HashMap<>();
queryParams.put("pspReference", pspReference);
queryParams.put("eventCode", eventCode);
queryParams.put("success", success);

final FlexibleSearchQuery selectNonProcessedNotificationsQuery = new FlexibleSearchQuery(
final FlexibleSearchQuery selectProcessedNotificationsQuery = new FlexibleSearchQuery(
"SELECT {pk} FROM {" + NotificationItemModel._TYPECODE + "}"
+ " WHERE {" + NotificationItemModel.PSPREFERENCE + "} = ?pspReference"
+ " AND {" + NotificationItemModel.EVENTCODE + "} = ?eventCode"
+ " AND {" + NotificationItemModel.SUCCESS + "} = ?success"
+ " AND {" + NotificationItemModel.PROCESSEDAT + "} IS NOT NULL",
+ " AND {" + NotificationItemModel.PROCESSEDAT + "} IS NOT NULL"
+ " ORDER BY {" + NotificationItemModel.PROCESSEDAT + "} ASC",
queryParams
);

LOG.debug("Checking if notification already exists");
int count = flexibleSearchService
.search(selectNonProcessedNotificationsQuery)
.getCount();
NotificationItemModel processed = flexibleSearchService
.search(selectProcessedNotificationsQuery)
.getResult()
.stream()
.map(element -> (NotificationItemModel) element)
.findFirst()
.orElse(null);

LOG.debug(count + " items found ");
if(processed != null) {
LOG.debug(processed.getUuid() + " - processed item found");
}

return (count > 0);
return processed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
import com.adyen.model.checkout.PaymentsResponse;
import com.adyen.v6.model.NotificationItemModel;
import de.hybris.platform.core.model.order.AbstractOrderModel;
import de.hybris.platform.core.model.order.OrderModel;
import de.hybris.platform.payment.dto.TransactionStatus;
import de.hybris.platform.payment.dto.TransactionStatusDetails;
import de.hybris.platform.payment.enums.PaymentTransactionType;
import de.hybris.platform.payment.model.PaymentTransactionEntryModel;
import de.hybris.platform.payment.model.PaymentTransactionModel;

import java.math.BigDecimal;

public interface AdyenTransactionService {
/**
* Get TX entry by type and status
Expand Down Expand Up @@ -93,4 +96,9 @@ static PaymentTransactionEntryModel getTransactionEntry(PaymentTransactionModel
* Creates a PaymentTransactionModel
*/
PaymentTransactionModel createPaymentTransactionFromResultCode(AbstractOrderModel abstractOrderModel, String merchantTransactionCode, String pspReference, PaymentsResponse.ResultCodeEnum resultCodeEnum);

/**
* Stores the authorization transactions for an order
*/
PaymentTransactionModel authorizeOrderModel(AbstractOrderModel abstractOrderModel, String merchantTransactionCode, String pspReference, BigDecimal paymentAmount);
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ public PaymentTransactionModel processAuthorisationEvent(NotificationItemModel n
return null;
}

PaymentTransactionModel paymentTransactionModel = null;
PaymentTransactionModel paymentTransactionModel;
if (notificationItemModel.getSuccess()) {
paymentTransactionModel = adyenTransactionService.authorizeOrderModel(orderModel, notificationItemModel.getMerchantReference(), notificationItemModel.getPspReference());
paymentTransactionModel = adyenTransactionService.authorizeOrderModel(orderModel, notificationItemModel.getMerchantReference(), notificationItemModel.getPspReference(), notificationItemModel.getAmountValue());
} else {
paymentTransactionModel = adyenTransactionService.storeFailedAuthorizationFromNotification(notificationItemModel, orderModel);
}
Expand Down
Loading

0 comments on commit 6b74596

Please sign in to comment.