Skip to content

Commit 51c84af

Browse files
committed
Add and use EnvironmentEnum
1 parent e97578d commit 51c84af

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

src/client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Config from "./config";
1+
import Config, { EnvironmentEnum } from "./config";
22
import { TERMINAL_API_ENDPOINT_TEST } from "./config";
33

44
import HttpURLConnectionClient from "./httpClient/httpURLConnectionClient";
@@ -41,10 +41,10 @@ class Client {
4141
}
4242

4343
// set Terminal API endpoints
44-
if (this.config.environment === "TEST") {
44+
if (this.config.environment === EnvironmentEnum.TEST) {
4545
// one TEST endpoint for all regions
4646
this.config.terminalApiCloudEndpoint = TERMINAL_API_ENDPOINT_TEST;
47-
} else if (this.config.environment === "LIVE") {
47+
} else if (this.config.environment === EnvironmentEnum.LIVE) {
4848
// region-based LIVE endpoints
4949
if(this.config.region) {
5050
if (!Config.isRegionValid(this.config.region)) {
@@ -55,9 +55,9 @@ class Client {
5555
}
5656

5757
// legacy support for marketPayEndpoint
58-
if (this.config.environment === "TEST") {
58+
if (this.config.environment === EnvironmentEnum.TEST) {
5959
this.config.marketPayEndpoint = Client.MARKETPAY_ENDPOINT_TEST;
60-
} else if (this.config.environment === "LIVE") {
60+
} else if (this.config.environment === EnvironmentEnum.LIVE) {
6161
this.config.marketPayEndpoint = Client.MARKETPAY_ENDPOINT_LIVE;
6262
}
6363

src/config.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ const TERMINAL_API_ENDPOINT_AU_LIVE = "https://terminal-api-au.adyen.com";
88
const TERMINAL_API_ENDPOINT_US_LIVE = "https://terminal-api-us.adyen.com";
99
const TERMINAL_API_ENDPOINT_APSE_LIVE = "https://terminal-api-apse.adyen.com";
1010

11+
12+
/**
13+
* Supported environments for the Adyen APIs.
14+
*/
15+
export enum EnvironmentEnum {
16+
LIVE = "LIVE",
17+
TEST = "TEST"
18+
}
19+
1120
/**
1221
* Supported Regions for Terminal API integration.
1322
*/
@@ -30,7 +39,7 @@ export const TERMINAL_API_ENDPOINTS_MAP: Record<RegionEnum, string> = {
3039
interface ConfigConstructor {
3140
username?: string;
3241
password?: string;
33-
environment?: Environment;
42+
environment?: EnvironmentEnum;
3443
marketPayEndpoint?: string;
3544
applicationName?: string;
3645
apiKey?: string;
@@ -48,7 +57,7 @@ class Config {
4857

4958
public username?: string;
5059
public password?: string;
51-
public environment?: Environment;
60+
public environment?: EnvironmentEnum;
5261
public marketPayEndpoint?: string;
5362
public applicationName?: string;
5463
public apiKey?: string;
@@ -75,6 +84,15 @@ class Config {
7584
if (options.region) this.region = options.region;
7685
}
7786

87+
/**
88+
* Checks if the provided environment is valid.
89+
* @param environment - The environment to validate.
90+
* @returns true if the environment exists in EnvironmentEnum, false otherwise.
91+
*/
92+
public static isEnvironmentValid(environment: EnvironmentEnum): boolean {
93+
return Object.values(EnvironmentEnum).includes(environment);
94+
}
95+
7896
/**
7997
* Checks if the provided region is a valid supported.
8098
* @param region - The region to validate.

src/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
import Client from "./client";
21-
import Config from "./config";
21+
import Config, { EnvironmentEnum } from "./config";
2222

2323
/**
2424
* Base Service class for all API services.
@@ -48,11 +48,11 @@ class Service {
4848
throw new Error("Endpoint URL must be provided.");
4949
}
5050

51-
if (config.environment !== "LIVE") {
51+
if (config.environment !== EnvironmentEnum.LIVE) {
5252
return url.replace("-live", "-test");
5353
}
5454

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

0 commit comments

Comments
 (0)