@yosle/tropipayjs
Advanced tools
Comparing version 0.1.23 to 0.1.24
@@ -19,2 +19,3 @@ /** | ||
request: Axios; | ||
loginRequest: Axios; | ||
static accessToken: string | null; | ||
@@ -21,0 +22,0 @@ static refreshToken: string | null; |
@@ -336,2 +336,3 @@ import { Axios } from 'axios'; | ||
request: Axios; | ||
loginRequest: Axios; | ||
static accessToken: string | null; | ||
@@ -338,0 +339,0 @@ static refreshToken: string | null; |
21
index.js
@@ -482,5 +482,7 @@ 'use strict'; | ||
request; | ||
loginRequest; | ||
static accessToken; | ||
static refreshToken; | ||
static expiresIn; | ||
static expiresIn; | ||
serverMode; | ||
@@ -525,2 +527,7 @@ hooks; | ||
baseURL: config.customTropipayUrl || tpp_env, | ||
const tpp_env = this.serverMode === "Production" | ||
? "https://www.tropipay.com" | ||
: "https://tropipay-dev.herokuapp.com"; | ||
this.request = axios__default["default"].create({ | ||
baseURL: config.customTropipayUrl || tpp_env, | ||
headers: { | ||
@@ -532,2 +539,10 @@ "Content-Type": "application/json", | ||
}); | ||
// Create a separate instance for login requests | ||
this.loginRequest = axios__default["default"].create({ | ||
baseURL: tpp_env, | ||
headers: { | ||
"Content-Type": "application/json", | ||
Accept: "application/json", | ||
}, | ||
}); | ||
// Add request interceptor for Token expired | ||
@@ -560,3 +575,3 @@ this.request.interceptors.request.use(async (config) => { | ||
if (Tropipay.refreshToken) { | ||
const { data } = await this.request.post("/api/v2/access/token", { | ||
const { data } = await this.loginRequest.post("/api/v2/access/token", { | ||
client_id: this.clientId, | ||
@@ -575,3 +590,3 @@ client_secret: this.clientSecret, | ||
// normal credetials login | ||
const { data } = await this.request.post("/api/v2/access/token", { | ||
const { data } = await this.loginRequest.post("/api/v2/access/token", { | ||
client_id: this.clientId, | ||
@@ -590,2 +605,3 @@ client_secret: this.clientSecret, | ||
Tropipay.expiresIn = data.expires_in; | ||
Tropipay.expiresIn = data.expires_in; | ||
return data; | ||
@@ -597,2 +613,3 @@ } | ||
Tropipay.expiresIn = null; | ||
Tropipay.expiresIn = null; | ||
throw handleExceptions(error); | ||
@@ -599,0 +616,0 @@ } |
{ | ||
"name": "@yosle/tropipayjs", | ||
"version": "0.1.23", | ||
"version": "0.1.24", | ||
"description": "Javascript / Typescript SDK for the Tropipay API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -30,2 +30,3 @@ /** | ||
public request: Axios; | ||
public loginRequest: Axios; | ||
public static accessToken: string | null; | ||
@@ -80,3 +81,3 @@ public static refreshToken: string | null; | ||
this.request = axios.create({ | ||
baseURL: config.customTropipayUrl || tpp_env, | ||
baseURL: config.customTropipayUrl || tpp_env, | ||
headers: { | ||
@@ -89,2 +90,10 @@ "Content-Type": "application/json", | ||
// Create a separate instance for login requests | ||
this.loginRequest = axios.create({ | ||
baseURL: tpp_env, | ||
headers: { | ||
"Content-Type": "application/json", | ||
Accept: "application/json", | ||
}, | ||
}); | ||
@@ -122,2 +131,4 @@ // Add request interceptor for Token expired | ||
} | ||
@@ -128,3 +139,3 @@ | ||
if (Tropipay.refreshToken) { | ||
const { data } = await this.request.post<LoginResponse>( | ||
const { data } = await this.loginRequest.post<LoginResponse>( | ||
"/api/v2/access/token", | ||
@@ -148,3 +159,3 @@ { | ||
// normal credetials login | ||
const { data } = await this.request.post<LoginResponse>( | ||
const { data } = await this.loginRequest.post<LoginResponse>( | ||
"/api/v2/access/token", | ||
@@ -168,2 +179,3 @@ { | ||
Tropipay.expiresIn = data.expires_in; | ||
Tropipay.expiresIn = data.expires_in; | ||
return data; | ||
@@ -174,2 +186,3 @@ } catch (error) { | ||
Tropipay.expiresIn = null; | ||
Tropipay.expiresIn = null; | ||
throw handleExceptions(error as any); | ||
@@ -176,0 +189,0 @@ } |
140801
3723