@yosle/tropipayjs 0.1.9 → 0.1.10
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/.nvmrc +1 -0
- package/LICENSE +9 -9
- package/README.md +154 -138
- package/api/TropipayAPI.d.ts +93 -0
- package/config/TropipayConfig.d.ts +2 -0
- package/constants/TropipayConstants.d.ts +1 -0
- package/docs/index.MD +18 -18
- package/globals.d.ts +75 -75
- package/hooks/TropipayHooks.d.ts +17 -0
- package/index.d.ts +154 -23
- package/index.js +149 -49
- package/interfaces/index.d.ts +159 -2
- package/package.json +43 -43
- package/rollup.config.js +24 -23
- package/src/api/TropipayAPI.ts +319 -0
- package/src/config/TropipayConfig.ts +2 -0
- package/src/constants/TropipayConstants.ts +1 -0
- package/src/hooks/TropipayHooks.ts +52 -0
- package/src/index.ts +13 -299
- package/src/interfaces/index.js +1 -1
- package/src/interfaces/index.ts +172 -4
- package/src/interfaces/mediation/index.ts +22 -22
- package/src/interfaces/paymentlink/index.d.ts +36 -36
- package/src/interfaces/paymentlink/index.js +2 -2
- package/src/interfaces/paymentlink/index.ts +39 -39
- package/src/utils/TropipayUtils.ts +42 -0
- package/tsconfig.json +95 -95
- package/utils/TropipayUtils.d.ts +17 -0
- package/src/globals.d.ts +0 -74
- package/src/interfaces/countries/index.d.ts +0 -0
- package/src/interfaces/countries/index.js +0 -2
- package/src/interfaces/countries/index.ts +0 -3
- package/src/interfaces/index.d.ts +0 -0
- package/src/interfaces/paymentlink.js +0 -1
package/index.d.ts
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
import { Axios } from 'axios';
|
|
2
2
|
|
|
3
|
+
type ServerMode$1 = "Development" | "Production";
|
|
4
|
+
|
|
5
|
+
type AccountBalance = {
|
|
6
|
+
balance: number;
|
|
7
|
+
pendingIn: number;
|
|
8
|
+
pendingOut: number;
|
|
9
|
+
};
|
|
10
|
+
interface TropipayConfig {
|
|
11
|
+
clientId: string;
|
|
12
|
+
clientSecret: string;
|
|
13
|
+
serverMode?: ServerMode$1;
|
|
14
|
+
}
|
|
15
|
+
type TropipayCredentials = {
|
|
16
|
+
clientId: string;
|
|
17
|
+
clientSecret: string;
|
|
18
|
+
};
|
|
19
|
+
type HookEventType = "transaction_completed" | "transaction_charged" | "transaction_guarded";
|
|
20
|
+
type HookTargetType = "web" | "email";
|
|
21
|
+
interface UserHook {
|
|
22
|
+
event: HookEventType;
|
|
23
|
+
target: string;
|
|
24
|
+
value: string;
|
|
25
|
+
}
|
|
26
|
+
interface UserHook {
|
|
27
|
+
event: HookEventType;
|
|
28
|
+
target: string;
|
|
29
|
+
value: string;
|
|
30
|
+
}
|
|
31
|
+
interface UserHookSubscribed extends UserHook {
|
|
32
|
+
createdAt: string;
|
|
33
|
+
updatedAt: string;
|
|
34
|
+
}
|
|
35
|
+
interface UserHookSubscribed extends UserHook {
|
|
36
|
+
createdAt: string;
|
|
37
|
+
updatedAt: string;
|
|
38
|
+
}
|
|
3
39
|
interface PaymentLinkPayload {
|
|
4
40
|
reference: string;
|
|
5
41
|
concept: string;
|
|
@@ -36,10 +72,6 @@ interface PaymentLink extends PaymentLinkPayload {
|
|
|
36
72
|
shortUrl: string;
|
|
37
73
|
paymentUrl: string;
|
|
38
74
|
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
*/
|
|
43
75
|
interface mediationPaymentCardConfig {
|
|
44
76
|
amount: number;
|
|
45
77
|
currency: "EUR" | "USD";
|
|
@@ -59,6 +91,91 @@ interface mediationPaymentCardConfig {
|
|
|
59
91
|
feeFixed?: number;
|
|
60
92
|
sendMail: boolean;
|
|
61
93
|
}
|
|
94
|
+
type LoginResponse = {
|
|
95
|
+
access_token: string;
|
|
96
|
+
refresh_token: string;
|
|
97
|
+
token_type: "Bearer";
|
|
98
|
+
expires_in: number;
|
|
99
|
+
scope: string;
|
|
100
|
+
};
|
|
101
|
+
type LoginError = {
|
|
102
|
+
error: string;
|
|
103
|
+
};
|
|
104
|
+
type Country = {
|
|
105
|
+
id: number;
|
|
106
|
+
name: string;
|
|
107
|
+
sepaZone: boolean;
|
|
108
|
+
state: number;
|
|
109
|
+
slug: string;
|
|
110
|
+
slugn: number;
|
|
111
|
+
callingCode: number;
|
|
112
|
+
isDestination: boolean;
|
|
113
|
+
isRisky: boolean;
|
|
114
|
+
currentCurrency: string | null;
|
|
115
|
+
createdAt: string;
|
|
116
|
+
updatedAt: string;
|
|
117
|
+
isFavorite: boolean;
|
|
118
|
+
position: any;
|
|
119
|
+
};
|
|
120
|
+
type Deposit = {
|
|
121
|
+
id: number;
|
|
122
|
+
accountNumber: string;
|
|
123
|
+
alias: string;
|
|
124
|
+
swift: string;
|
|
125
|
+
type: number;
|
|
126
|
+
country: number | null;
|
|
127
|
+
firstName: string;
|
|
128
|
+
default: null;
|
|
129
|
+
state: number;
|
|
130
|
+
userId: string;
|
|
131
|
+
countryDestinationId: number;
|
|
132
|
+
lastName: string;
|
|
133
|
+
documentNumber: number;
|
|
134
|
+
userRelationTypeId: number;
|
|
135
|
+
city: string;
|
|
136
|
+
postalCode: string;
|
|
137
|
+
address: string;
|
|
138
|
+
phone: string;
|
|
139
|
+
checked: boolean;
|
|
140
|
+
province: string;
|
|
141
|
+
beneficiaryType: number;
|
|
142
|
+
relatedUserId: null | string;
|
|
143
|
+
currency: string;
|
|
144
|
+
correspondent?: any;
|
|
145
|
+
location: any;
|
|
146
|
+
office: any;
|
|
147
|
+
officeValue: any;
|
|
148
|
+
paymentType: number;
|
|
149
|
+
paymentEntityBeneficiaryId: number;
|
|
150
|
+
paymentEntityAccountId: number;
|
|
151
|
+
verified: any;
|
|
152
|
+
paymentEntityInfo: any;
|
|
153
|
+
documentTypeId: any;
|
|
154
|
+
documentExpirationDate: Date;
|
|
155
|
+
createdAt: Date;
|
|
156
|
+
updatedAt: Date;
|
|
157
|
+
countryDestination: Country;
|
|
158
|
+
};
|
|
159
|
+
type AccountDeposits = {
|
|
160
|
+
count: number;
|
|
161
|
+
rows: Deposit[];
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
declare class TropipayHooks {
|
|
165
|
+
private tropipay;
|
|
166
|
+
constructor(tropipayInstance: Tropipay);
|
|
167
|
+
static subscribeHook(eventType: HookEventType, target: string, value: string): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Get hook the sucbcribed hook info by his eventType.
|
|
170
|
+
* If no eventType is passed it will return
|
|
171
|
+
* all subscribed hooks or empty Array if none hooks exist.
|
|
172
|
+
* @param eventType or no params for retrieving all hooks
|
|
173
|
+
* @returns
|
|
174
|
+
*/
|
|
175
|
+
getSubscribedHook(eventType?: HookEventType): Promise<UserHookSubscribed[]>;
|
|
176
|
+
updateSubscribedHook(eventType?: string): Promise<void>;
|
|
177
|
+
deleteSubscribedHook(eventType?: string): Promise<void>;
|
|
178
|
+
}
|
|
62
179
|
|
|
63
180
|
/**
|
|
64
181
|
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
@@ -67,24 +184,16 @@ interface mediationPaymentCardConfig {
|
|
|
67
184
|
*
|
|
68
185
|
*/
|
|
69
186
|
|
|
70
|
-
type ServerMode =
|
|
71
|
-
|
|
72
|
-
clientId: string;
|
|
73
|
-
clientSecret: string;
|
|
74
|
-
serverMode?: ServerMode;
|
|
75
|
-
}
|
|
76
|
-
type AccountBalance = {
|
|
77
|
-
balance: number;
|
|
78
|
-
pendingIn: number;
|
|
79
|
-
pendingOut: number;
|
|
80
|
-
};
|
|
187
|
+
type ServerMode = "Development" | "Production";
|
|
188
|
+
|
|
81
189
|
declare class Tropipay {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
190
|
+
readonly clientId: string;
|
|
191
|
+
readonly clientSecret: string;
|
|
192
|
+
request: Axios;
|
|
193
|
+
static accessToken: string | undefined;
|
|
194
|
+
static refreshToken: string | undefined;
|
|
195
|
+
serverMode: ServerMode;
|
|
196
|
+
hooks: TropipayHooks;
|
|
88
197
|
constructor(config: TropipayConfig);
|
|
89
198
|
login(): Promise<LoginResponse>;
|
|
90
199
|
/**
|
|
@@ -108,7 +217,7 @@ declare class Tropipay {
|
|
|
108
217
|
countries(): Promise<Country[]>;
|
|
109
218
|
/**
|
|
110
219
|
* Get user balance
|
|
111
|
-
* @returns balance
|
|
220
|
+
* @returns balance Object { balance: number, pendingIn: number, pendingOut: number }
|
|
112
221
|
*/
|
|
113
222
|
getBalance(): Promise<AccountBalance>;
|
|
114
223
|
/**
|
|
@@ -156,5 +265,27 @@ declare class Tropipay {
|
|
|
156
265
|
*/
|
|
157
266
|
createMediationPaymentCard(config: mediationPaymentCardConfig): Promise<PaymentLink>;
|
|
158
267
|
}
|
|
268
|
+
declare class ClientSideUtils {
|
|
269
|
+
constructor(tropipayInstance: Tropipay);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
declare class ServerSideUtils {
|
|
273
|
+
private tropipay;
|
|
274
|
+
constructor(tropipayInstance: Tropipay);
|
|
275
|
+
/**
|
|
276
|
+
* Verify Topipay's signature on webhooks.
|
|
277
|
+
* @param credentials Credential object or Tropipay instance
|
|
278
|
+
* @param {String} originalCurrencyAmount
|
|
279
|
+
* @param bankOrderCode
|
|
280
|
+
* @param signature
|
|
281
|
+
* @returns {Boolean}
|
|
282
|
+
*/
|
|
283
|
+
static verifySignature(credentials: {
|
|
284
|
+
clientId: string;
|
|
285
|
+
clientSecret: string;
|
|
286
|
+
} | Tropipay, originalCurrencyAmount: string, bankOrderCode: string, signature: string): boolean;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
declare const SERVER_MODE: ServerMode$1;
|
|
159
290
|
|
|
160
|
-
export { Tropipay };
|
|
291
|
+
export { AccountBalance, AccountDeposits, ClientSideUtils, Country, Deposit, HookEventType, HookTargetType, LoginError, LoginResponse, PaymentLink, PaymentLinkPayload, SERVER_MODE, ServerMode$1 as ServerMode, ServerSideUtils, Tropipay, TropipayConfig, TropipayCredentials, TropipayHooks, UserHook, UserHookSubscribed, mediationPaymentCardConfig };
|
package/index.js
CHANGED
|
@@ -3,10 +3,72 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var axios = require('axios');
|
|
6
|
+
var crypto = require('crypto');
|
|
6
7
|
|
|
7
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
9
|
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n["default"] = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
9
28
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
29
|
+
var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
|
|
30
|
+
|
|
31
|
+
class TropipayHooks {
|
|
32
|
+
tropipay;
|
|
33
|
+
// ... hook-related functionality ...
|
|
34
|
+
constructor(tropipayInstance) {
|
|
35
|
+
this.tropipay = tropipayInstance;
|
|
36
|
+
}
|
|
37
|
+
static async subscribeHook(eventType, target, value) { }
|
|
38
|
+
/**
|
|
39
|
+
* Get hook the sucbcribed hook info by his eventType.
|
|
40
|
+
* If no eventType is passed it will return
|
|
41
|
+
* all subscribed hooks or empty Array if none hooks exist.
|
|
42
|
+
* @param eventType or no params for retrieving all hooks
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
async getSubscribedHook(eventType) {
|
|
46
|
+
if (!Tropipay.accessToken) {
|
|
47
|
+
await this.tropipay.login();
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const hooks = await this.tropipay.request.get(`/api/v2/hooks/${eventType || ""}`, {
|
|
51
|
+
headers: {
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
54
|
+
Accept: "application/json",
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
return hooks.data;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
throw new Error(`Could not get subscribed hooks ${error}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async updateSubscribedHook(eventType) {
|
|
64
|
+
//TODO
|
|
65
|
+
throw new Error("Not implementet yet");
|
|
66
|
+
}
|
|
67
|
+
async deleteSubscribedHook(eventType) {
|
|
68
|
+
//TODO
|
|
69
|
+
throw new Error("Not implementet yet");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
10
72
|
|
|
11
73
|
/**
|
|
12
74
|
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
@@ -21,33 +83,35 @@ class Tropipay {
|
|
|
21
83
|
static accessToken;
|
|
22
84
|
static refreshToken;
|
|
23
85
|
serverMode;
|
|
86
|
+
hooks;
|
|
24
87
|
constructor(config) {
|
|
25
88
|
this.clientId = config.clientId;
|
|
26
89
|
this.clientSecret = config.clientSecret;
|
|
27
|
-
this.serverMode = config.serverMode ||
|
|
90
|
+
this.serverMode = config.serverMode || "Development";
|
|
28
91
|
this.request = axios__default["default"].create({
|
|
29
|
-
baseURL: this.serverMode ===
|
|
30
|
-
?
|
|
31
|
-
:
|
|
92
|
+
baseURL: this.serverMode === "Production"
|
|
93
|
+
? "https://www.tropipay.com"
|
|
94
|
+
: "https://tropipay-dev.herokuapp.com",
|
|
32
95
|
headers: {
|
|
33
|
-
|
|
34
|
-
Accept:
|
|
96
|
+
"Content-Type": "application/json",
|
|
97
|
+
Accept: "application/json",
|
|
35
98
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
36
|
-
}
|
|
99
|
+
},
|
|
37
100
|
});
|
|
101
|
+
this.hooks = new TropipayHooks(this);
|
|
38
102
|
}
|
|
39
103
|
async login() {
|
|
40
104
|
try {
|
|
41
|
-
const { data } = await this.request.post(
|
|
105
|
+
const { data } = await this.request.post("/api/v2/access/token", {
|
|
42
106
|
client_id: this.clientId,
|
|
43
107
|
client_secret: this.clientSecret,
|
|
44
108
|
grant_type: "client_credentials",
|
|
45
|
-
scope: "ALLOW_GET_PROFILE_DATA ALLOW_PAYMENT_IN ALLOW_EXTERNAL_CHARGE KYC3_FULL_ALLOW ALLOW_PAYMENT_OUT ALLOW_MARKET_PURCHASES ALLOW_GET_BALANCE ALLOW_GET_MOVEMENT_LIST ALLOW_GET_CREDENTIAL"
|
|
109
|
+
scope: "ALLOW_GET_PROFILE_DATA ALLOW_PAYMENT_IN ALLOW_EXTERNAL_CHARGE KYC3_FULL_ALLOW ALLOW_PAYMENT_OUT ALLOW_MARKET_PURCHASES ALLOW_GET_BALANCE ALLOW_GET_MOVEMENT_LIST ALLOW_GET_CREDENTIAL",
|
|
46
110
|
}, {
|
|
47
111
|
headers: {
|
|
48
|
-
|
|
49
|
-
Accept:
|
|
50
|
-
}
|
|
112
|
+
"Content-Type": "application/json",
|
|
113
|
+
Accept: "application/json",
|
|
114
|
+
},
|
|
51
115
|
});
|
|
52
116
|
Tropipay.accessToken = data.access_token;
|
|
53
117
|
Tropipay.refreshToken = data.refresh_token;
|
|
@@ -71,12 +135,12 @@ class Tropipay {
|
|
|
71
135
|
await this.login();
|
|
72
136
|
}
|
|
73
137
|
try {
|
|
74
|
-
const paylink = await this.request.post(
|
|
138
|
+
const paylink = await this.request.post("/api/v2/paymentcards", payload, {
|
|
75
139
|
headers: {
|
|
76
|
-
|
|
140
|
+
"Content-Type": "application/json",
|
|
77
141
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
78
|
-
Accept:
|
|
79
|
-
}
|
|
142
|
+
Accept: "application/json",
|
|
143
|
+
},
|
|
80
144
|
});
|
|
81
145
|
return paylink.data;
|
|
82
146
|
}
|
|
@@ -94,12 +158,12 @@ class Tropipay {
|
|
|
94
158
|
await this.login();
|
|
95
159
|
}
|
|
96
160
|
try {
|
|
97
|
-
const deposits = await this.request.get(
|
|
161
|
+
const deposits = await this.request.get("/api/v2/deposit_accounts", {
|
|
98
162
|
headers: {
|
|
99
|
-
|
|
163
|
+
"Content-Type": "application/json",
|
|
100
164
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
101
|
-
Accept:
|
|
102
|
-
}
|
|
165
|
+
Accept: "application/json",
|
|
166
|
+
},
|
|
103
167
|
});
|
|
104
168
|
return deposits.data;
|
|
105
169
|
}
|
|
@@ -114,33 +178,32 @@ class Tropipay {
|
|
|
114
178
|
*/
|
|
115
179
|
async countries() {
|
|
116
180
|
try {
|
|
117
|
-
const countries = await this.request.get(
|
|
181
|
+
const countries = await this.request.get("/api/v2/countries");
|
|
118
182
|
return countries.data;
|
|
119
183
|
}
|
|
120
184
|
catch (error) {
|
|
121
|
-
throw new Error(`
|
|
185
|
+
throw new Error(`Could not retrieve the countries list`);
|
|
122
186
|
}
|
|
123
187
|
}
|
|
124
188
|
/**
|
|
125
189
|
* Get user balance
|
|
126
|
-
* @returns balance
|
|
190
|
+
* @returns balance Object { balance: number, pendingIn: number, pendingOut: number }
|
|
127
191
|
*/
|
|
128
192
|
async getBalance() {
|
|
129
193
|
if (!Tropipay.accessToken) {
|
|
130
194
|
await this.login();
|
|
131
195
|
}
|
|
132
196
|
try {
|
|
133
|
-
const balance = await this.request.get(
|
|
197
|
+
const balance = await this.request.get("/api/v2/users/balance", {
|
|
134
198
|
headers: {
|
|
135
|
-
|
|
199
|
+
"Content-Type": "application/json",
|
|
136
200
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
137
|
-
Accept:
|
|
138
|
-
}
|
|
201
|
+
Accept: "application/json",
|
|
202
|
+
},
|
|
139
203
|
});
|
|
140
204
|
return balance.data;
|
|
141
205
|
}
|
|
142
206
|
catch (error) {
|
|
143
|
-
console.log("el error es ", error);
|
|
144
207
|
throw new Error(`TropipayJS Error - Could not retrieve the user's balance`);
|
|
145
208
|
}
|
|
146
209
|
}
|
|
@@ -154,7 +217,7 @@ class Tropipay {
|
|
|
154
217
|
*/
|
|
155
218
|
async destinations() {
|
|
156
219
|
try {
|
|
157
|
-
const countries = await this.request.get(
|
|
220
|
+
const countries = await this.request.get("/api/v2/countries/destinations");
|
|
158
221
|
return countries.data;
|
|
159
222
|
}
|
|
160
223
|
catch (error) {
|
|
@@ -170,12 +233,12 @@ class Tropipay {
|
|
|
170
233
|
await this.login();
|
|
171
234
|
}
|
|
172
235
|
try {
|
|
173
|
-
const favoritesList = await this.request.get(
|
|
236
|
+
const favoritesList = await this.request.get("/api/v2/paymentcards/favorites", {
|
|
174
237
|
headers: {
|
|
175
|
-
|
|
238
|
+
"Content-Type": "application/json",
|
|
176
239
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
177
|
-
Accept:
|
|
178
|
-
}
|
|
240
|
+
Accept: "application/json",
|
|
241
|
+
},
|
|
179
242
|
});
|
|
180
243
|
return favoritesList?.data?.rows;
|
|
181
244
|
}
|
|
@@ -192,13 +255,13 @@ class Tropipay {
|
|
|
192
255
|
if (!Tropipay.accessToken)
|
|
193
256
|
await this.login();
|
|
194
257
|
try {
|
|
195
|
-
const movements = await this.request.get(
|
|
258
|
+
const movements = await this.request.get("/api/v2/movements", {
|
|
196
259
|
params: { limit: limit, offset: offset },
|
|
197
260
|
headers: {
|
|
198
|
-
|
|
199
|
-
Accept:
|
|
200
|
-
Authorization: `Bearer ${Tropipay.accessToken}
|
|
201
|
-
}
|
|
261
|
+
"Content-Type": "application/json",
|
|
262
|
+
Accept: "application/json",
|
|
263
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
264
|
+
},
|
|
202
265
|
});
|
|
203
266
|
return movements.data;
|
|
204
267
|
}
|
|
@@ -214,7 +277,7 @@ class Tropipay {
|
|
|
214
277
|
if (!Tropipay.accessToken)
|
|
215
278
|
await this.login();
|
|
216
279
|
try {
|
|
217
|
-
const profile = await this.request.get(
|
|
280
|
+
const profile = await this.request.get("/api/users/profile");
|
|
218
281
|
return profile.data;
|
|
219
282
|
}
|
|
220
283
|
catch (error) {
|
|
@@ -229,20 +292,20 @@ class Tropipay {
|
|
|
229
292
|
* @returns Conversion rate (number)
|
|
230
293
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
|
|
231
294
|
*/
|
|
232
|
-
async rates(originCurrency, targetCurrency =
|
|
295
|
+
async rates(originCurrency, targetCurrency = "EUR") {
|
|
233
296
|
if (!Tropipay.accessToken) {
|
|
234
297
|
await this.login();
|
|
235
298
|
}
|
|
236
299
|
try {
|
|
237
|
-
const rates = await this.request.post(
|
|
300
|
+
const rates = await this.request.post("/api/v2/movements/get_rate", {
|
|
238
301
|
currencyFrom: originCurrency,
|
|
239
|
-
currencyTo: targetCurrency
|
|
302
|
+
currencyTo: targetCurrency,
|
|
240
303
|
}, {
|
|
241
304
|
headers: {
|
|
242
|
-
|
|
243
|
-
Accept:
|
|
305
|
+
"Content-Type": "application/json",
|
|
306
|
+
Accept: "application/json",
|
|
244
307
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
245
|
-
}
|
|
308
|
+
},
|
|
246
309
|
});
|
|
247
310
|
return rates.data.rate;
|
|
248
311
|
}
|
|
@@ -263,12 +326,12 @@ class Tropipay {
|
|
|
263
326
|
if (!Tropipay.accessToken)
|
|
264
327
|
await this.login();
|
|
265
328
|
try {
|
|
266
|
-
const mediation = await this.request.post(
|
|
329
|
+
const mediation = await this.request.post("/api/v2/paymentcards/mediation", config, {
|
|
267
330
|
headers: {
|
|
268
|
-
|
|
331
|
+
"Content-Type": "application/json",
|
|
269
332
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
270
|
-
Accept:
|
|
271
|
-
}
|
|
333
|
+
Accept: "application/json",
|
|
334
|
+
},
|
|
272
335
|
});
|
|
273
336
|
return mediation.data;
|
|
274
337
|
}
|
|
@@ -277,6 +340,43 @@ class Tropipay {
|
|
|
277
340
|
}
|
|
278
341
|
}
|
|
279
342
|
}
|
|
343
|
+
class ClientSideUtils {
|
|
344
|
+
constructor(tropipayInstance) { }
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
class ServerSideUtils {
|
|
348
|
+
tropipay;
|
|
349
|
+
constructor(tropipayInstance) {
|
|
350
|
+
this.tropipay = tropipayInstance;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Verify Topipay's signature on webhooks.
|
|
354
|
+
* @param credentials Credential object or Tropipay instance
|
|
355
|
+
* @param {String} originalCurrencyAmount
|
|
356
|
+
* @param bankOrderCode
|
|
357
|
+
* @param signature
|
|
358
|
+
* @returns {Boolean}
|
|
359
|
+
*/
|
|
360
|
+
static verifySignature(credentials, originalCurrencyAmount, bankOrderCode, signature) {
|
|
361
|
+
const localSignature = crypto__namespace
|
|
362
|
+
.createHash("sha256")
|
|
363
|
+
.update(bankOrderCode +
|
|
364
|
+
credentials.clientId +
|
|
365
|
+
crypto__namespace
|
|
366
|
+
.createHash("sha1")
|
|
367
|
+
.update(credentials.clientSecret)
|
|
368
|
+
.digest("hex") +
|
|
369
|
+
originalCurrencyAmount)
|
|
370
|
+
.digest("hex");
|
|
371
|
+
return localSignature === signature;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const SERVER_MODE = "Development"; // Move the constant here
|
|
280
376
|
|
|
377
|
+
exports.ClientSideUtils = ClientSideUtils;
|
|
378
|
+
exports.SERVER_MODE = SERVER_MODE;
|
|
379
|
+
exports.ServerSideUtils = ServerSideUtils;
|
|
281
380
|
exports.Tropipay = Tropipay;
|
|
381
|
+
exports.TropipayHooks = TropipayHooks;
|
|
282
382
|
//# sourceMappingURL=index.js.map
|