Skip to content

Commit

Permalink
POS live endpoints (#1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenit2001 authored Dec 3, 2024
1 parent 09b755e commit cf5ccd5
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 6 deletions.
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>
13 changes: 13 additions & 0 deletions src/cartridges/int_adyen_SFRA/cartridge/adyen/config/constants.js
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
26 changes: 26 additions & 0 deletions src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/adyenHelper.js
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

0 comments on commit cf5ccd5

Please sign in to comment.