Skip to content

Commit d2bbd16

Browse files
committed
Handle prefix correctly
1 parent 8bb29f3 commit d2bbd16

File tree

2 files changed

+281
-12
lines changed

2 files changed

+281
-12
lines changed

src/__tests__/service.spec.ts

Lines changed: 273 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe("Service", () => {
3838
client.config.environment = EnvironmentEnum.LIVE;
3939

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

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

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

@@ -119,6 +119,22 @@ describe("Service", () => {
119119
);
120120
});
121121

122+
it("should throw error if liveEndpointUrlPrefix is empty for possdk", () => {
123+
// create Client for TEST environment without liveEndpointUrlPrefix
124+
const config = new Config({
125+
apiKey: "test_key",
126+
environment: EnvironmentEnum.TEST,
127+
liveEndpointUrlPrefix: ""
128+
});
129+
client = new Client(config);
130+
// change to LIVE
131+
client.config.environment = EnvironmentEnum.LIVE;
132+
133+
const service = new TestService(client);
134+
expect(() => service.testCreateBaseUrl("https://checkout-test.adyen.com/possdk/v68"))
135+
.toThrow("Live endpoint URL prefix must be provided for LIVE environment.");
136+
});
137+
122138
it("should replace -test with -live for other URLs", () => {
123139
const config = new Config({
124140
apiKey: "test_key",
@@ -132,11 +148,11 @@ describe("Service", () => {
132148
expect(service.testCreateBaseUrl(url)).toBe("https://some-live.adyen.com/api/");
133149
});
134150

151+
// SessionAuthentication
135152
it("should build TEST url for SessionAuthentication", () => {
136153
const config = new Config({
137154
apiKey: "test_key",
138-
environment: EnvironmentEnum.TEST,
139-
liveEndpointUrlPrefix: "mycompany"
155+
environment: EnvironmentEnum.TEST
140156
});
141157
client = new Client(config);
142158

@@ -148,8 +164,7 @@ describe("Service", () => {
148164
it("should build LIVE url for SessionAuthentication", () => {
149165
const config = new Config({
150166
apiKey: "test_key",
151-
environment: EnvironmentEnum.LIVE,
152-
liveEndpointUrlPrefix: "mycompany"
167+
environment: EnvironmentEnum.LIVE
153168
});
154169
client = new Client(config);
155170

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

176+
// LEM
177+
it("should build TEST url for LEM", () => {
178+
const config = new Config({
179+
apiKey: "test_key",
180+
environment: EnvironmentEnum.TEST
181+
});
182+
client = new Client(config);
183+
184+
const service = new TestService(client);
185+
const url = "https://kyc-test.adyen.com/lem/v4";
186+
expect(service.testCreateBaseUrl(url)).toBe("https://kyc-test.adyen.com/lem/v4");
187+
});
188+
189+
it("should build LIVE url for LEM", () => {
190+
const config = new Config({
191+
apiKey: "test_key",
192+
environment: EnvironmentEnum.LIVE
193+
});
194+
client = new Client(config);
195+
196+
const service = new TestService(client);
197+
const url = "https://kyc-test.adyen.com/lem/v4";
198+
expect(service.testCreateBaseUrl(url)).toBe("https://kyc-live.adyen.com/lem/v4");
199+
});
200+
201+
// BalancePlatform
202+
it("should build TEST url for BalancePlatform", () => {
203+
const config = new Config({
204+
apiKey: "test_key",
205+
environment: EnvironmentEnum.TEST
206+
});
207+
client = new Client(config);
208+
209+
const service = new TestService(client);
210+
const url = "https://balanceplatform-api-test.adyen.com/bcl/v2";
211+
expect(service.testCreateBaseUrl(url)).toBe("https://balanceplatform-api-test.adyen.com/bcl/v2");
212+
});
213+
214+
it("should build LIVE url for BalancePlatform", () => {
215+
const config = new Config({
216+
apiKey: "test_key",
217+
environment: EnvironmentEnum.LIVE
218+
});
219+
client = new Client(config);
220+
221+
const service = new TestService(client);
222+
const url = "https://balanceplatform-api-test.adyen.com/bcl/v2";
223+
expect(service.testCreateBaseUrl(url)).toBe("https://balanceplatform-api-live.adyen.com/bcl/v2");
224+
});
225+
226+
// Management
227+
it("should build TEST url for Management", () => {
228+
const config = new Config({
229+
apiKey: "test_key",
230+
environment: EnvironmentEnum.TEST
231+
});
232+
client = new Client(config);
233+
234+
const service = new TestService(client);
235+
const url = "https://management-test.adyen.com/v3";
236+
expect(service.testCreateBaseUrl(url)).toBe("https://management-test.adyen.com/v3");
237+
});
238+
239+
it("should build LIVE url for Management", () => {
240+
const config = new Config({
241+
apiKey: "test_key",
242+
environment: EnvironmentEnum.LIVE
243+
});
244+
client = new Client(config);
245+
246+
const service = new TestService(client);
247+
const url = "https://management-test.adyen.com/v3";
248+
expect(service.testCreateBaseUrl(url)).toBe("https://management-live.adyen.com/v3");
249+
});
250+
251+
// Transfers
252+
it("should build TEST url for Transfers", () => {
253+
const config = new Config({
254+
apiKey: "test_key",
255+
environment: EnvironmentEnum.TEST
256+
});
257+
client = new Client(config);
258+
259+
const service = new TestService(client);
260+
const url = "https://balanceplatform-api-test.adyen.com/btl/v4";
261+
expect(service.testCreateBaseUrl(url)).toBe("https://balanceplatform-api-test.adyen.com/btl/v4");
262+
});
263+
264+
it("should build LIVE url for Transfers", () => {
265+
const config = new Config({
266+
apiKey: "test_key",
267+
environment: EnvironmentEnum.LIVE
268+
});
269+
client = new Client(config);
270+
271+
const service = new TestService(client);
272+
const url = "https://balanceplatform-api-test.adyen.com/btl/v4";
273+
expect(service.testCreateBaseUrl(url)).toBe("https://balanceplatform-api-live.adyen.com/btl/v4");
274+
});
275+
276+
// BinLookup
277+
it("should build TEST url for BinLookup", () => {
278+
const config = new Config({
279+
apiKey: "test_key",
280+
environment: EnvironmentEnum.TEST
281+
});
282+
client = new Client(config);
283+
284+
const service = new TestService(client);
285+
const url = "https://pal-test.adyen.com/pal/servlet/BinLookup/v54";
286+
expect(service.testCreateBaseUrl(url)).toBe("https://pal-test.adyen.com/pal/servlet/BinLookup/v54");
287+
});
288+
289+
it("should build LIVE url for BinLookup", () => {
290+
const config = new Config({
291+
apiKey: "test_key",
292+
environment: EnvironmentEnum.LIVE,
293+
liveEndpointUrlPrefix: "mycompany"
294+
});
295+
client = new Client(config);
296+
297+
const service = new TestService(client);
298+
const url = "https://pal-test.adyen.com/pal/servlet/BinLookup/v54";
299+
expect(service.testCreateBaseUrl(url)).toBe("https://mycompany-pal-live.adyenpayments.com/pal/servlet/BinLookup/v54");
300+
});
301+
302+
it("should throw error if liveEndpointUrlPrefix is empty for Payout", () => {
303+
// create Client for TEST environment without liveEndpointUrlPrefix
304+
const config = new Config({
305+
apiKey: "test_key",
306+
environment: EnvironmentEnum.TEST,
307+
liveEndpointUrlPrefix: ""
308+
});
309+
client = new Client(config);
310+
// change to LIVE
311+
client.config.environment = EnvironmentEnum.LIVE;
312+
313+
const service = new TestService(client);
314+
expect(() => service.testCreateBaseUrl("https://pal-test.adyen.com/pal/servlet/BinLookup/v54"))
315+
.toThrow("Live endpoint URL prefix must be provided for LIVE environment.");
316+
});
317+
318+
// Payout
319+
it("should build TEST url for Payout", () => {
320+
const config = new Config({
321+
apiKey: "test_key",
322+
environment: EnvironmentEnum.TEST
323+
});
324+
client = new Client(config);
325+
326+
const service = new TestService(client);
327+
const url = "https://pal-test.adyen.com/pal/servlet/Payout/v68";
328+
expect(service.testCreateBaseUrl(url)).toBe("https://pal-test.adyen.com/pal/servlet/Payout/v68");
329+
});
330+
331+
it("should build LIVE url for Payout", () => {
332+
const config = new Config({
333+
apiKey: "test_key",
334+
environment: EnvironmentEnum.LIVE,
335+
liveEndpointUrlPrefix: "mycompany"
336+
});
337+
client = new Client(config);
338+
339+
const service = new TestService(client);
340+
const url = "https://pal-test.adyen.com/pal/servlet/Payout/v68";
341+
expect(service.testCreateBaseUrl(url)).toBe("https://mycompany-pal-live.adyenpayments.com/pal/servlet/Payout/v68");
342+
});
343+
344+
it("should throw error if liveEndpointUrlPrefix is empty for Payout", () => {
345+
// create Client for TEST environment without liveEndpointUrlPrefix
346+
const config = new Config({
347+
apiKey: "test_key",
348+
environment: EnvironmentEnum.TEST,
349+
liveEndpointUrlPrefix: ""
350+
});
351+
client = new Client(config);
352+
// change to LIVE
353+
client.config.environment = EnvironmentEnum.LIVE;
354+
355+
const service = new TestService(client);
356+
expect(() => service.testCreateBaseUrl("https://pal-test.adyen.com/pal/servlet/Payout/v68"))
357+
.toThrow("Live endpoint URL prefix must be provided for LIVE environment.");
358+
});
359+
360+
// Recurring
361+
it("should build TEST url for Recurring", () => {
362+
const config = new Config({
363+
apiKey: "test_key",
364+
environment: EnvironmentEnum.TEST
365+
});
366+
client = new Client(config);
367+
368+
const service = new TestService(client);
369+
const url = "https://pal-test.adyen.com/pal/servlet/Recurring/v68";
370+
expect(service.testCreateBaseUrl(url)).toBe("https://pal-test.adyen.com/pal/servlet/Recurring/v68");
371+
});
372+
373+
it("should build LIVE url for Recurring", () => {
374+
const config = new Config({
375+
apiKey: "test_key",
376+
environment: EnvironmentEnum.LIVE,
377+
liveEndpointUrlPrefix: "mycompany"
378+
});
379+
client = new Client(config);
380+
381+
const service = new TestService(client);
382+
const url = "https://pal-test.adyen.com/pal/servlet/Recurring/v68";
383+
expect(service.testCreateBaseUrl(url)).toBe("https://mycompany-pal-live.adyenpayments.com/pal/servlet/Recurring/v68");
384+
});
385+
386+
it("should throw error if liveEndpointUrlPrefix is empty for Recurring", () => {
387+
// create Client for TEST environment without liveEndpointUrlPrefix
388+
const config = new Config({
389+
apiKey: "test_key",
390+
environment: EnvironmentEnum.TEST,
391+
liveEndpointUrlPrefix: ""
392+
});
393+
client = new Client(config);
394+
// change to LIVE
395+
client.config.environment = EnvironmentEnum.LIVE;
396+
397+
const service = new TestService(client);
398+
expect(() => service.testCreateBaseUrl("https://pal-test.adyen.com/pal/servlet/Recurring/v68"))
399+
.toThrow("Live endpoint URL prefix must be provided for LIVE environment.");
400+
});
401+
402+
// Open Banking
403+
it("should build TEST url for Open Banking", () => {
404+
const config = new Config({
405+
apiKey: "test_key",
406+
environment: EnvironmentEnum.TEST
407+
});
408+
client = new Client(config);
409+
410+
const service = new TestService(client);
411+
const url = "https://obgateway-test.adyen.com/obgateway/v1";
412+
expect(service.testCreateBaseUrl(url)).toBe("https://obgateway-test.adyen.com/obgateway/v1");
413+
});
414+
415+
it("should build LIVE url for Open Banking", () => {
416+
const config = new Config({
417+
apiKey: "test_key",
418+
environment: EnvironmentEnum.LIVE
419+
});
420+
client = new Client(config);
421+
422+
const service = new TestService(client);
423+
const url = "https://obgateway-test.adyen.com/obgateway/v1";
424+
expect(service.testCreateBaseUrl(url)).toBe("https://obgateway-live.adyen.com/obgateway/v1");
425+
});
426+
427+
161428
});

src/service.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,24 @@ class Service {
5252
return url.replace("-live", "-test");
5353
}
5454

55-
if(config.environment === EnvironmentEnum.LIVE) {
56-
if(!config?.liveEndpointUrlPrefix) {
57-
throw new Error("Live endpoint URL prefix must be provided for LIVE environment.");
58-
}
59-
}
60-
6155
if (url.includes("/authe/")) {
6256
return url.replace("https://test.adyen.com/", "https://authe-live.adyen.com/");
6357
}
6458

6559
if (url.includes("pal-")) {
60+
// LIVE pal URL must provide prefix
61+
if(config.environment === EnvironmentEnum.LIVE && !config.liveEndpointUrlPrefix) {
62+
throw new Error("Live endpoint URL prefix must be provided for LIVE environment.");
63+
}
6664
return url.replace("https://pal-test.adyen.com/pal/servlet/",
6765
`https://${this.client.config.liveEndpointUrlPrefix}-pal-live.adyenpayments.com/pal/servlet/`);
6866
}
6967

7068
if (url.includes("checkout-")) {
69+
// LIVE checkout URL must provide prefix
70+
if(config.environment === EnvironmentEnum.LIVE && !config.liveEndpointUrlPrefix) {
71+
throw new Error("Live endpoint URL prefix must be provided for LIVE environment.");
72+
}
7173
if (url.includes("/possdk/v68")) {
7274
return url.replace("https://checkout-test.adyen.com/",
7375
`https://${this.client.config.liveEndpointUrlPrefix}-checkout-live.adyenpayments.com/`);

0 commit comments

Comments
 (0)