Skip to content

Commit

Permalink
Merge pull request #111 from Adyen/develop
Browse files Browse the repository at this point in the history
Merge for Release 18.2.2
  • Loading branch information
maassenbas authored Jan 11, 2019
2 parents 25c8ce9 + c23428d commit 809b52c
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ $('button[value="add-new-payment"]').on('click', function (e) {
});

function getCardData(selectedCard) {
var cardData = {
expiryMonth: $('#expirationMonth').val(),
expiryYear: $('#expirationYear').val()
};
var cardData = {};
if (!selectedCard) {
cardData.number = $('#cardNumber').val();
cardData.holderName = $('#holderName').val();
cardData.expiryMonth = $('#expirationMonth').val();
cardData.expiryYear = $('#expirationYear').val();
cardData.cvc = $('#securityCode').val();
} else {
}
else {
cardData.cvc = $('.selected-payment #saved-payment-security-code').val();
}
return cardData;
Expand Down
17 changes: 11 additions & 6 deletions cartridges/int_adyen_SFRA/cartridge/controllers/Adyen.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ server.get('ShowConfirmation', server.middleware.https, function (req, res, next
}
// AUTHORISED: The payment authorisation was successfully completed.
if (req.querystring.authResult == 'AUTHORISED') {
Transaction.begin();
order.setConfirmationStatus(dw.order.Order.CONFIRMATION_STATUS_CONFIRMED);
order.setPaymentStatus(dw.order.Order.PAYMENT_STATUS_PAID);
order.setExportStatus(dw.order.Order.EXPORT_STATUS_READY);
Transaction.commit();
COHelpers.sendConfirmationEmail(order, req.locale.id);
var OrderModel = require('*/cartridge/models/order');
var Locale = require('dw/util/Locale');

var currentLocale = Locale.getLocale(req.locale.id);
var orderModel = new OrderModel(order, { countryCode: currentLocale.country });

//Save orderModel to custom object during session
Transaction.wrap(function () {
order.custom.Adyen_CustomerEmail = JSON.stringify(orderModel);
});

clearForms();
res.redirect(URLUtils.url('Order-Confirm', 'ID', order.orderNo, 'token', order.orderToken).toString());
return next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ server.append('SubmitPayment',
},
expirationYear: {
value: parseInt(paymentForm.creditCardFields.expirationYear.value, 10)
},
securityCode: {
value: paymentForm.creditCardFields.securityCode.value
}
};

if(paymentForm.creditCardFields.selectedCardID) {
viewData.storedPaymentUUID = paymentForm.creditCardFields.selectedCardID.value;
}

// set selected brandCode & issuerId to session variable
session.custom.brandCode = req.form.brandCode;
session.custom.adyenPaymentMethod = req.form.adyenPaymentMethod;
Expand Down
37 changes: 37 additions & 0 deletions cartridges/int_adyen_SFRA/cartridge/scripts/adyenService.ds
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var Site = require('dw/system/Site');
var Resource = require('dw/web/Resource');
var HashMap = require('dw/util/HashMap');
var Mail = require('dw/net/Mail');
var Template = require('dw/util/Template');
var Transaction = require('dw/system/Transaction');


function submit(order){
var confirmationEmail = new Mail();
var context = new HashMap();

var savedOrderModel = order.custom.Adyen_CustomerEmail;
var orderObject = { order: JSON.parse(savedOrderModel) };

confirmationEmail.addTo(order.customerEmail);
confirmationEmail.setSubject(Resource.msg('subject.order.confirmation.email', 'order', null));
confirmationEmail.setFrom(Site.current.getCustomPreferenceValue('customerServiceEmail')
|| '[email protected]');

Object.keys(orderObject).forEach(function (key) {
context.put(key, orderObject[key]);
});

var template = new Template('checkout/confirmation/confirmationEmail');
var content = template.render(context).text;
confirmationEmail.setContent(content, 'text/html', 'UTF-8');
confirmationEmail.send();

Transaction.wrap(function () {
order.custom.Adyen_CustomerEmail = null;
});
}

module.exports = {
'submit': submit
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ function Handle(basket, paymentInformation) {
PaymentInstrument.METHOD_CREDIT_CARD, currentBasket.totalGrossPrice
);

paymentInstrument.setCreditCardNumber(paymentInformation.cardNumber.value);
paymentInstrument.setCreditCardExpirationMonth(paymentInformation.expirationMonth.value);
paymentInstrument.setCreditCardExpirationYear(paymentInformation.expirationYear.value);
paymentInstrument.setCreditCardType(cardType);

if (!empty(tokenID)) {
paymentInstrument.setCreditCardToken(tokenID);
}
else {
paymentInstrument.setCreditCardNumber(paymentInformation.cardNumber.value);
paymentInstrument.setCreditCardExpirationMonth(paymentInformation.expirationMonth.value);
paymentInstrument.setCreditCardExpirationYear(paymentInformation.expirationYear.value);
paymentInstrument.setCreditCardType(cardType);
}

});
return {fieldErrors: cardErrors, serverErrors: serverErrors, error: false};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<body>
<div>
<p>${Resource.msg('msg.placed.order.thank.you', 'confirmation', null)}</p>
</div>
<p>
<strong>${Resource.msg('label.order.number', 'confirmation', null)}</strong>
<br/>
<span>${pdict.order.orderNumber}</span>
</p>
<p>
<strong>${Resource.msg('label.order.date', 'confirmation', null)}</strong>
<br/>
<span><isprint value="${pdict.order.creationDate}" style="DATE_LONG"/></span>
</p>

<!--- Shipping Address --->
<isloop items="${pdict.order.shipping}" var="shippingModel" status="shippingLoop">
<isinclude template="checkout/confirmation/shippingTitle"/>
<isset name="address" value="${shippingModel.shippingAddress}" scope="page"/>
<isinclude template="checkout/addressSummary" />
<br/>
<p>
<strong>${Resource.msg('label.order.shipping.method', 'confirmation', null)}</strong>
<br/>
${shippingModel.selectedShippingMethod.displayName}
<isif condition="${shippingModel.selectedShippingMethod.estimatedArrivalTime}">
(${shippingModel.selectedShippingMethod.estimatedArrivalTime})
</isif>
</p>

<isif condition="${shippingModel.isGift}">
<p>
<strong>
${Resource.msg('heading.gift.message', 'checkout', null)}
</strong>
${shippingModel.giftMessage}
</p>
</isif>

<isif condition="${pdict.order.shipping.length > 1}">
<strong>${Resource.msg('label.order.products', 'confirmation', null)}:</strong> <br/>
<isloop items="${shippingModel.productLineItems.items}" var="lineItem" status="loopSate">
<p>
${Resource.msg('label.order.product.name', 'confirmation', null)}: ${lineItem.productName}
<br/>

<isif condition="${lineItem.productType === 'bundle'}">
<isloop items="${lineItem.bundledProductLineItems}" var="bundledLineItem">
${Resource.msg('label.order.bundled.item.name', 'confirmation', null)}: ${bundledLineItem.productName}
<br/>
<isloop items="${bundledLineItem.variationAttributes}" var="attribute">
${attribute.displayName}: ${attribute.displayValue}
<br/>
</isloop>
</isloop>
<iselse/>
<isloop items="${lineItem.variationAttributes}" var="attribute">
${attribute.displayName}: ${attribute.displayValue}
<br/>
</isloop>
</isif>

<!--- item price --->
${Resource.msg('label.each.item.price','cart',null)} -
${lineItem.price.formatted || lineItem.price.sales.formatted}
<br/>
<!--- quantity --->
${Resource.msg('field.selectquantity','cart',null)}
- <isprint value="${lineItem.quantity}" formatter="##" />
<br/>

<!--- line item total price --->
${Resource.msg('label.total.price','cart',null)}
- ${lineItem.priceTotal.price}
<br/>
</p>
</isloop>
</isif>
</isloop>
<p>${pdict.order.totals.totalShippingCost}</p>
<!--- Billing Address --->
<strong>${Resource.msg('label.order.billing.address', 'confirmation', null)}</strong>
<br/>
<isset name="address" value="${pdict.order.billing.billingAddress.address}" scope="page"/>
<isinclude template="checkout/addressSummary" />

<br/>

<!--- Payment information --->
<div>
<strong>${Resource.msg('label.order.payment.info', 'confirmation', null)}</strong>
<br/>
<div>
<isloop items="${pdict.order.billing.payment.selectedPaymentInstruments}" var="payment">
<isif condition="${payment.paymentMethod === 'CREDIT_CARD'}">
<div>
<span>${Resource.msg('msg.payment.type.credit', 'confirmation', null)}
${payment.type}</span>
</div>
<div>
${payment.maskedCreditCardNumber}
</div>
<div>
<span>${Resource.msg('msg.card.type.ending', 'confirmation', null)} ${payment.expirationMonth}/${payment.expirationYear}</span>
</div>
</isif>
<isif condition="${payment.paymentMethod === 'Adyen'}">
<div>${payment.selectedAdyenPM}</div>
<isif condition="${payment.selectedIssuerName != null}">
<div>${payment.selectedIssuerName}</div>
</isif>
</isif>
</isloop>
</div>
</div>

<p>
${Resource.msgf('label.number.items.in.cart','cart', null, pdict.order.items.totalQuantity)}
<br/>
${pdict.order.totals.subTotal}
</p>

<br/>
<isif condition="${pdict.order.shipping.length === 1}">
<strong>${Resource.msg('label.order.products', 'confirmation', null)}:</strong> <br/>
<isloop items="${pdict.order.items.items}" var="lineItem" status="loopSate">
<p>
${Resource.msg('label.order.product.name', 'confirmation', null)}: ${lineItem.productName}
<br/>

<isif condition="${lineItem.productType === 'bundle'}">
<isloop items="${lineItem.bundledProductLineItems}" var="bundledLineItem">
${Resource.msg('label.order.bundled.item.name', 'confirmation', null)}: ${bundledLineItem.productName}
<br/>
<isloop items="${bundledLineItem.variationAttributes}" var="attribute">
${attribute.displayName}: ${attribute.displayValue}
<br/>
</isloop>
</isloop>
<iselse/>
<isloop items="${lineItem.variationAttributes}" var="attribute">
${attribute.displayName}: ${attribute.displayValue}
<br/>
</isloop>
</isif>

<isif condition="${lineItem.bonusProductLineItemUUID === 'bonus'}">
<isloop items="${lineItem.bonusProducts}" var="bonusProduct" status="loopstate">
<isif condition="${loopstate.first}">
<br/>
${Resource.msg('text.lineitem.bonus.msg','cart',null)}
</isif>
${bonusProduct.productName}
<isloop items="${bonusProduct.variationAttributes}" var="attribute">
${attribute.displayName}: ${attribute.displayValue}
<br/>
</isloop>

<!--- item price --->
${Resource.msg('label.each.item.price','cart',null)} -
${bonusProduct.priceTotal.price}
<br/>

<!--- quantity --->
${Resource.msg('field.selectquantity','cart',null)}
- <isprint value="${bonusProduct.quantity}" formatter="##" />
<br/>
<isif condition="${loopstate.last}">
<br/>
</isif>
</isloop>
</isif>

<!--- item price --->
${Resource.msg('label.each.item.price','cart',null)} -
${lineItem.price.formatted || lineItem.price.sales.formatted}
<br/>
<!--- quantity --->
${Resource.msg('field.selectquantity','cart',null)}
- <isprint value="${lineItem.quantity}" formatter="##" />
<br/>

<!--- line item total price --->
${Resource.msg('label.total.price','cart',null)}
- ${lineItem.priceTotal.price}
<br/>
</p>
</isloop>
</isif>
<isinclude template="checkout/confirmation/confirmationOrderTotal" />
</body>
10 changes: 10 additions & 0 deletions cartridges/int_adyen_controllers/cartridge/scripts/adyenService.ds
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var app = require('app_storefront_controllers/cartridge/scripts/app');
var OrderModel = app.getModel('Order');

function submit(order){
OrderModel.submit(order);
}

module.exports = {
'submit': submit
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function verify (args) {
adyenRequest.put("openinvoicedata.line" + line + '.description', description );
adyenRequest.put("openinvoicedata.line" + line + '.itemAmount', itemAmount.toFixed());
adyenRequest.put("openinvoicedata.line" + line + '.itemVatAmount', vatAmount.toFixed());
adyenRequest.put("openinvoicedata.line" + line + '.itemVatPercentage', (new Number(vatPercentage) * 100).toFixed() );
adyenRequest.put("openinvoicedata.line" + line + '.itemVatPercentage', (new Number(vatPercentage) * 10000).toFixed() );
adyenRequest.put("openinvoicedata.line" + line + '.numberOfItems', quantity );
adyenRequest.put("openinvoicedata.line" + line + '.vatCategory', 'None' );
adyenRequest.put("openinvoicedata.line" + line + '.itemId', id);
Expand Down Expand Up @@ -358,7 +358,7 @@ function getCurrency(lineItem) {

function getItemAmount(lineItem) {
if(lineItem instanceof dw.order.ProductLineItem || lineItem instanceof dw.order.ShippingLineItem) {
return lineItem.adjustedPrice;
return lineItem.adjustedNetPrice;
}
else if (lineItem instanceof dw.order.PriceAdjustment) {
return lineItem.basePrice;
Expand Down
Loading

0 comments on commit 809b52c

Please sign in to comment.