Skip to content
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
279 changes: 273 additions & 6 deletions src/__tests__/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("Service", () => {
client.config.environment = EnvironmentEnum.LIVE;

const service = new TestService(client);
expect(() => service.testCreateBaseUrl("https://pal-live.adyen.com/pal/servlet/"))
expect(() => service.testCreateBaseUrl("https://pal-test.adyen.com/pal/servlet/"))
.toThrow("Live endpoint URL prefix must be provided for LIVE environment.");
});

Expand All @@ -54,7 +54,7 @@ describe("Service", () => {
client.config.environment = EnvironmentEnum.LIVE;

const service = new TestService(client);
expect(() => service.testCreateBaseUrl("https://pal-live.adyen.com/pal/servlet/"))
expect(() => service.testCreateBaseUrl("https://pal-test.adyen.com/pal/servlet/"))
.toThrow("Live endpoint URL prefix must be provided for LIVE environment.");
});

Expand Down Expand Up @@ -119,6 +119,22 @@ describe("Service", () => {
);
});

it("should throw error if liveEndpointUrlPrefix is empty for possdk", () => {
// create Client for TEST environment without liveEndpointUrlPrefix
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST,
liveEndpointUrlPrefix: ""
});
client = new Client(config);
// change to LIVE
client.config.environment = EnvironmentEnum.LIVE;

const service = new TestService(client);
expect(() => service.testCreateBaseUrl("https://checkout-test.adyen.com/possdk/v68"))
.toThrow("Live endpoint URL prefix must be provided for LIVE environment.");
});

it("should replace -test with -live for other URLs", () => {
const config = new Config({
apiKey: "test_key",
Expand All @@ -132,11 +148,11 @@ describe("Service", () => {
expect(service.testCreateBaseUrl(url)).toBe("https://some-live.adyen.com/api/");
});

// SessionAuthentication
it("should build TEST url for SessionAuthentication", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST,
liveEndpointUrlPrefix: "mycompany"
environment: EnvironmentEnum.TEST
});
client = new Client(config);

Expand All @@ -148,8 +164,7 @@ describe("Service", () => {
it("should build LIVE url for SessionAuthentication", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.LIVE,
liveEndpointUrlPrefix: "mycompany"
environment: EnvironmentEnum.LIVE
});
client = new Client(config);

Expand All @@ -158,4 +173,256 @@ describe("Service", () => {
expect(service.testCreateBaseUrl(url)).toBe("https://authe-live.adyen.com/authe/api/v1");
});

// LEM
it("should build TEST url for LEM", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST
});
client = new Client(config);

const service = new TestService(client);
const url = "https://kyc-test.adyen.com/lem/v4";
expect(service.testCreateBaseUrl(url)).toBe("https://kyc-test.adyen.com/lem/v4");
});

it("should build LIVE url for LEM", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.LIVE
});
client = new Client(config);

const service = new TestService(client);
const url = "https://kyc-test.adyen.com/lem/v4";
expect(service.testCreateBaseUrl(url)).toBe("https://kyc-live.adyen.com/lem/v4");
});

// BalancePlatform
it("should build TEST url for BalancePlatform", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST
});
client = new Client(config);

const service = new TestService(client);
const url = "https://balanceplatform-api-test.adyen.com/bcl/v2";
expect(service.testCreateBaseUrl(url)).toBe("https://balanceplatform-api-test.adyen.com/bcl/v2");
});

it("should build LIVE url for BalancePlatform", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.LIVE
});
client = new Client(config);

const service = new TestService(client);
const url = "https://balanceplatform-api-test.adyen.com/bcl/v2";
expect(service.testCreateBaseUrl(url)).toBe("https://balanceplatform-api-live.adyen.com/bcl/v2");
});

// Management
it("should build TEST url for Management", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST
});
client = new Client(config);

const service = new TestService(client);
const url = "https://management-test.adyen.com/v3";
expect(service.testCreateBaseUrl(url)).toBe("https://management-test.adyen.com/v3");
});

it("should build LIVE url for Management", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.LIVE
});
client = new Client(config);

const service = new TestService(client);
const url = "https://management-test.adyen.com/v3";
expect(service.testCreateBaseUrl(url)).toBe("https://management-live.adyen.com/v3");
});

// Transfers
it("should build TEST url for Transfers", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST
});
client = new Client(config);

const service = new TestService(client);
const url = "https://balanceplatform-api-test.adyen.com/btl/v4";
expect(service.testCreateBaseUrl(url)).toBe("https://balanceplatform-api-test.adyen.com/btl/v4");
});

it("should build LIVE url for Transfers", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.LIVE
});
client = new Client(config);

const service = new TestService(client);
const url = "https://balanceplatform-api-test.adyen.com/btl/v4";
expect(service.testCreateBaseUrl(url)).toBe("https://balanceplatform-api-live.adyen.com/btl/v4");
});

// BinLookup
it("should build TEST url for BinLookup", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST
});
client = new Client(config);

const service = new TestService(client);
const url = "https://pal-test.adyen.com/pal/servlet/BinLookup/v54";
expect(service.testCreateBaseUrl(url)).toBe("https://pal-test.adyen.com/pal/servlet/BinLookup/v54");
});

it("should build LIVE url for BinLookup", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.LIVE,
liveEndpointUrlPrefix: "mycompany"
});
client = new Client(config);

