-
Notifications
You must be signed in to change notification settings - Fork 57
/
config.ts
108 lines (99 loc) · 4.64 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
* Adyen NodeJS API Library
* Copyright (c) 2020 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/
interface ConfigConstructor {
username?: string;
password?: string;
merchantAccount?: string;
environment?: Environment;
endpoint?: string;
marketPayEndpoint?: string;
applicationName?: string;
apiKey?: string;
connectionTimeoutMillis?: number;
readTimeoutMillis?: number;
certificatePath?: string;
hppEndpoint?: string;
skinCode?: string;
hmacKey?: string;
checkoutEndpoint?: string;
terminalApiCloudEndpoint?: string;
terminalApiLocalEndpoint?: string;
paymentEndpoint?: string;
storedValueEndpoint?: string;
managementEndpoint?: string;
balancePlatformEndpoint?: string;
}
class Config {
public username?: string;
public password?: string;
public merchantAccount?: string;
public environment?: Environment;
public endpoint?: string;
public marketPayEndpoint?: string;
public applicationName?: string;
public apiKey?: string;
public connectionTimeoutMillis?: number;
public readTimeoutMillis?: number;
public certificatePath?: string;
public hppEndpoint?: string;
public skinCode?: string;
public hmacKey?: string;
protected _checkoutEndpoint?: string;
public terminalApiCloudEndpoint?: string;
public terminalApiLocalEndpoint?: string;
public paymentEndpoint?: string;
public storedValueEndpoint?: string;
public managementEndpoint?: string;
public balancePlatformEndpoint?: string;
public constructor(options: ConfigConstructor = {}) {
if (options.username) this.username = options.username;
if (options.password) this.password = options.password;
if (options.merchantAccount) this.merchantAccount = options.merchantAccount;
if (options.environment) this.environment = options.environment;
if (options.endpoint) this.endpoint = options.endpoint;
if (options.marketPayEndpoint) this.marketPayEndpoint = options.marketPayEndpoint;
if (options.applicationName) this.applicationName = options.applicationName;
if (options.apiKey) this.apiKey = options.apiKey;
if (options.connectionTimeoutMillis) this.connectionTimeoutMillis = options.connectionTimeoutMillis || 30000;
if (options.readTimeoutMillis) this.readTimeoutMillis = options.readTimeoutMillis || 3000;
if (options.certificatePath) this.certificatePath = options.certificatePath;
if (options.hppEndpoint) this.hppEndpoint = options.hppEndpoint;
if (options.skinCode) this.skinCode = options.skinCode;
if (options.hmacKey) this.hmacKey = options.hmacKey;
if (options.checkoutEndpoint) this._checkoutEndpoint = options.checkoutEndpoint;
if (options.terminalApiCloudEndpoint) this.terminalApiCloudEndpoint = options.terminalApiCloudEndpoint;
if (options.terminalApiLocalEndpoint) this.terminalApiLocalEndpoint = options.terminalApiLocalEndpoint;
if (options.paymentEndpoint) this.paymentEndpoint = options.paymentEndpoint;
if (options.storedValueEndpoint) this.storedValueEndpoint = options.storedValueEndpoint;
if (options.managementEndpoint) this.managementEndpoint = options.managementEndpoint;
if (options.balancePlatformEndpoint) this.balancePlatformEndpoint = options.balancePlatformEndpoint;
}
public set checkoutEndpoint(checkoutEndpoint: string | undefined) {
this._checkoutEndpoint = checkoutEndpoint;
}
public get checkoutEndpoint(): string | undefined {
if (!this._checkoutEndpoint) {
const message = "Please provide your unique live url prefix on the setEnvironment() call on the Client or provide checkoutEndpoint in your config object.";
throw new Error(message);
} else {
return this._checkoutEndpoint;
}
}
}
export default Config;