@yosle/tropipayjs
Advanced tools
Comparing version 0.1.8 to 0.1.9
@@ -14,16 +14,16 @@ type LoginResponse = { | ||
type Country = { | ||
id: number, | ||
name: string, | ||
sepaZone: boolean, | ||
state: number, | ||
slug: string, | ||
slugn: number, | ||
callingCode: number, | ||
isDestination: boolean, | ||
isRisky: boolean, | ||
currentCurrency: string | null, | ||
createdAt: string, | ||
updatedAt: string, | ||
isFavorite: boolean, | ||
position: any | ||
id: number, | ||
name: string, | ||
sepaZone: boolean, | ||
state: number, | ||
slug: string, | ||
slugn: number, | ||
callingCode: number, | ||
isDestination: boolean, | ||
isRisky: boolean, | ||
currentCurrency: string | null, | ||
createdAt: string, | ||
updatedAt: string, | ||
isFavorite: boolean, | ||
position: any | ||
@@ -73,4 +73,5 @@ } | ||
type AccountDeposits = { | ||
count: number, | ||
rows: Deposit[] | ||
} | ||
count: number, | ||
rows: Deposit[] | ||
} | ||
@@ -76,2 +76,7 @@ import { Axios } from 'axios'; | ||
} | ||
type AccountBalance = { | ||
balance: number; | ||
pendingIn: number; | ||
pendingOut: number; | ||
}; | ||
declare class Tropipay { | ||
@@ -106,2 +111,7 @@ protected clientId: string; | ||
/** | ||
* Get user balance | ||
* @returns balance object | ||
*/ | ||
getBalance(): Promise<AccountBalance>; | ||
/** | ||
* Get the list of all detination countries supported by Tropipay. | ||
@@ -108,0 +118,0 @@ * Obtaining the list of valid countries to send funds to. Useful |
23
index.js
@@ -125,2 +125,25 @@ 'use strict'; | ||
/** | ||
* Get user balance | ||
* @returns balance object | ||
*/ | ||
async getBalance() { | ||
if (!Tropipay.accessToken) { | ||
await this.login(); | ||
} | ||
try { | ||
const balance = await this.request.get('/api/v2/users/balance', { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${Tropipay.accessToken}`, | ||
Accept: 'application/json' | ||
} | ||
}); | ||
return balance.data; | ||
} | ||
catch (error) { | ||
console.log("el error es ", error); | ||
throw new Error(`TropipayJS Error - Could not retrieve the user's balance`); | ||
} | ||
} | ||
/** | ||
* Get the list of all detination countries supported by Tropipay. | ||
@@ -127,0 +150,0 @@ * Obtaining the list of valid countries to send funds to. Useful |
{ | ||
"name": "@yosle/tropipayjs", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Javascript / Typescript SDK for the Tropipay API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -63,5 +63,9 @@ TropipayJS - Typescript/Javascript SDK for Tropipay Payments API | ||
```javascript | ||
// test environment server | ||
const tpp = new Tropipay("yourclientidhere", | ||
"yourclientsecrethere") | ||
// test environment server tropipay-dev.herokuapp.com | ||
const config = { | ||
clientId: process.env.TROPIPAY_CLIENT_ID, | ||
clientSecret: process.env.TROPIPAY_CLIENT_SECRET | ||
serverMode: 'Development' // it will be used as default if omited | ||
} | ||
const tpp = new Tropipay(config) | ||
``` | ||
@@ -73,4 +77,8 @@ | ||
//real account credentials | ||
const tpp = new Tropipay("yourclientidhere", | ||
"yourclientsecrethere",'Production') | ||
const config = { | ||
clientId: process.env.TROPIPAY_CLIENT_ID, | ||
clientSecret: process.env.TROPIPAY_CLIENT_SECRET, | ||
serverMode: 'Production' //live account | ||
} | ||
const tpp = new Tropipay(config) | ||
``` | ||
@@ -82,3 +90,3 @@ ### Generating a Payment Link | ||
*/ | ||
const payload = await tpp.createPayLink({ | ||
const payload = { | ||
reference: "my-paylink-1", | ||
@@ -108,7 +116,6 @@ concept: "Bicycle", | ||
directPayment: "true" | ||
}) | ||
} | ||
// Use inside an async function | ||
const paylink = await tpp.createPayLink(payload) | ||
console.log(paylink.shortUrl) | ||
const paylink = await tpp.createPaymentCard(payload); | ||
console.log(paylink.shortUrl); | ||
``` | ||
@@ -115,0 +122,0 @@ |
@@ -20,2 +20,8 @@ /** | ||
type AccountBalance = { | ||
balance: number, | ||
pendingIn: number, | ||
pendingOut: number | ||
} | ||
export class Tropipay { | ||
@@ -132,2 +138,23 @@ protected clientId: string; | ||
} | ||
/** | ||
* Get user balance | ||
* @returns balance Object { balance: number, pendingIn: number, pendingOut: number } | ||
*/ | ||
async getBalance(): Promise<AccountBalance> { | ||
if (!Tropipay.accessToken) { | ||
await this.login() | ||
} | ||
try { | ||
const balance = await this.request.get('/api/v2/users/balance', { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${Tropipay.accessToken}`, | ||
Accept: 'application/json' | ||
} | ||
}); | ||
return balance.data | ||
} catch (error) { | ||
throw new Error(`TropipayJS Error - Could not retrieve the user's balance`); | ||
} | ||
} | ||
@@ -134,0 +161,0 @@ /** |
207362
1114
139