Skip to content

Commit

Permalink
Merge pull request #11 from LazerpayHQ/feature/onramp-api
Browse files Browse the repository at this point in the history
Feature/onramp api
  • Loading branch information
iamnotstatic authored Feb 12, 2023
2 parents 4cdef51 + cb49cff commit 2c25dec
Show file tree
Hide file tree
Showing 13 changed files with 338 additions and 59 deletions.
123 changes: 77 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,25 @@ Use TEST API keys for testing, and LIVE API keys for production
- Get a single payment link
- Update a payment Link

**5**. **Misc**
**5**. **Onramp**
- Get Rate
- Get Accounts
- Initiate

**6**. **Misc**

- Get all accepted coins
- Get all accepted currencies
- Get wallet balance


## Payment

#### `Initialize Payment`

This describes to allow your customers to initiate a crypto payment transfer.

```javascript
const Lazerpay = require('lazerpay-node-sdk');

const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

const payment_tx = async () => {
try {
const transaction_payload = {
Expand All @@ -72,7 +75,7 @@ const payment_tx = async () => {
customer_email: '[email protected]',
coin: 'BUSD', // BUSD, DAI, USDC or USDT
currency: 'USD', // NGN, AED, GBP, EUR
amount: 100,
amount: '100',
accept_partial_payment: true, // By default it's false
metadata: {
type: "Wallet fund"
Expand All @@ -93,10 +96,6 @@ const payment_tx = async () => {
This describes to allow you confirm your customers transaction after payment has been made.

```javascript
const Lazerpay = require('lazerpay-node-sdk');

const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

