Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POS live endpoints #1220

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest/__mocks__/dw/system/Site.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getCurrent = jest.fn();
3 changes: 2 additions & 1 deletion jest/sfccCartridgeMocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ jest.mock(
jest.mock(
'*/cartridge/adyen/utils/adyenConfigs',
() => ({
getAdyenEnvironment: jest.fn(() => 'TEST'),
getAdyenEnvironment: jest.fn(),
getAdyenInstallmentsEnabled: jest.fn(() => true),
getCreditCardInstallments: jest.fn(() => true),
getAdyenTokenisationEnabled: jest.fn(() => true),
Expand All @@ -344,6 +344,7 @@ jest.mock(
getAdyen3DS2Enabled: jest.fn(() => false),
getAdyenLevel23DataEnabled: jest.fn(() => false),
getAdyenSalePaymentMethods: jest.fn(() => []),
getAdyenPosRegion: jest.fn(),
}),
{ virtual: true },
);
Expand Down
21 changes: 21 additions & 0 deletions metadata/site_import/meta/system-objecttype-extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,27 @@
</value-definition>
</value-definitions>
</attribute-definition>
<attribute-definition attribute-id="Adyen_Pos_Region">
<display-name xml:lang="x-default">Region</display-name>
<description xml:lang="x-default">This should be set to the region closest to where your shoppers are located. It influences the speed of the communication between your payment terminal and our back-end.</description>
<type>enum-of-string</type>
<mandatory-flag>false</mandatory-flag>
<externally-managed-flag>false</externally-managed-flag>
<value-definitions>
<value-definition default="true">
<value>EU</value>
</value-definition>
<value-definition>
<value>US</value>
</value-definition>
<value-definition>
<value>AU</value>
</value-definition>
<value-definition>
<value>APSE</value>
</value-definition>
</value-definitions>
</attribute-definition>
<attribute-definition attribute-id="Adyen_notification_password">
<display-name xml:lang="x-default">Adyen Notifications Password</display-name>
<description xml:lang="x-default">Adyen Notifications Password for basic Authentication</description>
Expand Down
4 changes: 2 additions & 2 deletions metadata/site_import/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<password/>
</service-credential>
<service-credential service-credential-id="AdyenPosPaymentLive">
<url>https://[YOUR_LIVE_PREFIX]-terminal-api-live.adyenpayments.com/sync</url>
<url>https://terminal-api-[ADYEN-REGION].adyen.com/sync</url>
<user-id></user-id>
<password/>
</service-credential>
Expand All @@ -56,7 +56,7 @@
<password/>
</service-credential>
<service-credential service-credential-id="AdyenConnectedTerminalsLive">
<url>https://[YOUR_LIVE_PREFIX]-terminal-api-live.adyenpayments.com/connectedTerminals</url>
<url>https://terminal-api-live.adyen.com/connectedTerminals</url>
<user-id></user-id>
<password/>
</service-credential>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,19 @@
</div>
</div>
</div>
<div class="form-group">
<label class="form-title mb-0" for="posRegion">Terminal API Region</label>
<small id="posRegionHelp" class="form-text mb-1">
When you are ready to go live, enter the closest regions to your shoppers. This setup ensures that the communication between your payment terminal and our back-end is optimal.
<a class="text-primary" href="https://docs.adyen.com/point-of-sale/design-your-integration/terminal-api/#live-endpoints" target="_blank">Check the list of regions</a></small>
<div class='input-fields' id="dropdown-options">
<select name="Adyen_Pos_Region" class="form-select" required>
<option class="dropdown-option" value="US" id="regionUS" ${AdyenConfigs.getAdyenPosRegion() === 'US' ? 'selected': ''}>US - United States</option>
<option class="dropdown-option" value="EU" id="regionEU" ${AdyenConfigs.getAdyenPosRegion() === 'EU' ? 'selected': ''}>EU - Europe (Default)</option>
<option class="dropdown-option" value="AU" id="regionAU" ${AdyenConfigs.getAdyenPosRegion() === 'AU' ? 'selected': ''}>AU - Australia</option>
<option class="dropdown-option" value="APSE" id="regionAPSE" ${AdyenConfigs.getAdyenPosRegion() === 'APSE' ? 'selected': ''}>APSE - East Asia</option>
</select>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ module.exports = {
IN: 'IN',
},

POS_REGIONS: {
US: 'US',
AU: 'AU',
EU: 'EU',
APSE: 'APSE',
},

SHOPPER_INTERACTIONS: {
CONT_AUTH: 'ContAuth',
ECOMMERCE: 'Ecommerce',
Expand All @@ -93,6 +100,12 @@ module.exports = {
CHECKOUT_ENVIRONMENT_LIVE_AU: 'live-au',
CHECKOUT_ENVIRONMENT_LIVE_IN: 'live-in',

POS_ENVIRONMENT_TEST: 'test',
POS_ENVIRONMENT_LIVE_EU: 'live',
POS_ENVIRONMENT_LIVE_US: 'live-us',
POS_ENVIRONMENT_LIVE_AU: 'live-au',
POS_ENVIRONMENT_LIVE_APSE: 'live-apse',

MERCHANT_APPLICATION_NAME: 'adyen-salesforce-commerce-cloud',
EXTERNAL_PLATFORM_NAME: 'SalesforceCommerceCloud',
EXTERNAL_PLATFORM_VERSION: 'SFRA',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ function executeCall(serviceType, requestObject) {
service.addHeader('Content-type', 'application/json');
service.addHeader('charset', 'UTF-8');
service.addHeader('X-API-KEY', apiKey);
if (AdyenConfigs.getAdyenEnvironment() === constants.MODE.LIVE && serviceType === constants.SERVICE.POSPAYMENT) {
const regionEndpoint = AdyenHelper.getTerminalApiEnvironment();
const serviceUrl = service.getURL().replace(`[ADYEN-REGION]`, regionEndpoint);
service.setURL(serviceUrl);
}
const callResult = service.call(JSON.stringify(requestObject.request));

if (callResult.isOk() === false) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable global-require */
const Money = require('../../../../../../../jest/__mocks__/dw/value/Money');
const { getApplicableShippingMethods } = require('../adyenHelper');
const { getApplicableShippingMethods, getTerminalApiEnvironment } = require('../adyenHelper');
const savePaymentDetails = require('../adyenHelper').savePaymentDetails;
describe('savePaymentDetails', () => {
let paymentInstrument;
Expand Down Expand Up @@ -116,3 +116,31 @@ describe('getApplicableShippingMethods', () => {
expect(shippingMethods).toBeNull();
})
})

describe('getTerminalApiEnvironment', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should return TEST endpoint for TEST environment', () => {
const adyenConfigs = require('*/cartridge/adyen/utils/adyenConfigs');
adyenConfigs.getAdyenEnvironment.mockReturnValue('TEST');
const result = getTerminalApiEnvironment();
expect(result).toBe('test');
});

it('should return LIVE US endpoint for LIVE environment', () => {
const adyenConfigs = require('*/cartridge/adyen/utils/adyenConfigs');
adyenConfigs.getAdyenEnvironment.mockReturnValue('LIVE');
adyenConfigs.getAdyenPosRegion.mockReturnValue('US');
const result = getTerminalApiEnvironment();
expect(result).toBe('live-us');
});

it('should return default LIVE endpoint for LIVE environment', () => {
const adyenConfigs = require('*/cartridge/adyen/utils/adyenConfigs');
adyenConfigs.getAdyenEnvironment.mockReturnValue('LIVE');
adyenConfigs.getAdyenPosRegion.mockReturnValue('EU');
const result = getTerminalApiEnvironment();
expect(result).toBe('live');
});
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dwsystem = require('dw/system');
const Site = require('dw/system/Site');

const adyenCurrentSite = dwsystem.Site.getCurrent();
const adyenCurrentSite = Site.getCurrent();

function getCustomPreference(field) {
let customPreference = null;
Expand Down Expand Up @@ -106,6 +106,10 @@ const adyenConfigsObj = {
return getCustomPreference('Adyen_Frontend_Region').value;
},

getAdyenPosRegion() {
return getCustomPreference('Adyen_Pos_Region').value;
},

getAdyenTokenisationEnabled() {
return getCustomPreference('AdyenTokenisationEnabled');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,32 @@ let adyenHelperObj = {
return returnValue;
},

getTerminalApiEnvironment() {
let returnValue = '';
switch (AdyenConfigs.getAdyenEnvironment()) {
case constants.MODE.TEST:
returnValue = constants.POS_ENVIRONMENT_TEST;
break;
case constants.MODE.LIVE:
const terminalRegion = AdyenConfigs.getAdyenPosRegion();
if (terminalRegion === constants.POS_REGIONS.US) {
returnValue = constants.POS_ENVIRONMENT_LIVE_US;
break;
}
if (terminalRegion === constants.POS_REGIONS.AU) {
returnValue = constants.POS_ENVIRONMENT_LIVE_AU;
break;
}
if (terminalRegion === constants.POS_REGIONS.APSE) {
returnValue = constants.POS_ENVIRONMENT_LIVE_APSE;
break;
}
returnValue = constants.POS_ENVIRONMENT_LIVE_EU;
break;
}
return returnValue;
},

// get the loading context based on the current environment (live or test)
getLoadingContext() {
return `https://checkoutshopper-${adyenHelperObj.getCheckoutEnvironment()}.adyen.com/checkoutshopper/`;
Expand Down
Loading