@yosle/tropipayjs 0.1.23 → 0.1.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yosle/tropipayjs",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "Javascript / Typescript SDK for the Tropipay API",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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: 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.request.post<LoginResponse>(
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.request.post<LoginResponse>(
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
  }