Skip to content

Commit

Permalink
Merge pull request #563 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 21.2.0
  • Loading branch information
maassenbas authored Oct 12, 2021
2 parents 2e65280 + 032218e commit b4cfd7d
Show file tree
Hide file tree
Showing 245 changed files with 4,955 additions and 2,012 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
"window": "readonly",
"location": "readonly",
},
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
Expand Down
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @msilvagarcia @cyattilakiss @maassenbas @rikterbeek @zaiddreakh
* @maassenbas @rikterbeek @zaiddreakh @wboereboom
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.idea
.DS_Store
/cartridges/
node_modules
dw.json
/.vscode/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Salesforce Commerce Cloud Adyen Cartridge

Adyen provides a LINK cartridge to integrate with [Salesforce Commerce Cloud (SFCC)](https://www.adyen.com/partners/salesforce-commerce-cloud). This cartridge enables a SFCC storefront to use the Adyen payment service. This cartridge supports SFRA version 4.x.x & 5.x.x and SiteGenesis JS-Controllers version 103.1.11 and higher.
Adyen provides a LINK cartridge to integrate with [Salesforce Commerce Cloud (SFCC)](https://www.adyen.com/partners/salesforce-commerce-cloud). This cartridge enables a SFCC storefront to use the Adyen payment service. This cartridge supports SFRA version 4.x.x, 5.x.x, 6.x.x and SiteGenesis JS-Controllers version 103.1.11 and higher.

Please note that the cartridge is not compatible with SFRA version 4.3.x and 4.4.x due to a [bug](https://github.com/SalesforceCommerceCloud/storefront-reference-architecture/pull/797) on Salesforce.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

var _require = require('./commons/index'),
onFieldValid = _require.onFieldValid,
onBrand = _require.onBrand;

var store = require('../../../store');

var cardNode = document.getElementById('card');
var checkout; // Store configuration

store.checkoutConfiguration.amount = {
value: 0,
currency: 'EUR'
Expand All @@ -15,6 +18,7 @@ store.checkoutConfiguration.paymentMethodsConfiguration = {
card: {
enableStoreDetails: false,
hasHolderName: true,
holderNameRequired: true,
installments: [],
onBrand: onBrand,
onFieldValid: onFieldValid,
Expand All @@ -23,15 +27,74 @@ store.checkoutConfiguration.paymentMethodsConfiguration = {
store.componentState = state;
}
}
};
var checkout = new AdyenCheckout(store.checkoutConfiguration);
}; // Handle Payment action

function handleAction(action) {
checkout.createFromAction(action).mount('#action-container');
$('#action-modal').modal({
backdrop: 'static',
keyboard: false
});
} // confirm onAdditionalDetails event and paymentsDetails response


store.checkoutConfiguration.onAdditionalDetails = function (state) {
$.ajax({
type: 'POST',
url: 'Adyen-PaymentsDetails',
data: JSON.stringify(state.data),
contentType: 'application/json; charset=utf-8',
async: false,
success: function success(data) {
if (data.isSuccessful) {
window.location.href = window.redirectUrl;
} else if (!data.isFinal && _typeof(data.action) === 'object') {
handleAction(data.action);
} else {
$('#action-modal').modal('hide');
document.getElementById('cardError').style.display = 'block';
}
}
});
}; // card and checkout component creation


var cardNode = document.getElementById('card');
checkout = new AdyenCheckout(store.checkoutConfiguration);
var card = checkout.create('card').mount(cardNode);
$('button[value="add-new-payment"]').on('click', function () {
var formErrorsExist = false;

function submitAddCard() {
var form = $(document.getElementById('payment-form'));
$.ajax({
type: 'POST',
url: form.attr('action'),
data: form.serialize(),
async: false,
success: function success(data) {
if (data.redirectAction) {
handleAction(data.redirectAction);
} else if (data.redirectUrl) {
window.location.href = data.redirectUrl;
} else if (data.error) {
formErrorsExist = true;
}
}
});
} // Add Payment Button event handler


$('button[value="add-new-payment"]').on('click', function (event) {
if (store.isValid) {
document.querySelector('#adyenStateData').value = JSON.stringify(store.componentState.data);
return true;
}
submitAddCard();

if (formErrorsExist) {
return;
}

card.showValidation();
return false;
event.preventDefault();
} else {
card.showValidation();
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ if (window.installments) {
if (window.googleMerchantID !== 'null' && window.Configuration.environment === 'live') {
var id = 'merchantIdentifier';
store.checkoutConfiguration.paymentMethodsConfiguration.paywithgoogle.configuration[id] = window.googleMerchantID;
}

if (window.paypalMerchantID !== 'null') {
store.checkoutConfiguration.paymentMethodsConfiguration.paypal.merchantId = window.paypalMerchantID;
} // Submit the payment


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@ exports[`Render Generic Component should render 1`] = `
Object {
"amount": "mocked_amount",
"countryCode": "mocked_country",
"paymentMethodsConfiguration": Object {
"amazonpay": Object {
"addressDetails": Object {
"addressLine1": "test",
"city": "test",
"countryCode": "test",
"name": "test test",
"phoneNumber": "test",
"postalCode": "test",
"stateOrRegion": "test",
},
"configuration": undefined,
},
},
"paymentMethodsResponse": Object {
"paymentMethods": Array [
Object {
"name": "Card",
"type": "scheme",
},
Object {
"type": "amazonpay",
},
],
"storedPaymentMethods": true,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Render Payment Method should render payment method 1`] = `
exports[`Render Payment Method should render payment method with shopper information fields 1`] = `
<ul
id="paymentMethodsList"
>
Expand Down Expand Up @@ -43,7 +43,7 @@ exports[`Render Payment Method should render payment method 1`] = `
</ul>
`;

exports[`Render Payment Method should render payment method 2`] = `
exports[`Render Payment Method should render payment method with shopper information fields 2`] = `
Object {
"mocked_id": Object {
"node": Object {
Expand Down Expand Up @@ -76,7 +76,7 @@ Object {
}
`;

exports[`Render Payment Method should render stored payment method 1`] = `
exports[`Render Payment Method should render stored payment method with missing shopper information fields 1`] = `
<ul
id="paymentMethodsList"
>
Expand Down Expand Up @@ -119,7 +119,7 @@ exports[`Render Payment Method should render stored payment method 1`] = `
</ul>
`;

exports[`Render Payment Method should render stored payment method 2`] = `
exports[`Render Payment Method should render stored payment method with missing shopper information fields 2`] = `
Object {
"mocked_id": Object {
"node": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

Expand Down Expand Up @@ -54,7 +54,7 @@ describe('Render Generic Component', function () {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
document.body.innerHTML = "\n <div id=\"paymentMethodsList\"></div>\n <input type=\"radio\" name=\"brandCode\" value=\"card\" />\n <button value=\"submit-payment\">Submit</button>\n <div id=\"component_card\"></div>\n <div id=\"adyenPosTerminals\">\n <span>Child #1</span>\n </div>\n ";
document.body.innerHTML = "\n <div id=\"paymentMethodsList\"></div>\n <input type=\"radio\" name=\"brandCode\" value=\"card\" />\n <button value=\"submit-payment\">Submit</button>\n <div id=\"component_card\"></div>\n <div id=\"adyenPosTerminals\">\n <span>Child #1</span>\n </div>\n <div>\n <input type=\"text\" id=\"shippingFirstNamedefault\" value=\"test\">\n <input type=\"text\" id=\"shippingLastNamedefault\" value=\"test\">\n <input type=\"text\" id=\"shippingAddressOnedefault\" value=\"test\">\n <input type=\"text\" id=\"shippingAddressCitydefault\" value=\"test\">\n <input type=\"text\" id=\"shippingZipCodedefault\" value=\"test\">\n <input type=\"text\" id=\"shippingCountrydefault\" value=\"test\">\n <input type=\"text\" id=\"shippingPhoneNumberdefault\" value=\"test\">\n <input type=\"text\" id=\"shippingZipCodedefault\" value=\"test\"> \n </div>\n ";
window.AdyenCheckout = jest.fn(function () {
return {
create: jest.fn(),
Expand All @@ -75,12 +75,16 @@ describe('Render Generic Component', function () {
paymentMethods: [{
type: 'scheme',
name: 'Card'
}, {
type: 'amazonpay'
}],
storedPaymentMethods: true
},
ImagePath: 'example.com',
AdyenDescriptions: [{
description: 'mocked_description'
}, {
description: 'mocked_description2'
}]
};
$.ajax = jest.fn(function (_ref3) {
Expand All @@ -91,14 +95,17 @@ describe('Render Generic Component', function () {
foo: 'bar',
bar: 'baz'
};
_context2.next = 7;
store.checkoutConfiguration.paymentMethodsConfiguration = {
amazonpay: {}
};
_context2.next = 8;
return renderGenericComponent();

case 7:
case 8:
expect(store.checkoutConfiguration).toMatchSnapshot();
expect(document.querySelector('input[type=radio][name=brandCode]').value).toBeTruthy();

case 9:
case 10:
case "end":
return _context2.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Render Payment Method', function () {
})
};
});
it('should render stored payment method', function () {
it('should render stored payment method with missing shopper information fields', function () {
var paymentMethod = {
id: 'mocked_id',
brand: 'mocked_brand',
Expand All @@ -39,7 +39,8 @@ describe('Render Payment Method', function () {
expect(document.getElementById('paymentMethodsList')).toMatchSnapshot();
expect(store.componentsObj).toMatchSnapshot();
});
it('should render payment method', function () {
it('should render payment method with shopper information fields', function () {
document.body.innerHTML += "\n <input id=\"shippingFirstNamedefault\" value=\"shippingFirstNamedefaultMock\" />\n <input id=\"shippingLastNamedefault\" value=\"shippingLastNamedefaultMock\" />\n <input id=\"shippingPhoneNumberdefault\" value=\"shippingPhoneNumberdefaultMock\" />\n <input id=\"shippingAddressCitydefault\" value=\"shippingAddressCitydefaultMock\" />\n <input id=\"shippingZipCodedefault\" value=\"shippingZipCodedefaultMock\" />\n <input id=\"shippingCountrydefault\" value=\"shippingCountrydefaultMock\" />\n <input id=\"shippingStatedefault\" value=\"shippingStatedefaultMock\" />\n <input id=\"shippingAddressOnedefault\" value=\"shippingAddressOnedefaultMock\" />\n <input id=\"shippingAddressTwodefault\" value=\"shippingAddressTwodefaultMock\" />\n \n <input id=\"billingAddressCity\" value=\"billingAddressCityMock\" />\n <input id=\"billingZipCode\" value=\"billingZipCodeMock\" />\n <input id=\"billingCountry\" value=\"billingCountryMock\" />\n <input id=\"billingState\" value=\"billingStateMock\" />\n <input id=\"billingAddressOne\" value=\"billingAddressOneMock\" />\n <input id=\"billingAddressTwo\" value=\"billingAddressTwoMock\" />\n \n <span class=\"customer-summary-email\">[email protected]</span>\n ";
var paymentMethod = {
type: 'scheme',
name: 'mocked_name',
Expand All @@ -48,6 +49,52 @@ describe('Render Payment Method', function () {
renderPaymentMethod(paymentMethod, false, '/mocked_path/', 'mocked_description');
expect(document.getElementById('paymentMethodsList')).toMatchSnapshot();
expect(store.componentsObj).toMatchSnapshot();
expect(store.checkout.create.mock.calls[0][1]).toEqual({
data: {
personalDetails: {
firstName: 'shippingFirstNamedefaultMock',
lastName: 'shippingLastNamedefaultMock',
telephoneNumber: 'shippingPhoneNumberdefaultMock',
shopperEmail: '[email protected]',
billingAddress: {
city: 'billingAddressCityMock',
postalCode: 'billingZipCodeMock',
country: 'billingCountryMock',
stateOrProvince: 'billingStateMock',
street: 'billingAddressOneMock',
houseNumberOrName: 'billingAddressTwoMock'
},
deliveryAddress: {
city: 'shippingAddressCitydefaultMock',
postalCode: 'shippingZipCodedefaultMock',
country: 'shippingCountrydefaultMock',
stateOrProvince: 'shippingStatedefaultMock',
street: 'shippingAddressOnedefaultMock',
houseNumberOrName: 'shippingAddressTwodefaultMock'
}
},
firstName: 'shippingFirstNamedefaultMock',
lastName: 'shippingLastNamedefaultMock',
telephoneNumber: 'shippingPhoneNumberdefaultMock',
shopperEmail: '[email protected]',
billingAddress: {
city: 'billingAddressCityMock',
postalCode: 'billingZipCodeMock',
country: 'billingCountryMock',
stateOrProvince: 'billingStateMock',
street: 'billingAddressOneMock',
houseNumberOrName: 'billingAddressTwoMock'
},
deliveryAddress: {
city: 'shippingAddressCitydefaultMock',
postalCode: 'shippingZipCodedefaultMock',
country: 'shippingCountrydefaultMock',
stateOrProvince: 'shippingStatedefaultMock',
street: 'shippingAddressOnedefaultMock',
houseNumberOrName: 'shippingAddressTwodefaultMock'
}
}
});
});
it('should handle input onChange for paypal', function () {
document.body.innerHTML += "\n <button value=\"submit-payment\"></button>\n <div id=\"component_paypal\"></div>\n ";
Expand Down
Loading

0 comments on commit b4cfd7d

Please sign in to comment.