const service = new TestService(client);
const url = "https://pal-test.adyen.com/pal/servlet/BinLookup/v54";
expect(service.testCreateBaseUrl(url)).toBe("https://mycompany-pal-live.adyenpayments.com/pal/servlet/BinLookup/v54");
});

it("should throw error if liveEndpointUrlPrefix is empty for BinLookup", () => {
// create Client for TEST environment without liveEndpointUrlPrefix
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST,
liveEndpointUrlPrefix: ""
});
client = new Client(config);
// change to LIVE
client.config.environment = EnvironmentEnum.LIVE;

const service = new TestService(client);
expect(() => service.testCreateBaseUrl("https://pal-test.adyen.com/pal/servlet/BinLookup/v54"))
.toThrow("Live endpoint URL prefix must be provided for LIVE environment.");
});

// Payout
it("should build TEST url for Payout", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST
});
client = new Client(config);

const service = new TestService(client);
const url = "https://pal-test.adyen.com/pal/servlet/Payout/v68";
expect(service.testCreateBaseUrl(url)).toBe("https://pal-test.adyen.com/pal/servlet/Payout/v68");
});

it("should build LIVE url for Payout", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.LIVE,
liveEndpointUrlPrefix: "mycompany"
});
client = new Client(config);

const service = new TestService(client);
const url = "https://pal-test.adyen.com/pal/servlet/Payout/v68";
expect(service.testCreateBaseUrl(url)).toBe("https://mycompany-pal-live.adyenpayments.com/pal/servlet/Payout/v68");
});

it("should throw error if liveEndpointUrlPrefix is empty for Payout", () => {
// create Client for TEST environment without liveEndpointUrlPrefix
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST,
liveEndpointUrlPrefix: ""
});
client = new Client(config);
// change to LIVE
client.config.environment = EnvironmentEnum.LIVE;

const service = new TestService(client);
expect(() => service.testCreateBaseUrl("https://pal-test.adyen.com/pal/servlet/Payout/v68"))
.toThrow("Live endpoint URL prefix must be provided for LIVE environment.");
});

// Recurring
it("should build TEST url for Recurring", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST
});
client = new Client(config);

const service = new TestService(client);
const url = "https://pal-test.adyen.com/pal/servlet/Recurring/v68";
expect(service.testCreateBaseUrl(url)).toBe("https://pal-test.adyen.com/pal/servlet/Recurring/v68");
});

it("should build LIVE url for Recurring", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.LIVE,
liveEndpointUrlPrefix: "mycompany"
});
client = new Client(config);

const service = new TestService(client);
const url = "https://pal-test.adyen.com/pal/servlet/Recurring/v68";
expect(service.testCreateBaseUrl(url)).toBe("https://mycompany-pal-live.adyenpayments.com/pal/servlet/Recurring/v68");
});

it("should throw error if liveEndpointUrlPrefix is empty for Recurring", () => {
// create Client for TEST environment without liveEndpointUrlPrefix
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST,
liveEndpointUrlPrefix: ""
});
client = new Client(config);
// change to LIVE
client.config.environment = EnvironmentEnum.LIVE;

const service = new TestService(client);
expect(() => service.testCreateBaseUrl("https://pal-test.adyen.com/pal/servlet/Recurring/v68"))
.toThrow("Live endpoint URL prefix must be provided for LIVE environment.");
});

// Open Banking
it("should build TEST url for Open Banking", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.TEST
});
client = new Client(config);

const service = new TestService(client);
const url = "https://obgateway-test.adyen.com/obgateway/v1";
expect(service.testCreateBaseUrl(url)).toBe("https://obgateway-test.adyen.com/obgateway/v1");
});

it("should build LIVE url for Open Banking", () => {
const config = new Config({
apiKey: "test_key",
environment: EnvironmentEnum.LIVE
});
client = new Client(config);

const service = new TestService(client);
const url = "https://obgateway-test.adyen.com/obgateway/v1";
expect(service.testCreateBaseUrl(url)).toBe("https://obgateway-live.adyen.com/obgateway/v1");
});


});
16 changes: 10 additions & 6 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,30 @@ class Service {
throw new Error("Endpoint URL must be provided.");
}

// handle TEST urls
if (config.environment !== EnvironmentEnum.LIVE) {
return url.replace("-live", "-test");
}

if(config.environment === EnvironmentEnum.LIVE) {
if(!config?.liveEndpointUrlPrefix) {
throw new Error("Live endpoint URL prefix must be provided for LIVE environment.");
}
}

// handle LIVE urls
if (url.includes("/authe/")) {
return url.replace("https://test.adyen.com/", "https://authe-live.adyen.com/");
}

if (url.includes("pal-")) {
// LIVE pal URL must provide prefix
if(!config.liveEndpointUrlPrefix) {
throw new Error("Live endpoint URL prefix must be provided for LIVE environment.");
}
return url.replace("https://pal-test.adyen.com/pal/servlet/",
`https://${this.client.config.liveEndpointUrlPrefix}-pal-live.adyenpayments.com/pal/servlet/`);
}

if (url.includes("checkout-")) {
// LIVE checkout URL must provide prefix
if(!config.liveEndpointUrlPrefix) {
throw new Error("Live endpoint URL prefix must be provided for LIVE environment.");
}
if (url.includes("/possdk/v68")) {
return url.replace("https://checkout-test.adyen.com/",
`https://${this.client.config.liveEndpointUrlPrefix}-checkout-live.adyenpayments.com/`);
Expand Down