@yosle/tropipayjs 0.1.6 → 0.1.8

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/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,115 +1,131 @@
1
- TropipayJS - Typescript/Javascript SDK for Tropipay Payments API
2
- ===========
3
- ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge&logo=node.js&logoColor=white)
4
- ![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)
5
- ![JavaScript](https://img.shields.io/badge/javascript-%23323330.svg?style=for-the-badge&logo=javascript&logoColor=%23F7DF1E)
6
- ![Next JS](https://img.shields.io/badge/Next-black?style=for-the-badge&logo=next.js&logoColor=white)
7
- ![RollupJS](https://img.shields.io/badge/RollupJS-ef3335?style=for-the-badge&logo=rollup.js&logoColor=white)
8
-
9
- 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).
10
-
11
-
12
- # Table of Contents
13
- - [TropipayJS - Typescript/Javascript SDK for Tropipay Payments API](#tropipayjs---typescriptjavascript-sdk-for-tropipay-payments-api)
14
- - [Table of Contents](#table-of-contents)
15
- - [About the project](#about-the-project)
16
- - [Getting started](#getting-started)
17
- - [Setting up your app credentials](#setting-up-your-app-credentials)
18
- - [Usage](#usage)
19
- - [CommonJS](#commonjs)
20
- - [ES6](#es6)
21
- - [Initialize the Tropipay class](#initialize-the-tropipay-class)
22
- - [Generating a Payment Link](#generating-a-payment-link)
23
- - [Contributing](#contributing)
24
- - [License](#license)
25
- ## About the project
26
- This library is a community effort still under development so use caution if you're planing to use it in production. Tropipay may make some changes on the API Specification in the future. Use the [test environment](https://tropipay-dev.herokuapp.com) to make sure everything is working as expected.
27
- # Getting started
28
- You can use npm or yarn to install this package:
29
-
30
- ```npm install @yosle/tropipayjs```
31
-
32
- or
33
-
34
- ```yarn add @yosle/tropipayjs```
35
-
36
- ## Setting up your app credentials
37
-
38
- ![alt]([/docs/images/app-credentials-menu.png](https://github.com/yosle/tropipayjs/blob/master/docs/images/app-credentials-menu.png))
39
- ![alt]([/docs/images/confirmation-code-screen.png](https://github.com/yosle/tropipayjs/blob/master/docs/images/confirmation-code-screen.png))
40
-
41
- 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 enviroment](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.
42
-
43
- ## Usage
44
- 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.
45
-
46
- ### CommonJS
47
- ```javascript
48
- const { Tropipay } = require('@yosle/tropipayjs')
49
- ```
50
- ### ES6
51
- ```javascript
52
- import { Tropipay } from '@yosle/tropipayjs'
53
- ```
54
- ### Initialize the Tropipay class
55
- ```javascript
56
- const tpp = new Tropipay("yourclientidhere",
57
- "yourclientsecrethere")
58
- ```
59
- ### Generating a Payment Link
60
- ```javascript
61
- /*
62
- * Example Payload
63
- */
64
- const payload = await tpp.createPayLink({
65
- reference: "my-paylink-1",
66
- concept: "Bicycle",
67
- favorite: "true",
68
- amount: 3000,
69
- currency: "EUR",
70
- description: "Two wheels",
71
- singleUse: "true",
72
- reasonId: 4,
73
- expirationDays: 1,
74
- lang: "es",
75
- urlSuccess: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
76
- urlFailed: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
77
- urlNotification: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
78
- serviceDate: "2021-08-20",
79
- client: {
80
- name: "John",
81
- lastName: "McClane",
82
- address: "Ave. Guadí 232, Barcelona, Barcelona",
83
- phone: "+34645553333",
84
- email: "client@email.com",
85
- countryId: 1,
86
- termsAndConditions: "true"
87
- },
88
- directPayment: "true"
89
- })
90
-
91
- // Use inside an async function
92
- const paylink = await tpp.createPayLink(payload)
93
- console.log(paylink.shortUrl)
94
- ```
95
-
96
- For more examples, please refer to the [Documentation](https://github.com/yosle/tropipayjs/blob/master/docs/)
97
-
98
- # Contributing
99
- 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!
100
-
101
- 1. Fork the Project
102
- 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
103
- 3. Commit your Changes (`git commit -m 'Add some AmazingFeature`)
104
- 4. Push to the Branch (`git push origin feature/AmazingFeature`)
105
- 5. Open a Pull Request
106
-
107
- Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
108
-
109
- You can also make a small [donation to the author](https://tppay.me/l94qaa3h) of the library.
110
- # License
111
- Distributed under the MIT License. See `LICENSE.txt` for more information.
112
-
113
-
114
-
115
-
1
+ TropipayJS - Typescript/Javascript SDK for Tropipay Payments API
2
+ ===========
3
+ ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge&logo=node.js&logoColor=white)
4
+ ![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white)
5
+ ![JavaScript](https://img.shields.io/badge/javascript-%23323330.svg?style=for-the-badge&logo=javascript&logoColor=%23F7DF1E)
6
+ ![Next JS](https://img.shields.io/badge/Next-black?style=for-the-badge&logo=next.js&logoColor=white)
7
+ ![RollupJS](https://img.shields.io/badge/RollupJS-ef3335?style=for-the-badge&logo=rollup.js&logoColor=white)
8
+
9
+ 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).
10
+
11
+
12
+ # Table of Contents
13
+ - [TropipayJS - Typescript/Javascript SDK for Tropipay Payments API](#tropipayjs---typescriptjavascript-sdk-for-tropipay-payments-api)
14
+ - [Table of Contents](#table-of-contents)
15
+ - [About the project](#about-the-project)
16
+ - [Getting started](#getting-started)
17
+ - [Setting up your app credentials](#setting-up-your-app-credentials)
18
+ - [Usage](#usage)
19
+ - [CommonJS](#commonjs)
20
+ - [ES6](#es6)
21
+ - [Initialize the Tropipay class](#initialize-the-tropipay-class)
22
+ - [Generating a Payment Link](#generating-a-payment-link)
23
+ - [Contributing](#contributing)
24
+ - [License](#license)
25
+
26
+ ## About the project
27
+ 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.
28
+
29
+ **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.
30
+
31
+ 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.
32
+ # Getting started
33
+ You can use npm or yarn to install this package:
34
+
35
+ ```npm install @yosle/tropipayjs```
36
+
37
+ or
38
+
39
+ ```yarn add @yosle/tropipayjs```
40
+
41
+ ## Setting up your app credentials
42
+
43
+ ![alt](https://github.com/yosle/tropipayjs/blob/master/docs/images/app-credentials-menu.png?raw=true)
44
+ ![alt](https://github.com/yosle/tropipayjs/blob/master/docs/images/confirmation-code-screen.png?raw=true)
45
+
46
+ 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.
47
+
48
+ ## Usage
49
+ 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.
50
+
51
+ ### CommonJS
52
+ ```javascript
53
+ const { Tropipay } = require('@yosle/tropipayjs')
54
+ ```
55
+ ### ES6
56
+ ```javascript
57
+ import { Tropipay } from '@yosle/tropipayjs'
58
+ ```
59
+ ### Initialize the Tropipay class
60
+ 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`.
61
+
62
+ ```javascript
63
+ // test environment server
64
+ const tpp = new Tropipay("yourclientidhere",
65
+ "yourclientsecrethere")
66
+ ```
67
+
68
+ To use your live credentials (real account) you must explicity set serverMode to `Production`.
69
+
70
+ ```javascript
71
+ //real account credentials
72
+ const tpp = new Tropipay("yourclientidhere",
73
+ "yourclientsecrethere",'Production')
74
+ ```
75
+ ### Generating a Payment Link
76
+ ```javascript
77
+ /*
78
+ * Example Payload
79
+ */
80
+ const payload = await tpp.createPayLink({
81
+ reference: "my-paylink-1",
82
+ concept: "Bicycle",
83
+ favorite: "true",
84
+ amount: 3000,
85
+ currency: "EUR",
86
+ description: "Two wheels",
87
+ singleUse: "true",
88
+ reasonId: 4,
89
+ expirationDays: 1,
90
+ lang: "es",
91
+ urlSuccess: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
92
+ urlFailed: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
93
+ urlNotification: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
94
+ serviceDate: "2021-08-20",
95
+ client: {
96
+ name: "John",
97
+ lastName: "McClane",
98
+ address: "Ave. Guadí 232, Barcelona, Barcelona",
99
+ phone: "+34645553333",
100
+ email: "client@email.com",
101
+ countryId: 1,
102
+ termsAndConditions: "true"
103
+ },
104
+ directPayment: "true"
105
+ })
106
+
107
+ // Use inside an async function
108
+ const paylink = await tpp.createPayLink(payload)
109
+ console.log(paylink.shortUrl)
110
+ ```
111
+
112
+ For more examples, please refer to the [Documentation](https://github.com/yosle/tropipayjs/blob/master/docs/)
113
+
114
+ # Contributing
115
+ 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!
116
+
117
+ 1. Fork the Project
118
+ 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
119
+ 3. Commit your Changes (`git commit -m 'Add some AmazingFeature`)
120
+ 4. Push to the Branch (`git push origin feature/AmazingFeature`)
121
+ 5. Open a Pull Request
122
+
123
+ Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
124
+
125
+ You can also make a small [donation to the author](https://tppay.me/l94qaa3h) of the library.
126
+ # License
127
+ Distributed under the MIT License. See `LICENSE.txt` for more information.
128
+
129
+
130
+
131
+
package/docs/index.MD ADDED
@@ -0,0 +1,19 @@
1
+ # Tropipayjs
2
+
3
+ Tropipayjs is a TypeScript/JavaScript library for the Tropipay API.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Usage](#usage)
9
+ - [API Reference](#api-reference)
10
+ - [Contributing](#contributing)
11
+ - [License](#license)
12
+
13
+ ## Installation
14
+
15
+ To use Tropipayjs in your project, you need to install it via npm. Run the following command:
16
+
17
+ ```npm install tropipayjs```
18
+ or
19
+ ```yarn add tropipayjs```
package/globals.d.ts CHANGED
@@ -1,74 +1,74 @@
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[]
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
74
  }
package/index.d.ts CHANGED
@@ -37,6 +37,29 @@ interface PaymentLink extends PaymentLinkPayload {
37
37
  paymentUrl: string;
38
38
  }
39
39
 
40
+ /**
41
+ *
42
+ */
43
+ interface mediationPaymentCardConfig {
44
+ amount: number;
45
+ currency: "EUR" | "USD";
46
+ concept: string;
47
+ description: string;
48
+ reference: string;
49
+ singleUse: boolean;
50
+ lang: string;
51
+ productUrl?: string;
52
+ buyer: null | any;
53
+ seller: {
54
+ sellerId?: number;
55
+ type?: number;
56
+ email?: string;
57
+ };
58
+ feePercent?: number;
59
+ feeFixed?: number;
60
+ sendMail: boolean;
61
+ }
62
+
40
63
  /**
41
64
  * Tropipayjs is a Typescript/Javascript library for the Tropipay API.
42
65
  *
@@ -44,15 +67,20 @@ interface PaymentLink extends PaymentLinkPayload {
44
67
  *
45
68
  */
46
69
 
47
- declare type ServerMode = 'Development' | 'Production';
70
+ type ServerMode = 'Development' | 'Production';
71
+ interface TropipayConfig {
72
+ clientId: string;
73
+ clientSecret: string;
74
+ serverMode?: ServerMode;
75
+ }
48
76
  declare class Tropipay {
49
- readonly clientId: string;
50
- readonly clientSecret: string;
77
+ protected clientId: string;
78
+ protected clientSecret: string;
51
79
  protected request: Axios;
52
- protected accessToken: string | undefined;
53
- protected refreshToken: string | undefined;
80
+ protected static accessToken: string | undefined;
81
+ protected static refreshToken: string | undefined;
54
82
  protected serverMode: ServerMode;
55
- constructor(client_id: string, client_secret: string, server_mode?: ServerMode);
83
+ constructor(config: TropipayConfig);
56
84
  login(): Promise<LoginResponse>;
57
85
  /**
58
86
  * Create a paymentLink with the specified options.
@@ -60,7 +88,7 @@ declare class Tropipay {
60
88
  * @returns Promise<PaymentLink> or throws an Exception.
61
89
  * @see https://tpp.stoplight.io/docs/tropipay-api-doc/b3A6ODgyNTM3OQ-create-a-new-pay-link-charge
62
90
  */
63
- createPayLink(payload: PaymentLinkPayload): Promise<PaymentLink>;
91
+ createPaymentCard(payload: PaymentLinkPayload): Promise<PaymentLink>;
64
92
  /**
65
93
  * Get all deposits in this account.
66
94
  * @returns A Promise of an Array of AccountDeposits or throws an Exception
@@ -83,9 +111,8 @@ declare class Tropipay {
83
111
  */
84
112
  destinations(): Promise<Country[]>;
85
113
  /**
86
- * Get list of all the favorites accounts. This endpoint is not documented
87
- * in the official Tropipay documentation.
88
- * @returns
114
+ * Get list of all the favorites payment links.
115
+ * @returns Array of account Object or throws an error
89
116
  */
90
117
  favorites(): Promise<any>;
91
118
  /**
@@ -99,9 +126,25 @@ declare class Tropipay {
99
126
  * @returns
100
127
  */
101
128
  profile(): Promise<any>;
102
- rates(payload?: {
103
- currencyFrom: string;
104
- }): Promise<any>;
129
+ /**
130
+ * Obtain current Tropipay conversion rate. For example USD to EUR
131
+ * targetCurrency must be 'EUR'
132
+ * @param originCurrency Target currency code supported by Tropipay.
133
+ * @param targetCurrency Must be 'EUR'? (not documented by Tropipay)
134
+ * @returns Conversion rate (number)
135
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/85163f6f28b23-get-rate
136
+ */
137
+ rates(originCurrency: string, targetCurrency?: string): Promise<number | Error>;
138
+ /**
139
+ * (ONLY in Bussiness Accounts)
140
+ * An escrow payment link. This allows a payment to be made to persons
141
+ * belonging or not to the TropiPay platform with the particularity
142
+ * that the payment will be held in custody or retained until it is
143
+ * released with the approval of the payer.
144
+ * @see https://tpp.stoplight.io/docs/tropipay-api-doc/12a128ff971e4-creating-a-mediation-payment-card
145
+ * @param config Payload with the payment details
146
+ */
147
+ createMediationPaymentCard(config: mediationPaymentCardConfig): Promise<PaymentLink>;
105
148
  }
106
149
 
107
150
  export { Tropipay };