Skip to content

Commit

Permalink
Merge pull request #700 from recurly/add-eu-api-endpoint
Browse files Browse the repository at this point in the history
Adding the eu api url for eu on rjs
  • Loading branch information
chrissrogers authored Jan 24, 2022
2 parents 5847c2d + 91054e6 commit 75b8849
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/recurly.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import SubscriptionPricing from './recurly/pricing/subscription';

const debug = require('debug')('recurly');

const DEFAULT_API_URL = 'https://api.recurly.com/js/v1';
const DEFAULT_API_URL_EU = 'https://api.eu.recurly.com/js/v1';

/**
* Default configuration values.
*
Expand Down Expand Up @@ -64,7 +67,7 @@ const DEFAULTS = {
risk: {
threeDSecure: { preflightDeviceDataCollector: true }
},
api: 'https://api.recurly.com/js/v1',
api: DEFAULT_API_URL,
fields: {
all: {
style: {}
Expand Down Expand Up @@ -229,6 +232,8 @@ export class Recurly extends Emitter {

if (options.api) {
this.config.api = options.api;
} else if (this.config.publicKey.lastIndexOf('fra-', 0) === 0 && this.config.api === DEFAULT_API_URL) {
this.config.api = DEFAULT_API_URL_EU;
}

if (options.currency) {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/display.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ function assertDiffThresholdMet (diff) {
threshold = 0.25;
} else if (environmentIs(BROWSERS.EDGE)) {
threshold = 0.05;
} else if (environmentIs(BROWSERS.FIREFOX)) {
threshold = 0.1;
}
if (threshold) assert(diff <= threshold, `${diff} is above the threshold of ${threshold}`);
else assert.strictEqual(diff, 0);
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/support/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const BROWSERS = {
IE_11: ['internet explorer', '11'],
EDGE: ['MicrosoftEdge'],
ELECTRON: ['chrome', 'electron'],
SAFARI: ['Safari']
SAFARI: ['Safari'],
FIREFOX: ['firefox']
};

const DEVICES = {
Expand Down
32 changes: 32 additions & 0 deletions test/unit/recurly.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,38 @@ describe('Recurly', function () {
});
});
});

describe('when switching form different keyspaces', function () {
const DEFAULT_API_URL = 'https://api.recurly.com/js/v1';
const DEFAULT_API_URL_EU = 'https://api.eu.recurly.com/js/v1';
const SAMPLE_API = 'https://api.test.com';
describe('when publicKey of merchant is from eu', function () {
it('returns the eu api url', function () {
const recurly = new Recurly;
recurly.configure({ publicKey: 'fra-2test2' });
assert.strictEqual(recurly.config.api, DEFAULT_API_URL_EU);
});
});
describe('when publicKey of merchant is from us', function () {
it('returns the us api url', function () {
const recurly = new Recurly;
recurly.configure({ publicKey: 'ewr-1test1' });
assert.strictEqual(recurly.config.api, DEFAULT_API_URL);
});
});
describe('when publicKey is from eu and api is passed', function () {
it('returns the default api url', function () {
const recurly = initRecurly({ publicKey: 'fra-3test3', api: SAMPLE_API });
assert.strictEqual(recurly.config.api, SAMPLE_API);
});
});
describe('when publicKey is from us and api is passed', function () {
it('returns the default api url', function () {
const recurly = initRecurly({ publicKey: 'ewr-3test3', api: SAMPLE_API });
assert.strictEqual(recurly.config.api, SAMPLE_API);
});
});
});
});

describe('destroy', function () {
Expand Down

0 comments on commit 75b8849

Please sign in to comment.