@yosle/tropipayjs 0.1.22 → 0.1.23
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 -1
- package/.vscode/launch.json +18 -18
- package/LICENSE +9 -9
- package/README.md +152 -152
- package/api/TropipayAPI.d.ts +1 -0
- package/docs/readme.md +3 -3
- package/globals.d.ts +75 -75
- package/index.d.ts +10 -6
- package/index.js +26 -3
- package/interfaces/countries/index.d.ts +1 -1
- package/interfaces/index.d.ts +9 -6
- package/jest.config.js +5 -5
- package/package.json +49 -49
- package/paymentcard/paymentcard.spec.d.ts +1 -1
- package/rollup.config.js +24 -24
- package/src/api/TropipayAPI.ts +370 -338
- package/src/config/TropipayConfig.ts +2 -2
- package/src/constants/TropipayConstants.ts +2 -2
- package/src/depositAccount/depositAccounts.ts +139 -139
- package/src/hooks/TropipayHooks.ts +154 -154
- package/src/index.ts +28 -28
- package/src/interfaces/depositaccounts/index.ts +70 -70
- package/src/interfaces/index.js +1 -1
- package/src/interfaces/index.ts +201 -197
- 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 -91
- package/src/mediationPaymentCard/MediationPaymentCard.ts +42 -42
- package/src/paymentcard/PaymentCard.ts +123 -123
- package/src/paymentcard/paymentcard.spec.ts +79 -79
- package/src/utils/TropipayUtils.ts +126 -126
- package/src/utils/errors.ts +92 -92
- package/tsconfig.json +96 -96
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
v20.10.0
|
|
1
|
+
v20.10.0
|
package/.vscode/launch.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [
|
|
7
|
-
{
|
|
8
|
-
"type": "node",
|
|
9
|
-
"name": "vscode-jest-tests",
|
|
10
|
-
"request": "launch",
|
|
11
|
-
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
|
|
12
|
-
"args": ["paymentcard.spec.ts"],
|
|
13
|
-
"cwd": "${workspaceFolder}",
|
|
14
|
-
"console": "integratedTerminal",
|
|
15
|
-
"runtimeExecutable": "/home/yosle/.nvm/versions/node/v20.10.0/bin/node"
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
}
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"type": "node",
|
|
9
|
+
"name": "vscode-jest-tests",
|
|
10
|
+
"request": "launch",
|
|
11
|
+
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
|
|
12
|
+
"args": ["paymentcard.spec.ts"],
|
|
13
|
+
"cwd": "${workspaceFolder}",
|
|
14
|
+
"console": "integratedTerminal",
|
|
15
|
+
"runtimeExecutable": "/home/yosle/.nvm/versions/node/v20.10.0/bin/node"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/LICENSE
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Yosleivy Baez Acosta.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
6
|
-
furnished to do so, subject to the following conditions:
|
|
7
|
-
|
|
8
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Yosleivy Baez Acosta.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
6
|
+
furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
10
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,152 +1,152 @@
|
|
|
1
|
-
# TropipayJS - Typescript/Javascript SDK for Tropipay Payments API
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-

|
|
5
|
-

|
|
6
|
-

|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
<p align="center">
|
|
10
|
-
<a href="https://yosle.github.io/tropipayjs-docs">Explore the TropipayJS Documentation</a>
|
|
11
|
-
</p>
|
|
12
|
-
|
|
13
|
-
TropiPay is an electronic wallet that allows you to execute the most common financial operations of the day to day. This is SDK for Typescript and Javacript that helps you build integrations with the Tropipay platform in an easier way. Can save you a lot of time and effort implementing all the API features. You can use this library with CommonJS system (node + express) or ES6 module system (NextJS).
|
|
14
|
-
|
|
15
|
-
# Table of Contents
|
|
16
|
-
|
|
17
|
-
- [TropipayJS - Typescript/Javascript SDK for Tropipay Payments API](#tropipayjs---typescriptjavascript-sdk-for-tropipay-payments-api)
|
|
18
|
-
- [Table of Contents](#table-of-contents)
|
|
19
|
-
- [About the project](#about-the-project)
|
|
20
|
-
- [Getting started](#getting-started)
|
|
21
|
-
- [Setting up your app credentials](#setting-up-your-app-credentials)
|
|
22
|
-
- [Usage](#usage)
|
|
23
|
-
- [CommonJS](#commonjs)
|
|
24
|
-
- [ES6](#es6)
|
|
25
|
-
- [Initialize the Tropipay class](#initialize-the-tropipay-class)
|
|
26
|
-
- [Generating a Payment Link](#generating-a-payment-link)
|
|
27
|
-
- [Contributing](#contributing)
|
|
28
|
-
- [License](#license)
|
|
29
|
-
|
|
30
|
-
## About the project
|
|
31
|
-
|
|
32
|
-
This library is a community effort. Tropipay may make some changes on the API specification. Use the [test environment](https://tropipay-dev.herokuapp.com) to make sure everything is working as expected.
|
|
33
|
-
|
|
34
|
-
**Note:** This library is provided as-is and serves as a client for the Tropipay API. While every effort has been made to ensure the accuracy and reliability of the library, Tropipay is solely responsible for maintaining and updating the API documentation.
|
|
35
|
-
|
|
36
|
-
The library is intended to simplify the integration process with Tropipay's services, but it is essential to consult the official documentation to ensure that you are using the API correctly and taking into account any recent changes or updates made by Tropipay.
|
|
37
|
-
|
|
38
|
-
# Getting started
|
|
39
|
-
|
|
40
|
-
You can use npm or yarn to install this package:
|
|
41
|
-
|
|
42
|
-
`npm install @yosle/tropipayjs`
|
|
43
|
-
|
|
44
|
-
or
|
|
45
|
-
|
|
46
|
-
`yarn add @yosle/tropipayjs`
|
|
47
|
-
|
|
48
|
-
## Setting up your app credentials
|
|
49
|
-
|
|
50
|
-

|
|
51
|
-

|
|
52
|
-
|
|
53
|
-
In order to use the Tropipay API you'll need a client ID and a client secret. Sign up with your [Tropipay](www.tropipay.com) account, go to the App Menu->Applications and credentials. You'll be asked to enter a confirmation code (use 123456 in the test enviroment). _Make sure you test everything in the [test environment](https://tropipay-dev.herokuapp.com) first before using your real account._ Create an app and configure the client id an client secret for the app.
|
|
54
|
-
|
|
55
|
-
## Usage
|
|
56
|
-
|
|
57
|
-
The Tropipay instance, allows you to access all the method available in the API. This Object is meant to be used _only in server side_. Do not use the Tropipay object on the client side (browser). This would expose your app credentials (the client secret of your account). You can create an endpoint at your back-end using express and consume it in your front-end, or use SSR if you're using NextJS.
|
|
58
|
-
|
|
59
|
-
### CommonJS
|
|
60
|
-
|
|
61
|
-
```javascript
|
|
62
|
-
const { Tropipay } = require("@yosle/tropipayjs");
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### ES6
|
|
66
|
-
|
|
67
|
-
```javascript
|
|
68
|
-
import { Tropipay } from "@yosle/tropipayjs";
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Initialize the Tropipay class
|
|
72
|
-
|
|
73
|
-
You can instantiate the Tropipay class passing the client Id ,client secret and optionally the serverMode parameter, if no serverMode is provided, `Development` will be used as default. Make sure you use the [test environment](https://tropipay-dev.herokuapp.com) credentials when serverMode is on `Development`.
|
|
74
|
-
|
|
75
|
-
```javascript
|
|
76
|
-
// test environment server tropipay-dev.herokuapp.com
|
|
77
|
-
const config = {
|
|
78
|
-
clientId: process.env.TROPIPAY_CLIENT_ID,
|
|
79
|
-
clientSecret: process.env.TROPIPAY_CLIENT_SECRET
|
|
80
|
-
serverMode: 'Development' // it will be used as default if omited
|
|
81
|
-
}
|
|
82
|
-
const tpp = new Tropipay(config)
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
To use your live credentials (real account) you must explicity set serverMode to `Production`.
|
|
86
|
-
|
|
87
|
-
```javascript
|
|
88
|
-
//real account credentials
|
|
89
|
-
const config = {
|
|
90
|
-
clientId: process.env.TROPIPAY_CLIENT_ID,
|
|
91
|
-
clientSecret: process.env.TROPIPAY_CLIENT_SECRET,
|
|
92
|
-
serverMode: "Production", //live account
|
|
93
|
-
};
|
|
94
|
-
const tpp = new Tropipay(config);
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### Generating a Payment Link
|
|
98
|
-
|
|
99
|
-
```javascript
|
|
100
|
-
/*
|
|
101
|
-
* Example Payload
|
|
102
|
-
*/
|
|
103
|
-
const payload = {
|
|
104
|
-
reference: "my-paylink-1",
|
|
105
|
-
concept: "Bicycle",
|
|
106
|
-
favorite: "true",
|
|
107
|
-
amount: 3000,
|
|
108
|
-
currency: "EUR",
|
|
109
|
-
description: "Two wheels",
|
|
110
|
-
singleUse: "true",
|
|
111
|
-
reasonId: 4,
|
|
112
|
-
expirationDays: 1,
|
|
113
|
-
lang: "es",
|
|
114
|
-
urlSuccess: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
|
|
115
|
-
urlFailed: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
|
|
116
|
-
urlNotification: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
|
|
117
|
-
serviceDate: "2021-08-20",
|
|
118
|
-
client: {
|
|
119
|
-
name: "John",
|
|
120
|
-
lastName: "McClane",
|
|
121
|
-
address: "Ave. Guadí 232, Barcelona, Barcelona",
|
|
122
|
-
phone: "+34645553333",
|
|
123
|
-
email: "client@email.com",
|
|
124
|
-
countryId: 1,
|
|
125
|
-
termsAndConditions: "true",
|
|
126
|
-
},
|
|
127
|
-
directPayment: "true",
|
|
128
|
-
};
|
|
129
|
-
// Use inside an async function
|
|
130
|
-
const paylink = await tpp.paymentCards.create(payload);
|
|
131
|
-
console.log(paylink.shortUrl);
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
For more examples, please refer to the [Documentation](https://github.com/yosle/tropipayjs/blob/master/docs/)
|
|
135
|
-
|
|
136
|
-
# Contributing
|
|
137
|
-
|
|
138
|
-
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
|
|
139
|
-
|
|
140
|
-
1. Fork the Project
|
|
141
|
-
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
|
142
|
-
3. Commit your Changes (`git commit -m 'Add some AmazingFeature`)
|
|
143
|
-
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
|
144
|
-
5. Open a Pull Request
|
|
145
|
-
|
|
146
|
-
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
147
|
-
|
|
148
|
-
You can also make a small [donation to the author](https://tppay.me/l94qaa3h) of the library.
|
|
149
|
-
|
|
150
|
-
# License
|
|
151
|
-
|
|
152
|
-
Distributed under the MIT License. See `LICENSE.txt` for more information.
|
|
1
|
+
# TropipayJS - Typescript/Javascript SDK for Tropipay Payments API
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://yosle.github.io/tropipayjs-docs">Explore the TropipayJS Documentation</a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
TropiPay is an electronic wallet that allows you to execute the most common financial operations of the day to day. This is SDK for Typescript and Javacript that helps you build integrations with the Tropipay platform in an easier way. Can save you a lot of time and effort implementing all the API features. You can use this library with CommonJS system (node + express) or ES6 module system (NextJS).
|
|
14
|
+
|
|
15
|
+
# Table of Contents
|
|
16
|
+
|
|
17
|
+
- [TropipayJS - Typescript/Javascript SDK for Tropipay Payments API](#tropipayjs---typescriptjavascript-sdk-for-tropipay-payments-api)
|
|
18
|
+
- [Table of Contents](#table-of-contents)
|
|
19
|
+
- [About the project](#about-the-project)
|
|
20
|
+
- [Getting started](#getting-started)
|
|
21
|
+
- [Setting up your app credentials](#setting-up-your-app-credentials)
|
|
22
|
+
- [Usage](#usage)
|
|
23
|
+
- [CommonJS](#commonjs)
|
|
24
|
+
- [ES6](#es6)
|
|
25
|
+
- [Initialize the Tropipay class](#initialize-the-tropipay-class)
|
|
26
|
+
- [Generating a Payment Link](#generating-a-payment-link)
|
|
27
|
+
- [Contributing](#contributing)
|
|
28
|
+
- [License](#license)
|
|
29
|
+
|
|
30
|
+
## About the project
|
|
31
|
+
|
|
32
|
+
This library is a community effort. Tropipay may make some changes on the API specification. Use the [test environment](https://tropipay-dev.herokuapp.com) to make sure everything is working as expected.
|
|
33
|
+
|
|
34
|
+
**Note:** This library is provided as-is and serves as a client for the Tropipay API. While every effort has been made to ensure the accuracy and reliability of the library, Tropipay is solely responsible for maintaining and updating the API documentation.
|
|
35
|
+
|
|
36
|
+
The library is intended to simplify the integration process with Tropipay's services, but it is essential to consult the official documentation to ensure that you are using the API correctly and taking into account any recent changes or updates made by Tropipay.
|
|
37
|
+
|
|
38
|
+
# Getting started
|
|
39
|
+
|
|
40
|
+
You can use npm or yarn to install this package:
|
|
41
|
+
|
|
42
|
+
`npm install @yosle/tropipayjs`
|
|
43
|
+
|
|
44
|
+
or
|
|
45
|
+
|
|
46
|
+
`yarn add @yosle/tropipayjs`
|
|
47
|
+
|
|
48
|
+
## Setting up your app credentials
|
|
49
|
+
|
|
50
|
+

|
|
51
|
+

|
|
52
|
+
|
|
53
|
+
In order to use the Tropipay API you'll need a client ID and a client secret. Sign up with your [Tropipay](www.tropipay.com) account, go to the App Menu->Applications and credentials. You'll be asked to enter a confirmation code (use 123456 in the test enviroment). _Make sure you test everything in the [test environment](https://tropipay-dev.herokuapp.com) first before using your real account._ Create an app and configure the client id an client secret for the app.
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
The Tropipay instance, allows you to access all the method available in the API. This Object is meant to be used _only in server side_. Do not use the Tropipay object on the client side (browser). This would expose your app credentials (the client secret of your account). You can create an endpoint at your back-end using express and consume it in your front-end, or use SSR if you're using NextJS.
|
|
58
|
+
|
|
59
|
+
### CommonJS
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
const { Tropipay } = require("@yosle/tropipayjs");
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### ES6
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
import { Tropipay } from "@yosle/tropipayjs";
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Initialize the Tropipay class
|
|
72
|
+
|
|
73
|
+
You can instantiate the Tropipay class passing the client Id ,client secret and optionally the serverMode parameter, if no serverMode is provided, `Development` will be used as default. Make sure you use the [test environment](https://tropipay-dev.herokuapp.com) credentials when serverMode is on `Development`.
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
// test environment server tropipay-dev.herokuapp.com
|
|
77
|
+
const config = {
|
|
78
|
+
clientId: process.env.TROPIPAY_CLIENT_ID,
|
|
79
|
+
clientSecret: process.env.TROPIPAY_CLIENT_SECRET
|
|
80
|
+
serverMode: 'Development' // it will be used as default if omited
|
|
81
|
+
}
|
|
82
|
+
const tpp = new Tropipay(config)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
To use your live credentials (real account) you must explicity set serverMode to `Production`.
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
//real account credentials
|
|
89
|
+
const config = {
|
|
90
|
+
clientId: process.env.TROPIPAY_CLIENT_ID,
|
|
91
|
+
clientSecret: process.env.TROPIPAY_CLIENT_SECRET,
|
|
92
|
+
serverMode: "Production", //live account
|
|
93
|
+
};
|
|
94
|
+
const tpp = new Tropipay(config);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Generating a Payment Link
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
/*
|
|
101
|
+
* Example Payload
|
|
102
|
+
*/
|
|
103
|
+
const payload = {
|
|
104
|
+
reference: "my-paylink-1",
|
|
105
|
+
concept: "Bicycle",
|
|
106
|
+
favorite: "true",
|
|
107
|
+
amount: 3000,
|
|
108
|
+
currency: "EUR",
|
|
109
|
+
description: "Two wheels",
|
|
110
|
+
singleUse: "true",
|
|
111
|
+
reasonId: 4,
|
|
112
|
+
expirationDays: 1,
|
|
113
|
+
lang: "es",
|
|
114
|
+
urlSuccess: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
|
|
115
|
+
urlFailed: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
|
|
116
|
+
urlNotification: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
|
|
117
|
+
serviceDate: "2021-08-20",
|
|
118
|
+
client: {
|
|
119
|
+
name: "John",
|
|
120
|
+
lastName: "McClane",
|
|
121
|
+
address: "Ave. Guadí 232, Barcelona, Barcelona",
|
|
122
|
+
phone: "+34645553333",
|
|
123
|
+
email: "client@email.com",
|
|
124
|
+
countryId: 1,
|
|
125
|
+
termsAndConditions: "true",
|
|
126
|
+
},
|
|
127
|
+
directPayment: "true",
|
|
128
|
+
};
|
|
129
|
+
// Use inside an async function
|
|
130
|
+
const paylink = await tpp.paymentCards.create(payload);
|
|
131
|
+
console.log(paylink.shortUrl);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
For more examples, please refer to the [Documentation](https://github.com/yosle/tropipayjs/blob/master/docs/)
|
|
135
|
+
|
|
136
|
+
# Contributing
|
|
137
|
+
|
|
138
|
+
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
|
|
139
|
+
|
|
140
|
+
1. Fork the Project
|
|
141
|
+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
|
142
|
+
3. Commit your Changes (`git commit -m 'Add some AmazingFeature`)
|
|
143
|
+
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
|
144
|
+
5. Open a Pull Request
|
|
145
|
+
|
|
146
|
+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
147
|
+
|
|
148
|
+
You can also make a small [donation to the author](https://tppay.me/l94qaa3h) of the library.
|
|
149
|
+
|
|
150
|
+
# License
|
|
151
|
+
|
|
152
|
+
Distributed under the MIT License. See `LICENSE.txt` for more information.
|
package/api/TropipayAPI.d.ts
CHANGED
package/docs/readme.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# TropipayJs Documentation
|
|
2
|
-
|
|
3
|
-
[Open to the Documentation](https://yosle.github.io/tropipayjs-docs/)
|
|
1
|
+
# TropipayJs Documentation
|
|
2
|
+
|
|
3
|
+
[Open to the Documentation](https://yosle.github.io/tropipayjs-docs/)
|
package/globals.d.ts
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
type LoginResponse = {
|
|
2
|
-
access_token: string,
|
|
3
|
-
refresh_token: string
|
|
4
|
-
token_type: "Bearer",
|
|
5
|
-
expires_in: number,
|
|
6
|
-
scope: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
type LoginError = {
|
|
10
|
-
error: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type Country = {
|
|
14
|
-
id: number,
|
|
15
|
-
name: string,
|
|
16
|
-
sepaZone: boolean,
|
|
17
|
-
state: number,
|
|
18
|
-
slug: string,
|
|
19
|
-
slugn: number,
|
|
20
|
-
callingCode: number,
|
|
21
|
-
isDestination: boolean,
|
|
22
|
-
isRisky: boolean,
|
|
23
|
-
currentCurrency: string | null,
|
|
24
|
-
createdAt: string,
|
|
25
|
-
updatedAt: string,
|
|
26
|
-
isFavorite: boolean,
|
|
27
|
-
position: any
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type Deposit = {
|
|
32
|
-
id: number,
|
|
33
|
-
accountNumber: string,
|
|
34
|
-
alias: string,
|
|
35
|
-
swift: string,
|
|
36
|
-
type: number,
|
|
37
|
-
country: number | null,
|
|
38
|
-
firstName: string,
|
|
39
|
-
default: null,
|
|
40
|
-
state: number,
|
|
41
|
-
userId: string,
|
|
42
|
-
countryDestinationId: number,
|
|
43
|
-
lastName: string,
|
|
44
|
-
documentNumber: number,
|
|
45
|
-
userRelationTypeId: number,
|
|
46
|
-
city: string,
|
|
47
|
-
postalCode: string,
|
|
48
|
-
address: string,
|
|
49
|
-
phone: string,
|
|
50
|
-
checked: boolean,
|
|
51
|
-
province: string,
|
|
52
|
-
beneficiaryType: number,
|
|
53
|
-
relatedUserId: null | string,
|
|
54
|
-
currency: string,
|
|
55
|
-
correspondent?: any,
|
|
56
|
-
location: any,
|
|
57
|
-
office: any,
|
|
58
|
-
officeValue: any,
|
|
59
|
-
paymentType: number,
|
|
60
|
-
paymentEntityBeneficiaryId: number,
|
|
61
|
-
paymentEntityAccountId: number,
|
|
62
|
-
verified: any,
|
|
63
|
-
paymentEntityInfo: any,
|
|
64
|
-
documentTypeId: any,
|
|
65
|
-
documentExpirationDate: Date,
|
|
66
|
-
createdAt: Date<string>,
|
|
67
|
-
updatedAt: Date<string>,
|
|
68
|
-
countryDestination: Country
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
type AccountDeposits = {
|
|
72
|
-
count: number,
|
|
73
|
-
rows: Deposit[]
|
|
74
|
-
}
|
|
75
|
-
|
|
1
|
+
type LoginResponse = {
|
|
2
|
+
access_token: string,
|
|
3
|
+
refresh_token: string
|
|
4
|
+
token_type: "Bearer",
|
|
5
|
+
expires_in: number,
|
|
6
|
+
scope: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type LoginError = {
|
|
10
|
+
error: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type Country = {
|
|
14
|
+
id: number,
|
|
15
|
+
name: string,
|
|
16
|
+
sepaZone: boolean,
|
|
17
|
+
state: number,
|
|
18
|
+
slug: string,
|
|
19
|
+
slugn: number,
|
|
20
|
+
callingCode: number,
|
|
21
|
+
isDestination: boolean,
|
|
22
|
+
isRisky: boolean,
|
|
23
|
+
currentCurrency: string | null,
|
|
24
|
+
createdAt: string,
|
|
25
|
+
updatedAt: string,
|
|
26
|
+
isFavorite: boolean,
|
|
27
|
+
position: any
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type Deposit = {
|
|
32
|
+
id: number,
|
|
33
|
+
accountNumber: string,
|
|
34
|
+
alias: string,
|
|
35
|
+
swift: string,
|
|
36
|
+
type: number,
|
|
37
|
+
country: number | null,
|
|
38
|
+
firstName: string,
|
|
39
|
+
default: null,
|
|
40
|
+
state: number,
|
|
41
|
+
userId: string,
|
|
42
|
+
countryDestinationId: number,
|
|
43
|
+
lastName: string,
|
|
44
|
+
documentNumber: number,
|
|
45
|
+
userRelationTypeId: number,
|
|
46
|
+
city: string,
|
|
47
|
+
postalCode: string,
|
|
48
|
+
address: string,
|
|
49
|
+
phone: string,
|
|
50
|
+
checked: boolean,
|
|
51
|
+
province: string,
|
|
52
|
+
beneficiaryType: number,
|
|
53
|
+
relatedUserId: null | string,
|
|
54
|
+
currency: string,
|
|
55
|
+
correspondent?: any,
|
|
56
|
+
location: any,
|
|
57
|
+
office: any,
|
|
58
|
+
officeValue: any,
|
|
59
|
+
paymentType: number,
|
|
60
|
+
paymentEntityBeneficiaryId: number,
|
|
61
|
+
paymentEntityAccountId: number,
|
|
62
|
+
verified: any,
|
|
63
|
+
paymentEntityInfo: any,
|
|
64
|
+
documentTypeId: any,
|
|
65
|
+
documentExpirationDate: Date,
|
|
66
|
+
createdAt: Date<string>,
|
|
67
|
+
updatedAt: Date<string>,
|
|
68
|
+
countryDestination: Country
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type AccountDeposits = {
|
|
72
|
+
count: number,
|
|
73
|
+
rows: Deposit[]
|
|
74
|
+
}
|
|
75
|
+
|
package/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ interface TropipayConfig {
|
|
|
13
13
|
clientSecret: string;
|
|
14
14
|
scopes?: string[];
|
|
15
15
|
serverMode?: ServerMode$1;
|
|
16
|
+
customTropipayUrl?: string;
|
|
16
17
|
}
|
|
17
18
|
type TropipayCredentials = {
|
|
18
19
|
clientId: string;
|
|
@@ -53,14 +54,16 @@ interface PaymentLinkPayload {
|
|
|
53
54
|
urlFailed: string;
|
|
54
55
|
urlNotification: string;
|
|
55
56
|
serviceDate: string;
|
|
56
|
-
client
|
|
57
|
-
name
|
|
58
|
-
lastName
|
|
59
|
-
address
|
|
60
|
-
phone
|
|
61
|
-
email
|
|
57
|
+
client?: {
|
|
58
|
+
name?: string;
|
|
59
|
+
lastName?: string;
|
|
60
|
+
address?: string;
|
|
61
|
+
phone?: string;
|
|
62
|
+
email?: string;
|
|
62
63
|
countryId?: number;
|
|
63
64
|
countryIso?: string;
|
|
65
|
+
city: string;
|
|
66
|
+
postCode: string;
|
|
64
67
|
termsAndConditions: boolean;
|
|
65
68
|
} | null;
|
|
66
69
|
directPayment: boolean;
|
|
@@ -332,6 +335,7 @@ declare class Tropipay {
|
|
|
332
335
|
request: Axios;
|
|
333
336
|
static accessToken: string | null;
|
|
334
337
|
static refreshToken: string | null;
|
|
338
|
+
static expiresIn: number | null;
|
|
335
339
|
serverMode: ServerMode;
|
|
336
340
|
hooks: TropipayHooks;
|
|
337
341
|
paymentCards: PaymentCard;
|
package/index.js
CHANGED
|
@@ -481,6 +481,7 @@ class Tropipay {
|
|
|
481
481
|
request;
|
|
482
482
|
static accessToken;
|
|
483
483
|
static refreshToken;
|
|
484
|
+
static expiresIn;
|
|
484
485
|
serverMode;
|
|
485
486
|
hooks;
|
|
486
487
|
paymentCards;
|
|
@@ -515,16 +516,36 @@ class Tropipay {
|
|
|
515
516
|
this.clientId = config.clientId;
|
|
516
517
|
this.clientSecret = config.clientSecret;
|
|
517
518
|
this.serverMode = config.serverMode || "Development";
|
|
519
|
+
const tpp_env = this.serverMode === "Production"
|
|
520
|
+
? "https://www.tropipay.com"
|
|
521
|
+
: "https://tropipay-dev.herokuapp.com";
|
|
518
522
|
this.request = axios__default["default"].create({
|
|
519
|
-
baseURL:
|
|
520
|
-
? "https://www.tropipay.com"
|
|
521
|
-
: "https://tropipay-dev.herokuapp.com",
|
|
523
|
+
baseURL: config.customTropipayUrl || tpp_env,
|
|
522
524
|
headers: {
|
|
523
525
|
"Content-Type": "application/json",
|
|
524
526
|
Accept: "application/json",
|
|
525
527
|
Authorization: `Bearer ${Tropipay.accessToken}`,
|
|
526
528
|
},
|
|
527
529
|
});
|
|
530
|
+
// Add request interceptor for Token expired
|
|
531
|
+
this.request.interceptors.request.use(async (config) => {
|
|
532
|
+
const currentTimestamp = Math.floor(Date.now() / 1000); // Current time in seconds
|
|
533
|
+
if (Tropipay.expiresIn && Tropipay.expiresIn < currentTimestamp) {
|
|
534
|
+
// Token has expired, attempt to refresh it
|
|
535
|
+
try {
|
|
536
|
+
await this.login();
|
|
537
|
+
}
|
|
538
|
+
catch (error) {
|
|
539
|
+
// Handle token refresh error
|
|
540
|
+
Tropipay.accessToken = null;
|
|
541
|
+
Tropipay.refreshToken = null;
|
|
542
|
+
throw handleExceptions(error);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return config;
|
|
546
|
+
}, (error) => {
|
|
547
|
+
return Promise.reject(error);
|
|
548
|
+
});
|
|
528
549
|
this.hooks = new TropipayHooks(this);
|
|
529
550
|
this.paymentCards = new PaymentCard(this);
|
|
530
551
|
this.mediationPaymentCard = new MediationPaymentCard(this);
|
|
@@ -560,11 +581,13 @@ class Tropipay {
|
|
|
560
581
|
});
|
|
561
582
|
Tropipay.accessToken = data.access_token;
|
|
562
583
|
Tropipay.refreshToken = data.refresh_token;
|
|
584
|
+
Tropipay.expiresIn = data.expires_in;
|
|
563
585
|
return data;
|
|
564
586
|
}
|
|
565
587
|
catch (error) {
|
|
566
588
|
Tropipay.accessToken = null;
|
|
567
589
|
Tropipay.refreshToken = null;
|
|
590
|
+
Tropipay.expiresIn = null;
|
|
568
591
|
throw handleExceptions(error);
|
|
569
592
|
}
|
|
570
593
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type TropipayCountry = {};
|
|
1
|
+
export type TropipayCountry = {};
|