const confirm_tx = async () => {
try {
const payload = {
Expand All @@ -120,10 +119,6 @@ const confirm_tx = async () => {
This describes to allow you withdraw the crypto in their lazerpay balance to an external address

```javascript
const Lazerpay = require('lazerpay-node-sdk');

const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

const crypto_payout_tx = async () => {
const transaction_payload = {
amount: 1,
Expand All @@ -150,10 +145,6 @@ const crypto_payout_tx = async () => {
This describes to allow you swap swap between two stable coins

```javascript
const Lazerpay = require('lazerpay-node-sdk');

const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

const crypto_swap_tx = async () => {
const swap_payload = {
amount: 100,
Expand All @@ -178,10 +169,6 @@ const crypto_swap_tx = async () => {
This describes the amount you will receive on swap even before initiating the swap

```javascript
const Lazerpay = require('lazerpay-node-sdk');

const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

const crypto_swap_tx = async () => {
const swap_payload = {
amount: 100,
Expand All @@ -205,10 +192,6 @@ const crypto_swap_tx = async () => {
This describes to allow you create a Payment link programatically

```javascript
const Lazerpay = require('lazerpay-node-sdk');

const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

const create_paymentlink_tx = async () => {
const transaction_payload = {
title: 'Njoku Test',
Expand All @@ -235,10 +218,6 @@ const create_paymentlink_tx = async () => {
This describes disabling or enabling a payment link by updating it

```javascript
const Lazerpay = require('lazerpay-node-sdk');

const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

const transaction_payload = {
identifier: '7f2vrd8n',
status: 'inactive', // status should either be active or inactive
Expand All @@ -261,10 +240,6 @@ const update_paymentLink = async () => {
This describes to allow you get all Payment links created

```javascript
const Lazerpay = require('lazerpay-node-sdk');

const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

const get_all_paymentlinks = async () => {
try {
const response = await lazerpay.PaymentLinks.getAllPaymentLinks();
Expand All @@ -280,10 +255,6 @@ const get_all_paymentlinks = async () => {
This describes to allow you get a Payment link by it's identifier

```javascript
const Lazerpay = require('lazerpay-node-sdk');

const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

const identifier = '7f2vrd8n';

const get_paymentlink = async () => {
Expand All @@ -296,17 +267,65 @@ const get_paymentlink = async () => {
};
```

## Onramp

#### `Get rate`

This methods lets you get onramp rate

```javascript
const get_onramp_rate = async () => {
try {
const response = await lazerpay.Onramp.getOnrampRate({
currency: 'NGN',
});
console.log(response);
} catch (error) {
console.log(error);
}
};
```

#### `Get Accounts`
This methods lets get your onramp bank accounts
```javascript
const get_onramp_accounts = async () => {
try {
const response = await lazer.Onramp.getOnrampAccounts();
console.log(response);
} catch (error) {
console.log(error);
}
};
```

#### `Initiate`
This methods lets you initiate onramp request
```javascript
const initiate_onramp = async () => {
try {
const response = await lazer.Onramp.initiateOnramp({
amount: 10000,
currency: 'NGN',
accountId: "Account id",
reference: "Payment reference",
coin: 'USDT',
});
console.log(response);
} catch (error) {
console.log(error);
}
};
```


## Misc

#### `Get Accepted Coins`

This gets the list of accepted cryptocurrencies on Lazerpay

```javascript
const Lazerpay = require('lazerpay-node-sdk');

const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

const get_accepted_coins = async () => {
try {
const response = await lazerpay.Misc.getAcceptedCoins();
Expand All @@ -318,15 +337,27 @@ const get_accepted_coins = async () => {
```


#### `Get Wallet Balance`
#### `Get Accepted Currencies`

Get get wallet balance by specifying the coin
This gets the list of accepted Currencies on Lazerpay

```javascript
const Lazerpay = require('lazerpay-node-sdk');
const get_accepted_currencies = async () => {
try {
const response = await lazerpay.Misc.getAcceptedCurrencies();
console.log(response);
} catch (error) {
console.log(error);
}
};
```

const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

#### `Get Wallet Balance`

Get get wallet balance by specifying the coin

```javascript
const get_wallet_balance = async () => {
try {
const coin = "USDT" // BUSD, DAI, USDC or USDT
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
"size-limit": [
{
"path": "dist/lazerpay-node-sdk.cjs.production.min.js",
"limit": "10 KB"
"limit": "10.5 KB"
},
{
"path": "dist/lazerpay-node-sdk.esm.js",
"limit": "10 KB"
"limit": "10.5 KB"
}
],
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PaymentLink from './services/payment-links';
import Payout from './services/transfer';
import Swap from './services/swap';
import Misc from './services/misc';
import Onramp from './services/onramp';

class Lazerpay {
apiPubKey: string;
Expand All @@ -13,6 +14,7 @@ class Lazerpay {
Swap: Swap;
PaymentLinks: PaymentLink;
Misc: Misc;
Onramp: Onramp;

/**
* This is a constructor for creating Lazerpay Instance
Expand All @@ -28,6 +30,7 @@ class Lazerpay {
this.Swap = new Swap(apiSecKey);
this.PaymentLinks = new PaymentLink(apiSecKey);
this.Misc = new Misc(apiPubKey, apiSecKey);
this.Onramp = new Onramp(apiSecKey);
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/services/misc/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import getAcceptedCoins from './lazerpay.getAcceptedCoins';
import getWalletBalance from './lazerpay.getWalletBalance';
import getCurrencies from './lazerpay.getAcceptedCurrencies';

export default class Misc {
apiPubKey: string;
apiSecKey: string;
Expand All @@ -18,6 +20,17 @@ export default class Misc {
});
}

/**
* list of currencies
* @param payload
*/

async getAcceptedCurrencies(): Promise<any> {
return await getCurrencies({
apiPubKey: this.apiPubKey,
});
}

/**
* Get wallet balance
* @param payload
Expand Down
19 changes: 19 additions & 0 deletions src/services/misc/lazerpay.getAcceptedCurrencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { LazerApi, setapiPubKey } from '../../utils/api';
import { API_URL_GET_ACCEPTED_CURRENCIES } from '../../utils/constants';

type GetAcceptedCurrenciesData = {
apiPubKey: string;
};

export default async function(args: GetAcceptedCurrenciesData) {
const { apiPubKey } = args;

try {
await setapiPubKey(apiPubKey);
const response = await LazerApi.get(API_URL_GET_ACCEPTED_CURRENCIES);

return response?.data;
} catch (err) {
throw err;
}
}
51 changes: 51 additions & 0 deletions src/services/onramp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
GetOnrampRatePayloadData,
InitiateOnrampPayloadData,
} from '../../utils/types';

import getRate from './lazerpay.getRate';
import initiate from './lazerpay.initiate';
import getAccounts from './lazerpay.getAccounts';

export default class Onramp {
apiSecKey: string;
constructor(apiSecKey: string) {
this.apiSecKey = apiSecKey;
}

/**
* Get onramp rate
* @param payload
* @returns
*/

async getOnrampRate(args: GetOnrampRatePayloadData): Promise<any> {
return await getRate({
...args,
apiSecKey: this.apiSecKey,
});
}

/**
* Get onramp accounts
* @param payload
*/

async getOnrampAccounts(): Promise<any> {
return await getAccounts({
apiSecKey: this.apiSecKey,
});
}

/**
* Initiate onramp
* @param payload
*/

async initiateOnramp(args: InitiateOnrampPayloadData): Promise<any> {
return await initiate({
...args,
apiSecKey: this.apiSecKey,
});
}
}
19 changes: 19 additions & 0 deletions src/services/onramp/lazerpay.getAccounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { API_URL_GET_ONRAMP_ACCOUNTS } from '../../utils/constants';
import { LazerApi, setApiSecKey } from '../../utils/api';

type OnrampData = {
apiSecKey: string;
};

export default async function(args: OnrampData) {
const { apiSecKey } = args;

try {
await setApiSecKey(apiSecKey);
const response = await LazerApi.get(API_URL_GET_ONRAMP_ACCOUNTS);

return response.data;
} catch (err) {
throw err;
}
}
Loading

0 comments on commit 2c25dec

Please sign in to comment.