@yosle/tropipayjs 0.1.8 → 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 -131
- 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 -74
- package/hooks/TropipayHooks.d.ts +17 -0
- package/index.d.ts +158 -17
- package/index.js +166 -43
- 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 -272
- 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,19 +184,16 @@ interface mediationPaymentCardConfig {
|
|
|
67
184
|
*
|
|
68
185
|
*/
|
|
69
186
|
|
|
70
|
-
type ServerMode =
|
|
71
|
-
|
|
72
|
-
clientId: string;
|
|
73
|
-
clientSecret: string;
|
|
74
|
-
serverMode?: ServerMode;
|
|
75
|
-
}
|
|
187
|
+
type ServerMode = "Development" | "Production";
|
|
188
|
+
|
|
76
189
|
declare class Tropipay {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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;
|
|
83
197
|
constructor(config: TropipayConfig);
|
|
84
198
|
login(): Promise<LoginResponse>;
|
|
85
199
|
/**
|
|
@@ -101,6 +215,11 @@ declare class Tropipay {
|
|
|
101
215
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/bfac21259e2ff-getting-users-countries-list
|
|
102
216
|
*/
|
|
103
217
|
countries(): Promise<Country[]>;
|
|
218
|
+
/**
|
|
219
|
+
* Get user balance
|
|
220
|
+
* @returns balance Object { balance: number, pendingIn: number, pendingOut: number }
|
|
221
|
+
*/
|
|
222
|
+
getBalance(): Promise<AccountBalance>;
|
|
104
223
|
/**
|
|
105
224
|
* Get the list of all detination countries supported by Tropipay.
|
|
106
225
|
* Obtaining the list of valid countries to send funds to. Useful
|
|
@@ -146,5 +265,27 @@ declare class Tropipay {
|
|
|
146
265
|
*/
|
|
147
266
|
createMediationPaymentCard(config: mediationPaymentCardConfig): Promise<PaymentLink>;
|
|
148
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;
|
|
149
290
|
|
|
150
|
-
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,11 +178,33 @@ 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`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get user balance
|
|
190
|
+
* @returns balance Object { balance: number, pendingIn: number, pendingOut: number }
|
|
191
|
+
*/
|
|
192
|
+
async getBalance() {
|
|
193
|
+
if (!Tropipay.accessToken) {
|
|
194
|
+
await this.login();
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
const balance = await this.request.get("/api/v2/users/balance", {
|
|
198
|
+
headers: {
|
|
199
|
+
"Content-Type": "application/json",
|
|
200
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
201
|
+
Accept: "application/json",
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
return balance.data;
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
throw new Error(`TropipayJS Error - Could not retrieve the user's balance`);
|
|
122
208
|
}
|
|
123
209
|
}
|
|
124
210
|
/**
|
|
@@ -131,7 +217,7 @@ class Tropipay {
|
|
|
131
217
|
*/
|
|
132
218
|
async destinations() {
|
|
133
219
|
try {
|
|
134
|
-
const countries = await this.request.get(
|
|
220
|
+
const countries = await this.request.get("/api/v2/countries/destinations");
|
|
135
221
|
return countries.data;
|
|
136
222
|
}
|
|
137
223
|
catch (error) {
|
|
@@ -147,12 +233,12 @@ class Tropipay {
|
|
|
147
233
|
await this.login();
|
|
148
234
|
}
|
|
149
235
|
try {
|
|
150
|
-
const favoritesList = await this.request.get(
|
|
236
|
+
const favoritesList = await this.request.get("/api/v2/paymentcards/favorites", {
|
|
151
237
|
headers: {
|
|
152
|
-
|
|
238
|
+
"Content-Type": "application/json",
|
|
153
239
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
154
|
-
Accept:
|
|
155
|
-
}
|
|
240
|
+
Accept: "application/json",
|
|
241
|
+
},
|
|
156
242
|
});
|
|
157
243
|
return favoritesList?.data?.rows;
|
|
158
244
|
}
|
|
@@ -169,13 +255,13 @@ class Tropipay {
|
|
|
169
255
|
if (!Tropipay.accessToken)
|
|
170
256
|
await this.login();
|
|
171
257
|
try {
|
|
172
|
-
const movements = await this.request.get(
|
|
258
|
+
const movements = await this.request.get("/api/v2/movements", {
|
|
173
259
|
params: { limit: limit, offset: offset },
|
|
174
260
|
headers: {
|
|
175
|
-
|
|
176
|
-
Accept:
|
|
177
|
-
Authorization: `Bearer ${Tropipay.accessToken}
|
|
178
|
-
}
|
|
261
|
+
"Content-Type": "application/json",
|
|
262
|
+
Accept: "application/json",
|
|
263
|
+
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
264
|
+
},
|
|
179
265
|
});
|
|
180
266
|
return movements.data;
|
|
181
267
|
}
|
|
@@ -191,7 +277,7 @@ class Tropipay {
|
|
|
191
277
|
if (!Tropipay.accessToken)
|
|
192
278
|
await this.login();
|
|
193
279
|
try {
|
|
194
|
-
const profile = await this.request.get(
|
|
280
|
+
const profile = await this.request.get("/api/users/profile");
|
|
195
281
|
return profile.data;
|
|
196
282
|
}
|
|
197
283
|
catch (error) {
|
|
@@ -206,20 +292,20 @@ class Tropipay {
|
|
|
206
292
|
* @returns Conversion rate (number)
|
|
207
293
|
* @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
|
|
208
294
|
*/
|
|
209
|
-
async rates(originCurrency, targetCurrency =
|
|
295
|
+
async rates(originCurrency, targetCurrency = "EUR") {
|
|
210
296
|
if (!Tropipay.accessToken) {
|
|
211
297
|
await this.login();
|
|
212
298
|
}
|
|
213
299
|
try {
|
|
214
|
-
const rates = await this.request.post(
|
|
300
|
+
const rates = await this.request.post("/api/v2/movements/get_rate", {
|
|
215
301
|
currencyFrom: originCurrency,
|
|
216
|
-
currencyTo: targetCurrency
|
|
302
|
+
currencyTo: targetCurrency,
|
|
217
303
|
}, {
|
|
218
304
|
headers: {
|
|
219
|
-
|
|
220
|
-
Accept:
|
|
305
|
+
"Content-Type": "application/json",
|
|
306
|
+
Accept: "application/json",
|
|
221
307
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
222
|
-
}
|
|
308
|
+
},
|
|
223
309
|
});
|
|
224
310
|
return rates.data.rate;
|
|
225
311
|
}
|
|
@@ -240,12 +326,12 @@ class Tropipay {
|
|
|
240
326
|
if (!Tropipay.accessToken)
|
|
241
327
|
await this.login();
|
|
242
328
|
try {
|
|
243
|
-
const mediation = await this.request.post(
|
|
329
|
+
const mediation = await this.request.post("/api/v2/paymentcards/mediation", config, {
|
|
244
330
|
headers: {
|
|
245
|
-
|
|
331
|
+
"Content-Type": "application/json",
|
|
246
332
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
247
|
-
Accept:
|
|
248
|
-
}
|
|
333
|
+
Accept: "application/json",
|
|
334
|
+
},
|
|
249
335
|
});
|
|
250
336
|
return mediation.data;
|
|
251
337
|
}
|
|
@@ -254,6 +340,43 @@ class Tropipay {
|
|
|
254
340
|
}
|
|
255
341
|
}
|
|
256
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
|
|
257
376
|
|
|
377
|
+
exports.ClientSideUtils = ClientSideUtils;
|
|
378
|
+
exports.SERVER_MODE = SERVER_MODE;
|
|
379
|
+
exports.ServerSideUtils = ServerSideUtils;
|
|
258
380
|
exports.Tropipay = Tropipay;
|
|
381
|
+
exports.TropipayHooks = TropipayHooks;
|
|
259
382
|
//# sourceMappingURL=index.js.map
|
package/interfaces/index.d.ts
CHANGED
|
@@ -1,2 +1,159 @@
|
|
|
1
|
-
import
|
|
2
|
-
export
|
|
1
|
+
import { ServerMode } from "../constants/TropipayConstants";
|
|
2
|
+
export type AccountBalance = {
|
|
3
|
+
balance: number;
|
|
4
|
+
pendingIn: number;
|
|
5
|
+
pendingOut: number;
|
|
6
|
+
};
|
|
7
|
+
export interface TropipayConfig {
|
|
8
|
+
clientId: string;
|
|
9
|
+
clientSecret: string;
|
|
10
|
+
serverMode?: ServerMode;
|
|
11
|
+
}
|
|
12
|
+
export type TropipayCredentials = {
|
|
13
|
+
clientId: string;
|
|
14
|
+
clientSecret: string;
|
|
15
|
+
};
|
|
16
|
+
export type HookEventType = "transaction_completed" | "transaction_charged" | "transaction_guarded";
|
|
17
|
+
export type HookTargetType = "web" | "email";
|
|
18
|
+
export interface UserHook {
|
|
19
|
+
event: HookEventType;
|
|
20
|
+
target: string;
|
|
21
|
+
value: string;
|
|
22
|
+
}
|
|
23
|
+
export interface UserHookSubscribed extends UserHook {
|
|
24
|
+
createdAt: string;
|
|
25
|
+
updatedAt: string;
|
|
26
|
+
}
|
|
27
|
+
export interface UserHook {
|
|
28
|
+
event: HookEventType;
|
|
29
|
+
target: string;
|
|
30
|
+
value: string;
|
|
31
|
+
}
|
|
32
|
+
export interface UserHookSubscribed extends UserHook {
|
|
33
|
+
createdAt: string;
|
|
34
|
+
updatedAt: string;
|
|
35
|
+
}
|
|
36
|
+
export interface PaymentLinkPayload {
|
|
37
|
+
reference: string;
|
|
38
|
+
concept: string;
|
|
39
|
+
favorite: boolean;
|
|
40
|
+
amount: number;
|
|
41
|
+
currency: string;
|
|
42
|
+
description: string;
|
|
43
|
+
singleUse: boolean;
|
|
44
|
+
reasonId: number;
|
|
45
|
+
expirationDays: number;
|
|
46
|
+
lang: string;
|
|
47
|
+
urlSuccess: string;
|
|
48
|
+
urlFailed: string;
|
|
49
|
+
urlNotification: string;
|
|
50
|
+
serviceDate: string;
|
|
51
|
+
client: {
|
|
52
|
+
name: string;
|
|
53
|
+
lastName: string;
|
|
54
|
+
address: string;
|
|
55
|
+
phone: string;
|
|
56
|
+
email: string;
|
|
57
|
+
countryId: number;
|
|
58
|
+
termsAndConditions: boolean;
|
|
59
|
+
};
|
|
60
|
+
directPayment: boolean;
|
|
61
|
+
paymentMethods?: string[];
|
|
62
|
+
}
|
|
63
|
+
export interface PaymentLink extends PaymentLinkPayload {
|
|
64
|
+
expirationDate: string;
|
|
65
|
+
hasClient: boolean;
|
|
66
|
+
updatedAt: string;
|
|
67
|
+
createdAt: string;
|
|
68
|
+
qrImage: string;
|
|
69
|
+
shortUrl: string;
|
|
70
|
+
paymentUrl: string;
|
|
71
|
+
}
|
|
72
|
+
export interface mediationPaymentCardConfig {
|
|
73
|
+
amount: number;
|
|
74
|
+
currency: "EUR" | "USD";
|
|
75
|
+
concept: string;
|
|
76
|
+
description: string;
|
|
77
|
+
reference: string;
|
|
78
|
+
singleUse: boolean;
|
|
79
|
+
lang: string;
|
|
80
|
+
productUrl?: string;
|
|
81
|
+
buyer: null | any;
|
|
82
|
+
seller: {
|
|
83
|
+
sellerId?: number;
|
|
84
|
+
type?: number;
|
|
85
|
+
email?: string;
|
|
86
|
+
};
|
|
87
|
+
feePercent?: number;
|
|
88
|
+
feeFixed?: number;
|
|
89
|
+
sendMail: boolean;
|
|
90
|
+
}
|
|
91
|
+
export type LoginResponse = {
|
|
92
|
+
access_token: string;
|
|
93
|
+
refresh_token: string;
|
|
94
|
+
token_type: "Bearer";
|
|
95
|
+
expires_in: number;
|
|
96
|
+
scope: string;
|
|
97
|
+
};
|
|
98
|
+
export type LoginError = {
|
|
99
|
+
error: string;
|
|
100
|
+
};
|
|
101
|
+
export type Country = {
|
|
102
|
+
id: number;
|
|
103
|
+
name: string;
|
|
104
|
+
sepaZone: boolean;
|
|
105
|
+
state: number;
|
|
106
|
+
slug: string;
|
|
107
|
+
slugn: number;
|
|
108
|
+
callingCode: number;
|
|
109
|
+
isDestination: boolean;
|
|
110
|
+
isRisky: boolean;
|
|
111
|
+
currentCurrency: string | null;
|
|
112
|
+
createdAt: string;
|
|
113
|
+
updatedAt: string;
|
|
114
|
+
isFavorite: boolean;
|
|
115
|
+
position: any;
|
|
116
|
+
};
|
|
117
|
+
export type Deposit = {
|
|
118
|
+
id: number;
|
|
119
|
+
accountNumber: string;
|
|
120
|
+
alias: string;
|
|
121
|
+
swift: string;
|
|
122
|
+
type: number;
|
|
123
|
+
country: number | null;
|
|
124
|
+
firstName: string;
|
|
125
|
+
default: null;
|
|
126
|
+
state: number;
|
|
127
|
+
userId: string;
|
|
128
|
+
countryDestinationId: number;
|
|
129
|
+
lastName: string;
|
|
130
|
+
documentNumber: number;
|
|
131
|
+
userRelationTypeId: number;
|
|
132
|
+
city: string;
|
|
133
|
+
postalCode: string;
|
|
134
|
+
address: string;
|
|
135
|
+
phone: string;
|
|
136
|
+
checked: boolean;
|
|
137
|
+
province: string;
|
|
138
|
+
beneficiaryType: number;
|
|
139
|
+
relatedUserId: null | string;
|
|
140
|
+
currency: string;
|
|
141
|
+
correspondent?: any;
|
|
142
|
+
location: any;
|
|
143
|
+
office: any;
|
|
144
|
+
officeValue: any;
|
|
145
|
+
paymentType: number;
|
|
146
|
+
paymentEntityBeneficiaryId: number;
|
|
147
|
+
paymentEntityAccountId: number;
|
|
148
|
+
verified: any;
|
|
149
|
+
paymentEntityInfo: any;
|
|
150
|
+
documentTypeId: any;
|
|
151
|
+
documentExpirationDate: Date;
|
|
152
|
+
createdAt: Date;
|
|
153
|
+
updatedAt: Date;
|
|
154
|
+
countryDestination: Country;
|
|
155
|
+
};
|
|
156
|
+
export type AccountDeposits = {
|
|
157
|
+
count: number;
|
|
158
|
+
rows: Deposit[];
|
|
159
|
+
};
|