Skip to content

Commit 4d1ed29

Browse files
committed
Add Regions enum
1 parent 60ceb8c commit 4d1ed29

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

src/config.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
2+
// Test endpoint for Terminal API
3+
export const TERMINAL_API_ENDPOINT_TEST = "https://terminal-api-test.adyen.com";
4+
5+
// Live endpoints for Terminal API
6+
const TERMINAL_API_ENDPOINT_LIVE = "https://terminal-api-live.adyen.com";
7+
const TERMINAL_API_ENDPOINT_AU_LIVE = "https://terminal-api-au.adyen.com";
8+
const TERMINAL_API_ENDPOINT_US_LIVE = "https://terminal-api-us.adyen.com";
9+
const TERMINAL_API_ENDPOINT_APSE_LIVE = "https://terminal-api-apse.adyen.com";
10+
11+
/**
12+
* Supported Regions for Terminal API integration.
13+
*/
14+
export enum RegionEnum {
15+
EU = "EU",
16+
AU = "AU",
17+
US = "US",
18+
APSE = "APSE"
19+
}
20+
21+
// Terminal API Endpoints Map
22+
export const TERMINAL_API_ENDPOINTS_MAP: Record<RegionEnum, string> = {
23+
[RegionEnum.EU]: TERMINAL_API_ENDPOINT_LIVE,
24+
[RegionEnum.AU]: TERMINAL_API_ENDPOINT_AU_LIVE,
25+
[RegionEnum.US]: TERMINAL_API_ENDPOINT_US_LIVE,
26+
[RegionEnum.APSE]: TERMINAL_API_ENDPOINT_APSE_LIVE
27+
}
28+
29+
130
interface ConfigConstructor {
231
username?: string;
332
password?: string;
@@ -9,11 +38,14 @@ interface ConfigConstructor {
938
certificatePath?: string;
1039
terminalApiCloudEndpoint?: string;
1140
terminalApiLocalEndpoint?: string;
41+
liveEndpointUrlPrefix?: string; // must be provided for LIVE integration
42+
region?: RegionEnum; // must be provided for Terminal API integration
1243
}
1344

1445
const DEFAULT_TIMEOUT = 30000; // Default timeout value (30 sec)
1546

1647
class Config {
48+
1749
public username?: string;
1850
public password?: string;
1951
public environment?: Environment;
@@ -24,7 +56,8 @@ class Config {
2456
public certificatePath?: string;
2557
public terminalApiCloudEndpoint?: string;
2658
public terminalApiLocalEndpoint?: string;
27-
59+
public liveEndpointUrlPrefix?: string;
60+
public region?: RegionEnum;
2861

2962
public constructor(options: ConfigConstructor = {}) {
3063
if (options.username) this.username = options.username;
@@ -38,7 +71,29 @@ class Config {
3871
if (options.certificatePath) this.certificatePath = options.certificatePath;
3972
if (options.terminalApiCloudEndpoint) this.terminalApiCloudEndpoint = options.terminalApiCloudEndpoint;
4073
if (options.terminalApiLocalEndpoint) this.terminalApiLocalEndpoint = options.terminalApiLocalEndpoint;
74+
if (options.liveEndpointUrlPrefix) this.liveEndpointUrlPrefix = options.liveEndpointUrlPrefix;
75+
if (options.region) this.region = options.region;
76+
}
77+
78+
/**
79+
* Checks if the provided region is a valid supported.
80+
* @param region - The region to validate.
81+
* @returns true if the region exists in RegionEnum, false otherwise.
82+
*/
83+
public static isRegionValid(region: RegionEnum): boolean {
84+
return Object.values(RegionEnum).includes(region);
4185
}
86+
87+
/**
88+
* Returns the Terminal API endpoint for the given region.
89+
* If the region is not valid, returns the EU endpoint.
90+
* @param region - The region to get the endpoint for.
91+
* @returns The Terminal API endpoint URL.
92+
*/
93+
public static getTerminalApiEndpoint(region: RegionEnum): string {
94+
return TERMINAL_API_ENDPOINTS_MAP[region] || TERMINAL_API_ENDPOINTS_MAP[RegionEnum.EU];
95+
}
96+
4297
}
4398

4499
export default Config;

0 commit comments

Comments
 (0)