@yosle/tropipayjs 0.1.23 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/TropipayAPI.d.ts +1 -0
- package/index.d.ts +1 -0
- package/index.js +13 -2
- package/package.json +1 -1
- package/src/api/TropipayAPI.ts +16 -3
package/api/TropipayAPI.d.ts
CHANGED
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -479,6 +479,7 @@ class Tropipay {
|
|
|
479
479
|
clientSecret;
|
|
480
480
|
scopes;
|
|
481
481
|
request;
|
|
482
|
+
loginRequest;
|
|
482
483
|
static accessToken;
|
|
483
484
|
static refreshToken;
|
|
484
485
|
static expiresIn;
|
|
@@ -527,6 +528,14 @@ class Tropipay {
|
|
|
527
528
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
528
529
|
},
|
|
529
530
|
});
|
|
531
|
+
// Create a separate instance for login requests
|
|
532
|
+
this.loginRequest = axios__default["default"].create({
|
|
533
|
+
baseURL: config.customTropipayUrl || tpp_env,
|
|
534
|
+
headers: {
|
|
535
|
+
"Content-Type": "application/json",
|
|
536
|
+
Accept: "application/json",
|
|
537
|
+
},
|
|
538
|
+
});
|
|
530
539
|
// Add request interceptor for Token expired
|
|
531
540
|
this.request.interceptors.request.use(async (config) => {
|
|
532
541
|
const currentTimestamp = Math.floor(Date.now() / 1000); // Current time in seconds
|
|
@@ -554,7 +563,7 @@ class Tropipay {
|
|
|
554
563
|
async login() {
|
|
555
564
|
try {
|
|
556
565
|
if (Tropipay.refreshToken) {
|
|
557
|
-
const { data } = await this.
|
|
566
|
+
const { data } = await this.loginRequest.post("/api/v2/access/token", {
|
|
558
567
|
client_id: this.clientId,
|
|
559
568
|
client_secret: this.clientSecret,
|
|
560
569
|
grant_type: "refresh_token",
|
|
@@ -568,7 +577,7 @@ class Tropipay {
|
|
|
568
577
|
return data;
|
|
569
578
|
}
|
|
570
579
|
// normal credetials login
|
|
571
|
-
const { data } = await this.
|
|
580
|
+
const { data } = await this.loginRequest.post("/api/v2/access/token", {
|
|
572
581
|
client_id: this.clientId,
|
|
573
582
|
client_secret: this.clientSecret,
|
|
574
583
|
grant_type: "client_credentials",
|
|
@@ -582,12 +591,14 @@ class Tropipay {
|
|
|
582
591
|
Tropipay.accessToken = data.access_token;
|
|
583
592
|
Tropipay.refreshToken = data.refresh_token;
|
|
584
593
|
Tropipay.expiresIn = data.expires_in;
|
|
594
|
+
Tropipay.expiresIn = data.expires_in;
|
|
585
595
|
return data;
|
|
586
596
|
}
|
|
587
597
|
catch (error) {
|
|
588
598
|
Tropipay.accessToken = null;
|
|
589
599
|
Tropipay.refreshToken = null;
|
|
590
600
|
Tropipay.expiresIn = null;
|
|
601
|
+
Tropipay.expiresIn = null;
|
|
591
602
|
throw handleExceptions(error);
|
|
592
603
|
}
|
|
593
604
|
}
|
package/package.json
CHANGED
package/src/api/TropipayAPI.ts
CHANGED
|
@@ -27,6 +27,7 @@ export class Tropipay {
|
|
|
27
27
|
readonly clientSecret: string;
|
|
28
28
|
readonly scopes: String[];
|
|
29
29
|
public request: Axios;
|
|
30
|
+
public loginRequest: Axios;
|
|
30
31
|
public static accessToken: string | null;
|
|
31
32
|
public static refreshToken: string | null;
|
|
32
33
|
public static expiresIn: number | null;
|
|
@@ -76,7 +77,7 @@ export class Tropipay {
|
|
|
76
77
|
? "https://www.tropipay.com"
|
|
77
78
|
: "https://tropipay-dev.herokuapp.com";
|
|
78
79
|
this.request = axios.create({
|
|
79
|
-
baseURL: config.customTropipayUrl || tpp_env,
|
|
80
|
+
baseURL: config.customTropipayUrl || tpp_env,
|
|
80
81
|
headers: {
|
|
81
82
|
"Content-Type": "application/json",
|
|
82
83
|
Accept: "application/json",
|
|
@@ -84,6 +85,14 @@ export class Tropipay {
|
|
|
84
85
|
},
|
|
85
86
|
});
|
|
86
87
|
|
|
88
|
+
// Create a separate instance for login requests
|
|
89
|
+
this.loginRequest = axios.create({
|
|
90
|
+
baseURL: config.customTropipayUrl || tpp_env,
|
|
91
|
+
headers: {
|
|
92
|
+
"Content-Type": "application/json",
|
|
93
|
+
Accept: "application/json",
|
|
94
|
+
},
|
|
95
|
+
});
|
|
87
96
|
|
|
88
97
|
// Add request interceptor for Token expired
|
|
89
98
|
this.request.interceptors.request.use(
|
|
@@ -116,12 +125,14 @@ export class Tropipay {
|
|
|
116
125
|
this.depositAccounts = new DepositAccounts(this);
|
|
117
126
|
|
|
118
127
|
|
|
128
|
+
|
|
129
|
+
|
|
119
130
|
}
|
|
120
131
|
|
|
121
132
|
public async login() {
|
|
122
133
|
try {
|
|
123
134
|
if (Tropipay.refreshToken) {
|
|
124
|
-
const { data } = await this.
|
|
135
|
+
const { data } = await this.loginRequest.post<LoginResponse>(
|
|
125
136
|
"/api/v2/access/token",
|
|
126
137
|
{
|
|
127
138
|
client_id: this.clientId,
|
|
@@ -140,7 +151,7 @@ export class Tropipay {
|
|
|
140
151
|
}
|
|
141
152
|
|
|
142
153
|
// normal credetials login
|
|
143
|
-
const { data } = await this.
|
|
154
|
+
const { data } = await this.loginRequest.post<LoginResponse>(
|
|
144
155
|
"/api/v2/access/token",
|
|
145
156
|
{
|
|
146
157
|
client_id: this.clientId,
|
|
@@ -159,11 +170,13 @@ export class Tropipay {
|
|
|
159
170
|
Tropipay.accessToken = data.access_token;
|
|
160
171
|
Tropipay.refreshToken = data.refresh_token;
|
|
161
172
|
Tropipay.expiresIn = data.expires_in;
|
|
173
|
+
Tropipay.expiresIn = data.expires_in;
|
|
162
174
|
return data;
|
|
163
175
|
} catch (error) {
|
|
164
176
|
Tropipay.accessToken = null;
|
|
165
177
|
Tropipay.refreshToken = null;
|
|
166
178
|
Tropipay.expiresIn = null;
|
|
179
|
+
Tropipay.expiresIn = null;
|
|
167
180
|
throw handleExceptions(error as any);
|
|
168
181
|
}
|
|
169
182
|
}
|