@yosle/tropipayjs
Advanced tools
Comparing version 0.1.14 to 0.1.15
@@ -12,2 +12,3 @@ /** | ||
import { PaymentCard } from "../paymentcard/PaymentCard"; | ||
import { DepositAccounts } from "../depositAccount/depositAccounts"; | ||
export declare class Tropipay { | ||
@@ -21,3 +22,4 @@ readonly clientId: string; | ||
hooks: TropipayHooks; | ||
paymentcards: PaymentCard; | ||
paymentCards: PaymentCard; | ||
depositAccounts: DepositAccounts; | ||
constructor(config: TropipayConfig); | ||
@@ -24,0 +26,0 @@ login(): Promise<LoginResponse>; |
@@ -220,2 +220,64 @@ import { Axios } from 'axios'; | ||
interface DepositAccountConfig { | ||
searchValue?: string; | ||
alias: string; | ||
userRelationTypeId: number; | ||
beneficiaryType: BeneficiaryType; | ||
searchBy?: number; | ||
accountNumber?: string; | ||
swift?: string; | ||
type?: number; | ||
firstName?: string; | ||
lastName?: string; | ||
secondLastName?: string; | ||
countryDestinationId?: number; | ||
city?: string; | ||
postalCode?: number; | ||
address?: string; | ||
documentNumber?: string; | ||
phone?: string; | ||
province?: string; | ||
paymentType?: string; | ||
documentTypeId?: number; | ||
documentExpirationDate: string; | ||
} | ||
type INTERNAL = 1; | ||
type EXTERNAL = 2; | ||
type BeneficiaryType = INTERNAL | EXTERNAL; | ||
declare class DepositAccounts { | ||
private tropipay; | ||
constructor(tropipayInstance: Tropipay); | ||
/** | ||
* List od all beneficiaries of this account | ||
* @returns Array of DepositAccounts | ||
*/ | ||
list(): Promise<any>; | ||
/** | ||
* Adds a new beneficiary to the user account. | ||
* @param payload | ||
* @returns | ||
*/ | ||
create(depositAccountObj: DepositAccountConfig): Promise<any>; | ||
/** | ||
* This returns details of a specific | ||
* Deposit Account (beneficiary) specified by its ID | ||
* @param id | ||
* @returns | ||
*/ | ||
get(id: string): Promise<any>; | ||
/** | ||
* Updates certain beneficiary data. | ||
* @param depositAccountObj | ||
* @returns | ||
*/ | ||
update(depositAccountObj: Partial<DepositAccountConfig>): Promise<any>; | ||
/** | ||
* (UNTESTED) Deletes the beneficiary indicated by id | ||
* @param id | ||
* @returns | ||
*/ | ||
delete(id: number): Promise<any>; | ||
} | ||
/** | ||
@@ -238,3 +300,4 @@ * Tropipayjs is a Typescript/Javascript library for the Tropipay API. | ||
hooks: TropipayHooks; | ||
paymentcards: PaymentCard; | ||
paymentCards: PaymentCard; | ||
depositAccounts: DepositAccounts; | ||
constructor(config: TropipayConfig); | ||
@@ -327,2 +390,2 @@ login(): Promise<LoginResponse>; | ||
export { AccountBalance, AccountDeposits, ClientSideUtils, Country, Deposit, HookEventType, HookTargetType, LoginError, LoginResponse, PaymentCard, PaymentLink, PaymentLinkPayload, SERVER_MODE, ServerMode$1 as ServerMode, ServerSideUtils, Tropipay, TropipayConfig, TropipayCredentials, TropipayHooks, UserHook, UserHookSubscribed, mediationPaymentCardConfig }; | ||
export { AccountBalance, AccountDeposits, ClientSideUtils, Country, Deposit, DepositAccounts, HookEventType, HookTargetType, LoginError, LoginResponse, PaymentCard, PaymentLink, PaymentLinkPayload, SERVER_MODE, ServerMode$1 as ServerMode, ServerSideUtils, Tropipay, TropipayConfig, TropipayCredentials, TropipayHooks, UserHook, UserHookSubscribed, mediationPaymentCardConfig }; |
129
index.js
@@ -233,2 +233,124 @@ 'use strict'; | ||
class DepositAccounts { | ||
tropipay; | ||
constructor(tropipayInstance) { | ||
this.tropipay = tropipayInstance; | ||
} | ||
/** | ||
* List od all beneficiaries of this account | ||
* @returns Array of DepositAccounts | ||
*/ | ||
async list() { | ||
if (!Tropipay.accessToken) { | ||
await this.tropipay.login(); | ||
} | ||
try { | ||
const deposit = await this.tropipay.request.get(`/api/v2/deposit_accounts`, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${Tropipay.accessToken}`, | ||
Accept: "application/json", | ||
}, | ||
}); | ||
return deposit.data; | ||
} | ||
catch (error) { | ||
throw new Error(`Could not retrieve PaymenCards list`); | ||
} | ||
} | ||
/** | ||
* Adds a new beneficiary to the user account. | ||
* @param payload | ||
* @returns | ||
*/ | ||
async create(depositAccountObj) { | ||
if (!Tropipay.accessToken) { | ||
await this.tropipay.login(); | ||
} | ||
try { | ||
const deposit = await this.tropipay.request.post("/api/v2/deposit_accounts", depositAccountObj, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${Tropipay.accessToken}`, | ||
Accept: "application/json", | ||
}, | ||
}); | ||
return deposit.data; | ||
} | ||
catch (error) { | ||
throw new Error(`TropipayJS - Error creating the Deposit Accounts.`); | ||
} | ||
} | ||
/** | ||
* This returns details of a specific | ||
* Deposit Account (beneficiary) specified by its ID | ||
* @param id | ||
* @returns | ||
*/ | ||
async get(id) { | ||
if (!Tropipay.accessToken) { | ||
await this.tropipay.login(); | ||
} | ||
try { | ||
const deposit = await this.tropipay.request.get(`/api/v2/deposit_accounts/${id}`, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${Tropipay.accessToken}`, | ||
Accept: "application/json", | ||
}, | ||
}); | ||
return deposit.data; | ||
} | ||
catch (error) { | ||
throw new Error(`Could not retrieve deposit account`); | ||
} | ||
} | ||
/** | ||
* Updates certain beneficiary data. | ||
* @param depositAccountObj | ||
* @returns | ||
*/ | ||
async update(depositAccountObj) { | ||
if (!Tropipay.accessToken) { | ||
await this.tropipay.login(); | ||
} | ||
try { | ||
const deposit = await this.tropipay.request.put(`/api/v2/deposit_accounts/`, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${Tropipay.accessToken}`, | ||
Accept: "application/json", | ||
}, | ||
}); | ||
return deposit.data; | ||
} | ||
catch (error) { | ||
throw new Error(`Could not retrieve deposit account`); | ||
} | ||
} | ||
/** | ||
* (UNTESTED) Deletes the beneficiary indicated by id | ||
* @param id | ||
* @returns | ||
*/ | ||
async delete(id) { | ||
if (!Tropipay.accessToken) { | ||
await this.tropipay.login(); | ||
} | ||
try { | ||
const deposit = await this.tropipay.request.delete(`/api/v2/deposit_accounts/${id}`, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${Tropipay.accessToken}`, | ||
Accept: "application/json", | ||
}, | ||
}); | ||
return deposit.data; | ||
} | ||
catch (error) { | ||
throw new Error(`Could not retrieve deposit account`); | ||
} | ||
} | ||
} | ||
/** | ||
@@ -248,3 +370,4 @@ * Tropipayjs is a Typescript/Javascript library for the Tropipay API. | ||
hooks; | ||
paymentcards; | ||
paymentCards; | ||
depositAccounts; | ||
constructor(config) { | ||
@@ -265,3 +388,4 @@ this.clientId = config.clientId; | ||
this.hooks = new TropipayHooks(this); | ||
this.paymentcards = new PaymentCard(this); | ||
this.paymentCards = new PaymentCard(this); | ||
this.depositAccounts = new DepositAccounts(this); | ||
} | ||
@@ -534,2 +658,3 @@ async login() { | ||
exports.ClientSideUtils = ClientSideUtils; | ||
exports.DepositAccounts = DepositAccounts; | ||
exports.PaymentCard = PaymentCard; | ||
@@ -536,0 +661,0 @@ exports.SERVER_MODE = SERVER_MODE; |
{ | ||
"name": "@yosle/tropipayjs", | ||
"version": "0.1.14", | ||
"version": "0.1.15", | ||
"description": "Javascript / Typescript SDK for the Tropipay API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
100
README.md
@@ -1,6 +0,5 @@ | ||
TropipayJS - Typescript/Javascript SDK for Tropipay Payments API | ||
=========== | ||
# TropipayJS - Typescript/Javascript SDK for Tropipay Payments API | ||
![NodeJS](https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge&logo=node.js&logoColor=white) | ||
![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white) | ||
![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white) | ||
![JavaScript](https://img.shields.io/badge/javascript-%23323330.svg?style=for-the-badge&logo=javascript&logoColor=%23F7DF1E) | ||
@@ -12,3 +11,2 @@ ![Next JS](https://img.shields.io/badge/Next-black?style=for-the-badge&logo=next.js&logoColor=white) | ||
# Table of Contents | ||
@@ -33,3 +31,3 @@ | ||
**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. | ||
**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. | ||
@@ -42,7 +40,7 @@ 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. | ||
```npm install @yosle/tropipayjs``` | ||
`npm install @yosle/tropipayjs` | ||
or | ||
```yarn add @yosle/tropipayjs``` | ||
`yarn add @yosle/tropipayjs` | ||
@@ -58,14 +56,14 @@ ## Setting up your app credentials | ||
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. | ||
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. | ||
### CommonJS | ||
### CommonJS | ||
```javascript | ||
const { Tropipay } = require('@yosle/tropipayjs') | ||
const { Tropipay } = require("@yosle/tropipayjs"); | ||
``` | ||
### ES6 | ||
### ES6 | ||
```javascript | ||
import { Tropipay } from '@yosle/tropipayjs' | ||
import { Tropipay } from "@yosle/tropipayjs"; | ||
``` | ||
@@ -79,3 +77,3 @@ | ||
// test environment server tropipay-dev.herokuapp.com | ||
const config = { | ||
const config = { | ||
clientId: process.env.TROPIPAY_CLIENT_ID, | ||
@@ -92,8 +90,8 @@ clientSecret: process.env.TROPIPAY_CLIENT_SECRET | ||
//real account credentials | ||
const config = { | ||
clientId: process.env.TROPIPAY_CLIENT_ID, | ||
clientSecret: process.env.TROPIPAY_CLIENT_SECRET, | ||
serverMode: 'Production' //live account | ||
} | ||
const tpp = new Tropipay(config) | ||
const config = { | ||
clientId: process.env.TROPIPAY_CLIENT_ID, | ||
clientSecret: process.env.TROPIPAY_CLIENT_SECRET, | ||
serverMode: "Production", //live account | ||
}; | ||
const tpp = new Tropipay(config); | ||
``` | ||
@@ -105,32 +103,32 @@ | ||
/* | ||
* Example Payload | ||
*/ | ||
* Example Payload | ||
*/ | ||
const payload = { | ||
reference: "my-paylink-1", | ||
concept: "Bicycle", | ||
favorite: "true", | ||
amount: 3000, | ||
currency: "EUR", | ||
description: "Two wheels", | ||
singleUse: "true", | ||
reasonId: 4, | ||
expirationDays: 1, | ||
lang: "es", | ||
urlSuccess: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e", | ||
urlFailed: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e", | ||
urlNotification: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e", | ||
serviceDate: "2021-08-20", | ||
client: { | ||
name: "John", | ||
lastName: "McClane", | ||
address: "Ave. Guadí 232, Barcelona, Barcelona", | ||
phone: "+34645553333", | ||
email: "client@email.com", | ||
countryId: 1, | ||
termsAndConditions: "true" | ||
}, | ||
directPayment: "true" | ||
} | ||
reference: "my-paylink-1", | ||
concept: "Bicycle", | ||
favorite: "true", | ||
amount: 3000, | ||
currency: "EUR", | ||
description: "Two wheels", | ||
singleUse: "true", | ||
reasonId: 4, | ||
expirationDays: 1, | ||
lang: "es", | ||
urlSuccess: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e", | ||
urlFailed: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e", | ||
urlNotification: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e", | ||
serviceDate: "2021-08-20", | ||
client: { | ||
name: "John", | ||
lastName: "McClane", | ||
address: "Ave. Guadí 232, Barcelona, Barcelona", | ||
phone: "+34645553333", | ||
email: "client@email.com", | ||
countryId: 1, | ||
termsAndConditions: "true", | ||
}, | ||
directPayment: "true", | ||
}; | ||
// Use inside an async function | ||
const paylink = await tpp.createPaymentCard(payload); | ||
const paylink = await tpp.paymentCards.create(payload); | ||
console.log(paylink.shortUrl); | ||
@@ -150,5 +148,5 @@ ``` | ||
5. Open a Pull Request | ||
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. | ||
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. | ||
You can also make a small [donation to the author](https://tppay.me/l94qaa3h) of the library. | ||
@@ -159,5 +157,1 @@ | ||
Distributed under the MIT License. See `LICENSE.txt` for more information. | ||
@@ -22,2 +22,3 @@ /** | ||
import { PaymentCard } from "../paymentcard/PaymentCard"; | ||
import { DepositAccounts } from "../depositAccount/depositAccounts"; | ||
export class Tropipay { | ||
@@ -31,3 +32,4 @@ readonly clientId: string; | ||
public hooks: TropipayHooks; | ||
public paymentcards: PaymentCard; | ||
public paymentCards: PaymentCard; | ||
public depositAccounts: DepositAccounts; | ||
@@ -50,3 +52,4 @@ constructor(config: TropipayConfig) { | ||
this.hooks = new TropipayHooks(this); | ||
this.paymentcards = new PaymentCard(this); | ||
this.paymentCards = new PaymentCard(this); | ||
this.depositAccounts = new DepositAccounts(this); | ||
} | ||
@@ -53,0 +56,0 @@ |
@@ -13,2 +13,4 @@ /** | ||
import { DepositAccounts } from "./depositAccount/depositAccounts"; | ||
if (typeof window !== "undefined") { | ||
@@ -25,4 +27,5 @@ console.warn( | ||
export { PaymentCard } from "./paymentcard/PaymentCard"; | ||
export { DepositAccounts } from "./depositAccount/depositAccounts"; | ||
export * from "./interfaces/index"; | ||
export { SERVER_MODE } from "./config/TropipayConfig"; | ||
export * from "./constants/TropipayConstants"; |
@@ -6,3 +6,2 @@ import { Tropipay } from "../api/TropipayAPI"; | ||
private tropipay: Tropipay; | ||
constructor(tropipayInstance: Tropipay) { | ||
@@ -9,0 +8,0 @@ this.tropipay = tropipayInstance; |
1682893
130
2795
149