@yosle/tropipayjs 0.1.9 → 0.1.11
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 +38 -0
- package/index.d.ts +177 -25
- package/index.js +241 -53
- package/interfaces/index.d.ts +159 -2
- package/interfaces/paymentlink/index.d.ts +56 -5
- package/package.json +43 -43
- package/rollup.config.js +24 -23
- package/src/api/TropipayAPI.ts +317 -0
- package/src/config/TropipayConfig.ts +2 -0
- package/src/constants/TropipayConstants.ts +1 -0
- package/src/hooks/TropipayHooks.ts +153 -0
- package/src/index.ts +19 -299
- package/src/interfaces/index.js +1 -1
- package/src/interfaces/index.ts +193 -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 +91 -40
- 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" | "user_signup" | "user_kyc" | "payment_in_state_change" | "payment_out_state_change" | "beneficiary_added" | "beneficiary_updated" | "beneficiary_deleted" | "transaction_new" | "transaction_preauthorized" | "transaction_pendingin" | "transaction_processing" | "transaction_error" | "transaction_bloqued" | "transaction_guarded_send" | "transaction_guarded_mediation" | "user_after_update" | "user_after_create" | "userDetail_after_create" | "userDetail_after_update" | "tpv_callback_ok" | "fraud_state_on_change";
|
|
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,112 @@ 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
|
+
/**
|
|
168
|
+
* Subscribe a new hook
|
|
169
|
+
* @param event String that represents the name of the event,
|
|
170
|
+
* you must select from the list of available events, otherwise
|
|
171
|
+
* it will not produce an error but it will not be executed.
|
|
172
|
+
* For get full list of available events see endpoint
|
|
173
|
+
* GET /api/v2/hook/events.
|
|
174
|
+
* @param target String representing the type of event supported.
|
|
175
|
+
* It is currently available: 'web' (allows to receive information in a url),
|
|
176
|
+
* 'email' (allows to receive information in an email address).
|
|
177
|
+
* @param value if the selected 'target' is email the value would be an
|
|
178
|
+
* email address, likewise if the selected 'target' is 'web' the expected
|
|
179
|
+
* value corresponds to a url that receives information through the
|
|
180
|
+
* HTTP POST method.
|
|
181
|
+
* @returns
|
|
182
|
+
*/
|
|
183
|
+
subscribe({ eventType, target, value, }: {
|
|
184
|
+
eventType: HookEventType;
|
|
185
|
+
target: "email" | "web";
|
|
186
|
+
value: string;
|
|
187
|
+
}): Promise<any>;
|
|
188
|
+
/**
|
|
189
|
+
* Get the sucbcribed hook info by his event type.
|
|
190
|
+
* If no event type is passed, it will return
|
|
191
|
+
* all subscribed hooks or empty Array if none exist.
|
|
192
|
+
* @param eventType or no params for retrieving all hooks
|
|
193
|
+
* @returns All subscribed hooks or empty Array if none exist.
|
|
194
|
+
*/
|
|
195
|
+
list(eventType?: HookEventType): Promise<UserHookSubscribed[]>;
|
|
196
|
+
update(eventType: string, target: "web" | "email", value: string): Promise<any>;
|
|
197
|
+
delete(eventType: HookEventType, target: string): Promise<any>;
|
|
198
|
+
events(): Promise<any>;
|
|
199
|
+
}
|
|
62
200
|
|
|
63
201
|
/**
|
|
64
202
|
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
@@ -67,24 +205,16 @@ interface mediationPaymentCardConfig {
|
|
|
67
205
|
*
|
|
68
206
|
*/
|
|
69
207
|
|
|
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
|
-
};
|
|
208
|
+
type ServerMode = "Development" | "Production";
|
|
209
|
+
|
|
81
210
|
declare class Tropipay {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
211
|
+
readonly clientId: string;
|
|
212
|
+
readonly clientSecret: string;
|
|
213
|
+
request: Axios;
|
|
214
|
+
static accessToken: string | undefined;
|
|
215
|
+
static refreshToken: string | undefined;
|
|
216
|
+
serverMode: ServerMode;
|
|
217
|
+
hooks: TropipayHooks;
|
|
88
218
|
constructor(config: TropipayConfig);
|
|
89
219
|
login(): Promise<LoginResponse>;
|
|
90
220
|
/**
|
|
@@ -108,7 +238,7 @@ declare class Tropipay {
|
|
|
108
238
|
countries(): Promise<Country[]>;
|
|
109
239
|
/**
|
|
110
240
|
* Get user balance
|
|
111
|
-
* @returns balance
|
|
241
|
+
* @returns balance Object { balance: number, pendingIn: number, pendingOut: number }
|
|
112
242
|
*/
|
|
113
243
|
getBalance(): Promise<AccountBalance>;
|
|
114
244
|
/**
|
|
@@ -132,8 +262,8 @@ declare class Tropipay {
|
|
|
132
262
|
*/
|
|
133
263
|
movements(offset?: number, limit?: number): Promise<any>;
|
|
134
264
|
/**
|
|
135
|
-
* Return profile data for
|
|
136
|
-
* @returns
|
|
265
|
+
* Return profile data for current Tropipay account.
|
|
266
|
+
* @returns account object
|
|
137
267
|
*/
|
|
138
268
|
profile(): Promise<any>;
|
|
139
269
|
/**
|
|
@@ -156,5 +286,27 @@ declare class Tropipay {
|
|
|
156
286
|
*/
|
|
157
287
|
createMediationPaymentCard(config: mediationPaymentCardConfig): Promise<PaymentLink>;
|
|
158
288
|
}
|
|
289
|
+
declare class ClientSideUtils {
|
|
290
|
+
constructor(tropipayInstance: Tropipay);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
declare class ServerSideUtils {
|
|
294
|
+
private tropipay;
|
|
295
|
+
constructor(tropipayInstance: Tropipay);
|
|
296
|
+
/**
|
|
297
|
+
* Verify Topipay's signature on webhooks.
|
|
298
|
+
* @param credentials Credential object or Tropipay instance
|
|
299
|
+
* @param {String} originalCurrencyAmount
|
|
300
|
+
* @param bankOrderCode
|
|
301
|
+
* @param signature
|
|
302
|
+
* @returns {Boolean}
|
|
303
|
+
*/
|
|
304
|
+
static verifySignature(credentials: {
|
|
305
|
+
clientId: string;
|
|
306
|
+
clientSecret: string;
|
|
307
|
+
} | Tropipay, originalCurrencyAmount: string, bankOrderCode: string, signature: string): boolean;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
declare const SERVER_MODE: ServerMode$1;
|
|
159
311
|
|
|
160
|
-
export { Tropipay };
|
|
312
|
+
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,160 @@
|
|
|
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
|
+
/**
|
|
38
|
+
* Subscribe a new hook
|
|
39
|
+
* @param event String that represents the name of the event,
|
|
40
|
+
* you must select from the list of available events, otherwise
|
|
41
|
+
* it will not produce an error but it will not be executed.
|
|
42
|
+
* For get full list of available events see endpoint
|
|
43
|
+
* GET /api/v2/hook/events.
|
|
44
|
+
* @param target String representing the type of event supported.
|
|
45
|
+
* It is currently available: 'web' (allows to receive information in a url),
|
|
46
|
+
* 'email' (allows to receive information in an email address).
|
|
47
|
+
* @param value if the selected 'target' is email the value would be an
|
|
48
|
+
* email address, likewise if the selected 'target' is 'web' the expected
|
|
49
|
+
* value corresponds to a url that receives information through the
|
|
50
|
+
* HTTP POST method.
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
async subscribe({ eventType, target, value, }) {
|
|
54
|
+
if (!Tropipay.accessToken) {
|
|
55
|
+
await this.tropipay.login();
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const hooks = await this.tropipay.request.post(`/api/v2/hooks`, {
|
|
59
|
+
event: eventType,
|
|
60
|
+
target: target,
|
|
61
|
+
value: value,
|
|
62
|
+
}, {
|
|
63
|
+
headers: {
|
|
64
|
+
"Content-Type": "application/json",
|
|
65
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
66
|
+
Accept: "application/json",
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
return hooks.data;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw new Error(`Could not get subscribe new hook`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the sucbcribed hook info by his event type.
|
|
77
|
+
* If no event type is passed, it will return
|
|
78
|
+
* all subscribed hooks or empty Array if none exist.
|
|
79
|
+
* @param eventType or no params for retrieving all hooks
|
|
80
|
+
* @returns All subscribed hooks or empty Array if none exist.
|
|
81
|
+
*/
|
|
82
|
+
async list(eventType) {
|
|
83
|
+
if (!Tropipay.accessToken) {
|
|
84
|
+
await this.tropipay.login();
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const hooks = await this.tropipay.request.get(`/api/v2/hooks/${eventType || ""}`, {
|
|
88
|
+
headers: {
|
|
89
|
+
"Content-Type": "application/json",
|
|
90
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
91
|
+
Accept: "application/json",
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
return hooks.data;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw new Error(`Could not get subscribed hooks`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async update(eventType, target, value) {
|
|
101
|
+
if (!Tropipay.accessToken) {
|
|
102
|
+
await this.tropipay.login();
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const hooks = await this.tropipay.request.put(`/api/v2/hooks`, {
|
|
106
|
+
event: eventType,
|
|
107
|
+
target: target,
|
|
108
|
+
value: value,
|
|
109
|
+
}, {
|
|
110
|
+
headers: {
|
|
111
|
+
"Content-Type": "application/json",
|
|
112
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
113
|
+
Accept: "application/json",
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
return hooks.data;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new Error(`Could not update subscribed hooks`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async delete(eventType, target) {
|
|
123
|
+
if (!Tropipay.accessToken) {
|
|
124
|
+
await this.tropipay.login();
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const hooks = await this.tropipay.request.delete(`/api/v2/hooks/${eventType}/${target}`, {
|
|
128
|
+
headers: {
|
|
129
|
+
"Content-Type": "application/json",
|
|
130
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
131
|
+
Accept: "application/json",
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
return hooks.data;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.trace(error);
|
|
138
|
+
throw new Error(`Could not delete subscribed hooks`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async events() {
|
|
142
|
+
if (!Tropipay.accessToken) {
|
|
143
|
+
await this.tropipay.login();
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const hooks = await this.tropipay.request.get(`/api/v2/hooks/events`, {
|
|
147
|
+
headers: {
|
|
148
|
+
"Content-Type": "application/json",
|
|
149
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
150
|
+
Accept: "application/json",
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
return hooks.data;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
throw new Error(`Could not get events list for hooks ${error}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
10
160
|
|
|
11
161
|
/**
|
|
12
162
|
* Tropipayjs is a Typescript/Javascript library for the Tropipay API.
|
|
@@ -21,33 +171,35 @@ class Tropipay {
|
|
|
21
171
|
static accessToken;
|
|
22
172
|
static refreshToken;
|
|
23
173
|
serverMode;
|
|
174
|
+
hooks;
|
|
24
175
|
constructor(config) {
|
|
25
176
|
this.clientId = config.clientId;
|
|
26
177
|
this.clientSecret = config.clientSecret;
|
|
27
|
-
this.serverMode = config.serverMode ||
|
|
178
|
+
this.serverMode = config.serverMode || "Development";
|
|
28
179
|
this.request = axios__default["default"].create({
|
|
29
|
-
baseURL: this.serverMode ===
|
|
30
|
-
?
|
|
31
|
-
:
|
|
180
|
+
baseURL: this.serverMode === "Production"
|
|
181
|
+
? "https://www.tropipay.com"
|
|
182
|
+
: "https://tropipay-dev.herokuapp.com",
|
|
32
183
|
headers: {
|
|
33
|
-
|
|
34
|
-
Accept:
|
|
184
|
+
"Content-Type": "application/json",
|
|
185
|
+
Accept: "application/json",
|
|
35
186
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
36
|
-
}
|
|
187
|
+
},
|
|
37
188
|
});
|
|
189
|
+
this.hooks = new TropipayHooks(this);
|
|
38
190
|
}
|
|
39
191
|
async login() {
|
|
40
192
|
try {
|
|
41
|
-
const { data } = await this.request.post(
|
|
193
|
+
const { data } = await this.request.post("/api/v2/access/token", {
|
|
42
194
|
client_id: this.clientId,
|
|
43
195
|
client_secret: this.clientSecret,
|
|
44
196
|
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"
|
|
197
|
+
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
198
|
}, {
|
|
47
199
|
headers: {
|
|
48
|
-
|
|
49
|
-
Accept:
|
|
50
|
-
}
|
|
200
|
+
"Content-Type": "application/json",
|
|
201
|
+
Accept: "application/json",
|
|
202
|
+
},
|
|
51
203
|
});
|
|
52
204
|
Tropipay.accessToken = data.access_token;
|
|
53
205
|
Tropipay.refreshToken = data.refresh_token;
|
|
@@ -71,17 +223,17 @@ class Tropipay {
|
|
|
71
223
|
await this.login();
|
|
72
224
|
}
|
|
73
225
|
try {
|
|
74
|
-
const paylink = await this.request.post(
|
|
226
|
+
const paylink = await this.request.post("/api/v2/paymentcards", payload, {
|
|
75
227
|
headers: {
|
|
76
|
-
|
|
228
|
+
"Content-Type": "application/json",
|
|
77
229
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
78
|
-
Accept:
|
|
79
|
-
}
|
|
230
|
+
Accept: "application/json",
|
|
231
|
+
},
|
|
80
232
|
});
|
|
81
233
|
return paylink.data;
|
|
82
234
|
}
|
|
83
235
|
catch (error) {
|
|
84
|
-
throw new Error(`
|
|
236
|
+
throw new Error(`TropipayJS - Error creating the Payment Card.`);
|
|
85
237
|
}
|
|
86
238
|
}
|
|
87
239
|
/**
|
|
@@ -94,12 +246,12 @@ class Tropipay {
|
|
|
94
246
|
await this.login();
|
|
95
247
|
}
|
|
96
248
|
try {
|
|
97
|
-
const deposits = await this.request.get(
|
|
249
|
+
const deposits = await this.request.get("/api/v2/deposit_accounts", {
|
|
98
250
|
headers: {
|
|
99
|
-
|
|
251
|
+
"Content-Type": "application/json",
|
|
100
252
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
101
|
-
Accept:
|
|
102
|
-
}
|
|
253
|
+
Accept: "application/json",
|
|
254
|
+
},
|
|
103
255
|
});
|
|
104
256
|
return deposits.data;
|
|
105
257
|
}
|
|
@@ -114,33 +266,32 @@ class Tropipay {
|
|
|
114
266
|
*/
|
|
115
267
|
async countries() {
|
|
116
268
|
try {
|
|
117
|
-
const countries = await this.request.get(
|
|
269
|
+
const countries = await this.request.get("/api/v2/countries");
|
|
118
270
|
return countries.data;
|
|
119
271
|
}
|
|
120
272
|
catch (error) {
|
|
121
|
-
throw new Error(`
|
|
273
|
+
throw new Error(`Could not retrieve the countries list`);
|
|
122
274
|
}
|
|
123
275
|
}
|
|
124
276
|
/**
|
|
125
277
|
* Get user balance
|
|
126
|
-
* @returns balance
|
|
278
|
+
* @returns balance Object { balance: number, pendingIn: number, pendingOut: number }
|
|
127
279
|
*/
|
|
128
280
|
async getBalance() {
|
|
129
281
|
if (!Tropipay.accessToken) {
|
|
130
282
|
await this.login();
|
|
131
283
|
}
|
|
132
284
|
try {
|
|
133
|
-
const balance = await this.request.get(
|
|
285
|
+
const balance = await this.request.get("/api/v2/users/balance", {
|
|
134
286
|
headers: {
|
|
135
|
-
|
|
287
|
+
"Content-Type": "application/json",
|
|
136
288
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
137
|
-
Accept:
|
|
138
|
-
}
|
|
289
|
+
Accept: "application/json",
|
|
290
|
+
},
|
|
139
291
|
});
|
|
140
292
|
return balance.data;
|
|
141
293
|
}
|
|
142
294
|
catch (error) {
|
|
143
|
-
console.log("el error es ", error);
|
|
144
295
|
throw new Error(`TropipayJS Error - Could not retrieve the user's balance`);
|
|
145
296
|
}
|
|
146
297
|
}
|
|
@@ -154,7 +305,7 @@ class Tropipay {
|
|
|
154
305
|
*/
|
|
155
306
|
async destinations() {
|
|
156
307
|
try {
|
|
157
|
-
const countries = await this.request.get(
|
|
308
|
+
const countries = await this.request.get("/api/v2/countries/destinations");
|
|
158
309
|
return countries.data;
|
|
159
310
|
}
|
|
160
311
|
catch (error) {
|
|
@@ -170,12 +321,12 @@ class Tropipay {
|
|
|
170
321
|
await this.login();
|
|
171
322
|
}
|
|
172
323
|
try {
|
|
173
|
-
const favoritesList = await this.request.get(
|
|
324
|
+
const favoritesList = await this.request.get("/api/v2/paymentcards/favorites", {
|
|
174
325
|
headers: {
|
|
175
|
-
|
|
326
|
+
"Content-Type": "application/json",
|
|
176
327
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
177
|
-
Accept:
|
|
178
|
-
}
|
|
328
|
+
Accept: "application/json",
|
|
329
|
+
},
|
|
179
330
|
});
|
|
180
331
|
return favoritesList?.data?.rows;
|
|
181
332
|
}
|
|
@@ -192,13 +343,13 @@ class Tropipay {
|
|
|
192
343
|
if (!Tropipay.accessToken)
|
|
193
344
|
await this.login();
|
|
194
345
|
try {
|
|
195
|
-
const movements = await this.request.get(
|
|
346
|
+
const movements = await this.request.get("/api/v2/movements", {
|
|
196
347
|
params: { limit: limit, offset: offset },
|
|
197
348
|
headers: {
|
|
198
|
-
|
|
199
|
-
Accept:
|
|
200
|
-
Authorization: `Bearer ${Tropipay.accessToken}
|
|
201
|
-
}
|
|
349
|
+
"Content-Type": "application/json",
|
|
350
|
+
Accept: "application/json",
|
|
351
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
352
|
+
},
|
|
202
353
|
});
|
|
203
354
|
return movements.data;
|
|
204
355
|
}
|
|
@@ -207,14 +358,14 @@ class Tropipay {
|
|
|
207
358
|
}
|
|
208
359
|
}
|
|
209
360
|
/**
|
|
210
|
-
* Return profile data for
|
|
211
|
-
* @returns
|
|
361
|
+
* Return profile data for current Tropipay account.
|
|
362
|
+
* @returns account object
|
|
212
363
|
*/
|
|
213
364
|
async profile() {
|
|
214
365
|
if (!Tropipay.accessToken)
|
|
215
366
|
await this.login();
|
|
216
367
|
try {
|
|
217
|
-
const profile = await this.request.get(
|
|
368
|
+
const profile = await this.request.get("/api/users/profile");
|
|
218
369
|
return profile.data;
|
|
219
370
|
}
|
|
220
371
|
catch (error) {
|
|
@@ -229,20 +380,20 @@ class Tropipay {
|
|
|
229
380
|
* @returns Conversion rate (number)
|
|
230
381
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
|
|
231
382
|
*/
|
|
232
|
-
async rates(originCurrency, targetCurrency =
|
|
383
|
+
async rates(originCurrency, targetCurrency = "EUR") {
|
|
233
384
|
if (!Tropipay.accessToken) {
|
|
234
385
|
await this.login();
|
|
235
386
|
}
|
|
236
387
|
try {
|
|
237
|
-
const rates = await this.request.post(
|
|
388
|
+
const rates = await this.request.post("/api/v2/movements/get_rate", {
|
|
238
389
|
currencyFrom: originCurrency,
|
|
239
|
-
currencyTo: targetCurrency
|
|
390
|
+
currencyTo: targetCurrency,
|
|
240
391
|
}, {
|
|
241
392
|
headers: {
|
|
242
|
-
|
|
243
|
-
Accept:
|
|
393
|
+
"Content-Type": "application/json",
|
|
394
|
+
Accept: "application/json",
|
|
244
395
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
245
|
-
}
|
|
396
|
+
},
|
|
246
397
|
});
|
|
247
398
|
return rates.data.rate;
|
|
248
399
|
}
|
|
@@ -263,20 +414,57 @@ class Tropipay {
|
|
|
263
414
|
if (!Tropipay.accessToken)
|
|
264
415
|
await this.login();
|
|
265
416
|
try {
|
|
266
|
-
const mediation = await this.request.post(
|
|
417
|
+
const mediation = await this.request.post("/api/v2/paymentcards/mediation", config, {
|
|
267
418
|
headers: {
|
|
268
|
-
|
|
419
|
+
"Content-Type": "application/json",
|
|
269
420
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
270
|
-
Accept:
|
|
271
|
-
}
|
|
421
|
+
Accept: "application/json",
|
|
422
|
+
},
|
|
272
423
|
});
|
|
273
424
|
return mediation.data;
|
|
274
425
|
}
|
|
275
426
|
catch (error) {
|
|
276
|
-
throw new Error(`Could not
|
|
427
|
+
throw new Error(`Could not create mediation payment card`);
|
|
277
428
|
}
|
|
278
429
|
}
|
|
279
430
|
}
|
|
431
|
+
class ClientSideUtils {
|
|
432
|
+
constructor(tropipayInstance) { }
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
class ServerSideUtils {
|
|
436
|
+
tropipay;
|
|
437
|
+
constructor(tropipayInstance) {
|
|
438
|
+
this.tropipay = tropipayInstance;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Verify Topipay's signature on webhooks.
|
|
442
|
+
* @param credentials Credential object or Tropipay instance
|
|
443
|
+
* @param {String} originalCurrencyAmount
|
|
444
|
+
* @param bankOrderCode
|
|
445
|
+
* @param signature
|
|
446
|
+
* @returns {Boolean}
|
|
447
|
+
*/
|
|
448
|
+
static verifySignature(credentials, originalCurrencyAmount, bankOrderCode, signature) {
|
|
449
|
+
const localSignature = crypto__namespace
|
|
450
|
+
.createHash("sha256")
|
|
451
|
+
.update(bankOrderCode +
|
|
452
|
+
credentials.clientId +
|
|
453
|
+
crypto__namespace
|
|
454
|
+
.createHash("sha1")
|
|
455
|
+
.update(credentials.clientSecret)
|
|
456
|
+
.digest("hex") +
|
|
457
|
+
originalCurrencyAmount)
|
|
458
|
+
.digest("hex");
|
|
459
|
+
return localSignature === signature;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const SERVER_MODE = "Development"; // Move the constant here
|
|
280
464
|
|
|
465
|
+
exports.ClientSideUtils = ClientSideUtils;
|
|
466
|
+
exports.SERVER_MODE = SERVER_MODE;
|
|
467
|
+
exports.ServerSideUtils = ServerSideUtils;
|
|
281
468
|
exports.Tropipay = Tropipay;
|
|
469
|
+
exports.TropipayHooks = TropipayHooks;
|
|
282
470
|
//# sourceMappingURL=index.js.map
|