├── .gitignore ├── images └── LZP Blue 2.png ├── .github ├── workflows │ ├── size.yml │ └── main.yml └── pull_request_template.md ├── src ├── services │ ├── onramp │ │ ├── lazerpay.getAccounts.ts │ │ ├── lazerpay.getRate.ts │ │ ├── lazerpay.initiate.ts │ │ └── index.ts │ ├── payment-links │ │ ├── lazerpay.getAllPaymentLinks.ts │ │ ├── lazerpay.getPaymentLink.ts │ │ ├── lazerpay.updatePaymentLink.ts │ │ ├── lazerpay.createPaymentLink.ts │ │ └── index.ts │ ├── misc │ │ ├── lazerpay.getAcceptedCoins.ts │ │ ├── lazerpay.getAcceptedCurrencies.ts │ │ ├── lazerpay.getWalletBalance.ts │ │ └── index.ts │ ├── transfer │ │ ├── index.ts │ │ └── lazerpay.transferCrypto.ts │ ├── payment │ │ ├── lazerpay.confirmPayment.ts │ │ ├── index.ts │ │ └── lazerpay.initTransaction.ts │ └── swap │ │ ├── lazerpay.getCryptoAmountOut.ts │ │ ├── lazerpay.cryptoSwap.ts │ │ └── index.ts ├── utils │ ├── api.ts │ ├── constants.ts │ └── types.ts └── index.ts ├── LICENSE ├── test ├── onramp.test.ts ├── paymentLinks.test.ts └── initialize.test.ts ├── package.json ├── tsconfig.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .DS_Store 3 | node_modules 4 | dist 5 | .env 6 | -------------------------------------------------------------------------------- /images/LZP Blue 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LazerpayHQ/lazerpay-node-sdk/HEAD/images/LZP Blue 2.png -------------------------------------------------------------------------------- /.github/workflows/size.yml: -------------------------------------------------------------------------------- 1 | name: size 2 | on: [pull_request] 3 | jobs: 4 | size: 5 | runs-on: ubuntu-latest 6 | env: 7 | CI_JOB_NUMBER: 1 8 | steps: 9 | - uses: actions/checkout@v1 10 | - uses: andresz1/size-limit-action@v1 11 | with: 12 | github_token: ${{ secrets.GITHUB_TOKEN }} 13 | -------------------------------------------------------------------------------- /src/services/onramp/lazerpay.getAccounts.ts: -------------------------------------------------------------------------------- 1 | import { API_URL_GET_ONRAMP_ACCOUNTS } from '../../utils/constants'; 2 | import { LazerApi, setApiSecKey } from '../../utils/api'; 3 | 4 | type OnrampData = { 5 | apiSecKey: string; 6 | }; 7 | 8 | export default async function(args: OnrampData) { 9 | const { apiSecKey } = args; 10 | 11 | try { 12 | await setApiSecKey(apiSecKey); 13 | const response = await LazerApi.get(API_URL_GET_ONRAMP_ACCOUNTS); 14 | 15 | return response.data; 16 | } catch (err) { 17 | throw err; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/services/payment-links/lazerpay.getAllPaymentLinks.ts: -------------------------------------------------------------------------------- 1 | import { LazerApi, setApiSecKey } from '../../utils/api'; 2 | import { API_URL_PAYMENT_LINK } from '../../utils/constants'; 3 | 4 | type PaymentLinkData = { 5 | apiSecKey: string; 6 | }; 7 | 8 | export default async function(args: PaymentLinkData) { 9 | const { apiSecKey } = args; 10 | 11 | try { 12 | await setApiSecKey(apiSecKey); 13 | const response = await LazerApi.get(API_URL_PAYMENT_LINK); 14 | 15 | return response?.data; 16 | } catch (err) { 17 | throw err; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/services/misc/lazerpay.getAcceptedCoins.ts: -------------------------------------------------------------------------------- 1 | import { LazerApi, setapiPubKey } from '../../utils/api'; 2 | import { API_URL_GET_ACCEPTED_COINS } from '../../utils/constants'; 3 | 4 | type TransactionData = { 5 | apiPubKey: string; 6 | }; 7 | 8 | export default async function(args: TransactionData) { 9 | const { apiPubKey } = args; 10 | 11 | try { 12 | await setapiPubKey(apiPubKey); 13 | const response = await LazerApi.get(API_URL_GET_ACCEPTED_COINS); 14 | 15 | return response?.data; 16 | } catch (err) { 17 | throw err; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/services/transfer/index.ts: -------------------------------------------------------------------------------- 1 | import { TransferCryptoPayloadData } from '../../utils/types'; 2 | import transferCrypto from './lazerpay.transferCrypto'; 3 | export default class Payout { 4 | apiSecKey: string; 5 | constructor(apiSecKey: string) { 6 | this.apiSecKey = apiSecKey; 7 | } 8 | 9 | /** 10 | * Transfer out tokens to external wallet 11 | * @param payload 12 | */ 13 | async transferCrypto(args: TransferCryptoPayloadData): Promise { 14 | return await transferCrypto({ 15 | ...args, 16 | apiSecKey: this.apiSecKey, 17 | }); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/services/misc/lazerpay.getAcceptedCurrencies.ts: -------------------------------------------------------------------------------- 1 | import { LazerApi, setapiPubKey } from '../../utils/api'; 2 | import { API_URL_GET_ACCEPTED_CURRENCIES } from '../../utils/constants'; 3 | 4 | type GetAcceptedCurrenciesData = { 5 | apiPubKey: string; 6 | }; 7 | 8 | export default async function(args: GetAcceptedCurrenciesData) { 9 | const { apiPubKey } = args; 10 | 11 | try { 12 | await setapiPubKey(apiPubKey); 13 | const response = await LazerApi.get(API_URL_GET_ACCEPTED_CURRENCIES); 14 | 15 | return response?.data; 16 | } catch (err) { 17 | throw err; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/services/onramp/lazerpay.getRate.ts: -------------------------------------------------------------------------------- 1 | import { API_URL_GET_ONRAMP_RATE } from '../../utils/constants'; 2 | import { LazerApi, setApiSecKey } from '../../utils/api'; 3 | 4 | type OnrampData = { 5 | currency: string; 6 | apiSecKey: string; 7 | }; 8 | 9 | export default async function(args: OnrampData) { 10 | const { currency, apiSecKey } = args; 11 | 12 | try { 13 | await setApiSecKey(apiSecKey); 14 | const response = await LazerApi.get( 15 | `${API_URL_GET_ONRAMP_RATE}/?currency=${currency}` 16 | ); 17 | 18 | return response.data; 19 | } catch (err) { 20 | throw err; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/services/misc/lazerpay.getWalletBalance.ts: -------------------------------------------------------------------------------- 1 | import { LazerApi, setApiSecKey } from '../../utils/api'; 2 | import { API_URL_GET_WALLET_BALANCE } from '../../utils/constants'; 3 | 4 | type GetWalletBalanceData = { 5 | coin: string; 6 | apiSecKey: string; 7 | }; 8 | 9 | export default async function(args: GetWalletBalanceData) { 10 | const { apiSecKey, coin } = args; 11 | 12 | try { 13 | await setApiSecKey(apiSecKey); 14 | const response = await LazerApi.get( 15 | `${API_URL_GET_WALLET_BALANCE}?coin=${coin}` 16 | ); 17 | 18 | return response?.data; 19 | } catch (err) { 20 | throw err; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/services/payment-links/lazerpay.getPaymentLink.ts: -------------------------------------------------------------------------------- 1 | import { LazerApi, setApiSecKey } from '../../utils/api'; 2 | import { API_URL_PAYMENT_LINK } from '../../utils/constants'; 3 | 4 | type PaymentLinkData = { 5 | identifier: string; 6 | apiSecKey: string; 7 | }; 8 | 9 | export default async function(args: PaymentLinkData) { 10 | const { apiSecKey, identifier } = args; 11 | 12 | try { 13 | await setApiSecKey(apiSecKey); 14 | const response = await LazerApi.get( 15 | `${API_URL_PAYMENT_LINK}/${identifier}` 16 | ); 17 | 18 | return response?.data; 19 | } catch (err) { 20 | throw err; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/services/payment/lazerpay.confirmPayment.ts: -------------------------------------------------------------------------------- 1 | import { API_URL_CONFIRM_TRANSACTION } from '../../utils/constants'; 2 | import { LazerApi, setapiPubKey } from '../../utils/api'; 3 | 4 | type TransactionData = { 5 | identifier: string; 6 | apiPubKey: string; 7 | }; 8 | 9 | export default async function(args: TransactionData) { 10 | const { identifier, apiPubKey } = args; 11 | 12 | try { 13 | await setapiPubKey(apiPubKey); 14 | const response = await LazerApi.get( 15 | `${API_URL_CONFIRM_TRANSACTION}/${identifier}` 16 | ); 17 | 18 | return response.data; 19 | } catch (err) { 20 | throw err; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/services/payment-links/lazerpay.updatePaymentLink.ts: -------------------------------------------------------------------------------- 1 | import { LazerApi, setApiSecKey } from '../../utils/api'; 2 | import { API_URL_PAYMENT_LINK } from '../../utils/constants'; 3 | 4 | type PaymentLinkData = { 5 | identifier: string; 6 | status: string; 7 | apiSecKey: string; 8 | }; 9 | 10 | export default async function(args: PaymentLinkData) { 11 | const { apiSecKey, identifier, status } = args; 12 | 13 | try { 14 | await setApiSecKey(apiSecKey); 15 | const response = await LazerApi.put( 16 | `${API_URL_PAYMENT_LINK}/${identifier}`, 17 | { status } 18 | ); 19 | 20 | return response?.data; 21 | } catch (err) { 22 | throw err; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/utils/api.ts: -------------------------------------------------------------------------------- 1 | import { API_URL } from './constants'; 2 | import axios from 'axios'; 3 | 4 | export const LazerApi: any = axios.create({ 5 | baseURL: API_URL, 6 | headers: { 7 | 'Content-Type': 'application/json', 8 | }, 9 | }); 10 | 11 | export const setapiPubKey = async (apiPubKey: string) => { 12 | try { 13 | if (apiPubKey !== null) { 14 | LazerApi.defaults.headers.common['x-api-key'] = apiPubKey; 15 | } 16 | } catch { 17 | throw new Error('Error setting API key'); 18 | } 19 | }; 20 | export const setApiSecKey = async (apiSecKey: string) => { 21 | try { 22 | if (apiSecKey !== null) { 23 | LazerApi.defaults.headers.common['Authorization'] = `Bearer ${apiSecKey}`; 24 | } 25 | } catch { 26 | throw new Error('Error setting API key'); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /src/services/swap/lazerpay.getCryptoAmountOut.ts: -------------------------------------------------------------------------------- 1 | import { LazerApi, setApiSecKey } from '../../utils/api'; 2 | import { API_URL_GET_CRYPTO_AMOUNT_OUT } from '../../utils/constants'; 3 | 4 | type GetCryptoSwapAmountOutData = { 5 | amount: number; 6 | fromCoin: string; 7 | toCoin: string; 8 | blockchain: string; 9 | apiSecKey: string; 10 | }; 11 | 12 | export default async function(args: GetCryptoSwapAmountOutData) { 13 | const { amount, fromCoin, toCoin, blockchain, apiSecKey } = args; 14 | 15 | try { 16 | await setApiSecKey(apiSecKey); 17 | const response = await LazerApi.post(API_URL_GET_CRYPTO_AMOUNT_OUT, { 18 | amount, 19 | fromCoin, 20 | toCoin, 21 | blockchain, 22 | }); 23 | 24 | return response?.data; 25 | } catch (err) { 26 | throw err; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/services/swap/lazerpay.cryptoSwap.ts: -------------------------------------------------------------------------------- 1 | import { LazerApi, setApiSecKey } from '../../utils/api'; 2 | import { API_URL_CRYPTO_SWAP } from '../../utils/constants'; 3 | 4 | type CryptoSwapData = { 5 | amount: number; 6 | fromCoin: string; 7 | toCoin: string; 8 | blockchain: string; 9 | apiSecKey: string; 10 | metadata?: object | {}; 11 | }; 12 | 13 | export default async function(args: CryptoSwapData) { 14 | const { amount, fromCoin, toCoin, blockchain, apiSecKey, metadata } = args; 15 | 16 | try { 17 | await setApiSecKey(apiSecKey); 18 | const response = await LazerApi.post(API_URL_CRYPTO_SWAP, { 19 | amount, 20 | fromCoin, 21 | toCoin, 22 | blockchain, 23 | metadata, 24 | }); 25 | 26 | return response?.data; 27 | } catch (err) { 28 | throw err; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/services/transfer/lazerpay.transferCrypto.ts: -------------------------------------------------------------------------------- 1 | import { LazerApi, setApiSecKey } from '../../utils/api'; 2 | import { API_URL_TRANSFER_FUNDS } from '../../utils/constants'; 3 | 4 | type TransactionData = { 5 | amount: number; 6 | recipient: string; 7 | coin: string; 8 | blockchain: string; 9 | apiSecKey: string; 10 | metadata?: object | {}; 11 | }; 12 | 13 | export default async function(args: TransactionData) { 14 | const { amount, recipient, coin, blockchain, apiSecKey, metadata } = args; 15 | 16 | try { 17 | await setApiSecKey(apiSecKey); 18 | const response = await LazerApi.post(API_URL_TRANSFER_FUNDS, { 19 | amount, 20 | recipient, 21 | coin, 22 | blockchain, 23 | metadata, 24 | }); 25 | 26 | return response?.data; 27 | } catch (err) { 28 | throw err; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: [push] 3 | jobs: 4 | build: 5 | name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }} 6 | 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | matrix: 10 | node: ['14.x'] 11 | os: [ubuntu-latest, windows-latest, macOS-latest] 12 | 13 | steps: 14 | - name: Checkout repo 15 | uses: actions/checkout@v2 16 | 17 | - name: Use Node ${{ matrix.node }} 18 | uses: actions/setup-node@v1 19 | with: 20 | node-version: ${{ matrix.node }} 21 | 22 | - name: Install deps and build (with cache) 23 | uses: bahmutov/npm-install@v1 24 | 25 | - name: Lint 26 | run: yarn lint 27 | 28 | - name: Test 29 | run: yarn test --ci --coverage --maxWorkers=2 30 | 31 | - name: Build 32 | run: yarn build 33 | -------------------------------------------------------------------------------- /src/services/onramp/lazerpay.initiate.ts: -------------------------------------------------------------------------------- 1 | import { API_URL_INITIATE_ONRAMP } from '../../utils/constants'; 2 | import { LazerApi, setApiSecKey } from '../../utils/api'; 3 | 4 | type OnrampData = { 5 | reference: string; 6 | accountId: string; 7 | amount: number; 8 | currency: string; 9 | coin: string; 10 | metadata?: object | {}; 11 | apiSecKey: string; 12 | }; 13 | 14 | export default async function(args: OnrampData) { 15 | const { 16 | reference, 17 | accountId, 18 | amount, 19 | currency, 20 | coin, 21 | metadata, 22 | apiSecKey, 23 | } = args; 24 | 25 | try { 26 | await setApiSecKey(apiSecKey); 27 | const response = await LazerApi.post(API_URL_INITIATE_ONRAMP, { 28 | reference, 29 | bank_account_id: accountId, 30 | amount, 31 | currency, 32 | coin, 33 | metadata, 34 | }); 35 | 36 | return response?.data; 37 | } catch (err) { 38 | throw err; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/utils/constants.ts: -------------------------------------------------------------------------------- 1 | export const API_URL = 'https://api.lazerpay.engineering/api/v1'; 2 | 3 | export const API_URL_INIT_TRANSACTION = `${API_URL}/transaction/initialize`; 4 | export const API_URL_CONFIRM_TRANSACTION = `${API_URL}/transaction/verify`; 5 | export const API_URL_GET_ACCEPTED_COINS = `${API_URL}/coins`; 6 | export const API_URL_GET_ACCEPTED_CURRENCIES = `${API_URL}/currencies`; 7 | export const API_URL_TRANSFER_FUNDS = `${API_URL}/crypto/payouts/initiate`; 8 | export const API_URL_PAYMENT_LINK = `${API_URL}/payment-links`; 9 | export const API_URL_CRYPTO_SWAP = `${API_URL}/swap/crypto`; 10 | export const API_URL_GET_CRYPTO_AMOUNT_OUT = `${API_URL}/swap/crypto/amount-out`; 11 | export const API_URL_GET_WALLET_BALANCE = `${API_URL}/wallet/balance`; 12 | 13 | export const API_URL_GET_ONRAMP_RATE = `${API_URL}/bank/funding/rate`; 14 | export const API_URL_INITIATE_ONRAMP = `${API_URL}/bank/funding/initiate`; 15 | export const API_URL_GET_ONRAMP_ACCOUNTS = `${API_URL}/bank/funding/accounts`; 16 | -------------------------------------------------------------------------------- /src/services/payment-links/lazerpay.createPaymentLink.ts: -------------------------------------------------------------------------------- 1 | import { LazerApi, setApiSecKey } from '../../utils/api'; 2 | import { API_URL_PAYMENT_LINK } from '../../utils/constants'; 3 | 4 | type PaymentLinkData = { 5 | title: string; 6 | description: string; 7 | logo?: string; 8 | redirect_url?: string; 9 | amount?: string; 10 | currency?: string; 11 | apiSecKey: string; 12 | type?: string; 13 | }; 14 | 15 | export default async function(args: PaymentLinkData) { 16 | const { 17 | title, 18 | type, 19 | description, 20 | logo, 21 | redirect_url, 22 | amount, 23 | currency, 24 | apiSecKey, 25 | } = args; 26 | 27 | try { 28 | await setApiSecKey(apiSecKey); 29 | const response = await LazerApi.post(API_URL_PAYMENT_LINK, { 30 | title, 31 | type, 32 | description, 33 | logo, 34 | redirect_url, 35 | currency, 36 | amount, 37 | }); 38 | 39 | return response?.data; 40 | } catch (err) { 41 | throw err; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/services/swap/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CryptoSwapPayloadData, 3 | GetCryptoSwapAmountOutPayloadData, 4 | } from '../../utils/types'; 5 | import cryptoSwap from './lazerpay.cryptoSwap'; 6 | import getCryptoSwapAmountOut from './lazerpay.getCryptoAmountOut'; 7 | export default class Swap { 8 | apiSecKey: string; 9 | constructor(apiSecKey: string) { 10 | this.apiSecKey = apiSecKey; 11 | } 12 | 13 | /** 14 | * Initialize a swap between two stable coins 15 | * @param payload 16 | */ 17 | async cryptoSwap(args: CryptoSwapPayloadData): Promise { 18 | return await cryptoSwap({ 19 | ...args, 20 | apiSecKey: this.apiSecKey, 21 | }); 22 | } 23 | 24 | /** 25 | * Get coin swap amount out before initiating swap 26 | * @param payload 27 | */ 28 | async getCryptoSwapAmountOut( 29 | args: GetCryptoSwapAmountOutPayloadData 30 | ): Promise { 31 | return await getCryptoSwapAmountOut({ 32 | ...args, 33 | apiSecKey: this.apiSecKey, 34 | }); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/services/payment/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | TransactionPayloadData, 3 | ConfirmTransactionPayloadData, 4 | } from '../../utils/types'; 5 | import initializePayment from './lazerpay.initTransaction'; 6 | import confirmPayment from './lazerpay.confirmPayment'; 7 | export default class Payment { 8 | apiPubKey: string; 9 | apiSecKey: string; 10 | constructor(apiPubKey: string, apiSecKey: string) { 11 | this.apiPubKey = apiPubKey; 12 | this.apiSecKey = apiSecKey; 13 | } 14 | 15 | /** 16 | * Initialize a Payment 17 | * @param payload 18 | */ 19 | async initializePayment(args: TransactionPayloadData): Promise { 20 | return await initializePayment({ 21 | ...args, 22 | apiPubKey: this.apiPubKey, 23 | }); 24 | } 25 | /** 26 | * Confirm a Payment 27 | * @param payload 28 | */ 29 | async confirmPayment(args: ConfirmTransactionPayloadData): Promise { 30 | return await confirmPayment({ 31 | ...args, 32 | apiPubKey: this.apiPubKey, 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Njoku Emmanuel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /src/services/misc/index.ts: -------------------------------------------------------------------------------- 1 | import getAcceptedCoins from './lazerpay.getAcceptedCoins'; 2 | import getWalletBalance from './lazerpay.getWalletBalance'; 3 | import getCurrencies from './lazerpay.getAcceptedCurrencies'; 4 | 5 | export default class Misc { 6 | apiPubKey: string; 7 | apiSecKey: string; 8 | constructor(apiPubKey: string, apiSecKey: string) { 9 | this.apiPubKey = apiPubKey; 10 | this.apiSecKey = apiSecKey; 11 | } 12 | 13 | /** 14 | * list of accepted coins 15 | * @param payload 16 | */ 17 | async getAcceptedCoins(): Promise { 18 | return await getAcceptedCoins({ 19 | apiPubKey: this.apiPubKey, 20 | }); 21 | } 22 | 23 | /** 24 | * list of currencies 25 | * @param payload 26 | */ 27 | 28 | async getAcceptedCurrencies(): Promise { 29 | return await getCurrencies({ 30 | apiPubKey: this.apiPubKey, 31 | }); 32 | } 33 | 34 | /** 35 | * Get wallet balance 36 | * @param payload 37 | */ 38 | async getWalletBalance(coin: string): Promise { 39 | return await getWalletBalance({ 40 | apiSecKey: this.apiSecKey, 41 | coin, 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/services/payment/lazerpay.initTransaction.ts: -------------------------------------------------------------------------------- 1 | import { LazerApi, setapiPubKey } from '../../utils/api'; 2 | import { API_URL_INIT_TRANSACTION } from '../../utils/constants'; 3 | 4 | type TransactionData = { 5 | reference?: string; 6 | amount: string; 7 | customer_name: string; 8 | customer_email: string; 9 | coin: string; 10 | currency: string; 11 | apiPubKey: string; 12 | accept_partial_payment?: boolean; 13 | metadata?: object | {}; 14 | }; 15 | 16 | export default async function(args: TransactionData) { 17 | const { 18 | reference, 19 | amount, 20 | currency, 21 | customer_name, 22 | customer_email, 23 | apiPubKey, 24 | coin, 25 | accept_partial_payment, 26 | metadata, 27 | } = args; 28 | 29 | try { 30 | await setapiPubKey(apiPubKey); 31 | const response = await LazerApi.post(API_URL_INIT_TRANSACTION, { 32 | reference, 33 | customer_name, 34 | customer_email, 35 | coin, 36 | currency, 37 | amount, 38 | accept_partial_payment, 39 | metadata, 40 | }); 41 | 42 | return response?.data; 43 | } catch (err) { 44 | throw err; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/services/onramp/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | GetOnrampRatePayloadData, 3 | InitiateOnrampPayloadData, 4 | } from '../../utils/types'; 5 | 6 | import getRate from './lazerpay.getRate'; 7 | import initiate from './lazerpay.initiate'; 8 | import getAccounts from './lazerpay.getAccounts'; 9 | 10 | export default class Onramp { 11 | apiSecKey: string; 12 | constructor(apiSecKey: string) { 13 | this.apiSecKey = apiSecKey; 14 | } 15 | 16 | /** 17 | * Get onramp rate 18 | * @param payload 19 | * @returns 20 | */ 21 | 22 | async getOnrampRate(args: GetOnrampRatePayloadData): Promise { 23 | return await getRate({ 24 | ...args, 25 | apiSecKey: this.apiSecKey, 26 | }); 27 | } 28 | 29 | /** 30 | * Get onramp accounts 31 | * @param payload 32 | */ 33 | 34 | async getOnrampAccounts(): Promise { 35 | return await getAccounts({ 36 | apiSecKey: this.apiSecKey, 37 | }); 38 | } 39 | 40 | /** 41 | * Initiate onramp 42 | * @param payload 43 | */ 44 | 45 | async initiateOnramp(args: InitiateOnrampPayloadData): Promise { 46 | return await initiate({ 47 | ...args, 48 | apiSecKey: this.apiSecKey, 49 | }); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import * as Types from './utils/types'; 2 | import Payment from './services/payment'; 3 | import PaymentLink from './services/payment-links'; 4 | import Payout from './services/transfer'; 5 | import Swap from './services/swap'; 6 | import Misc from './services/misc'; 7 | import Onramp from './services/onramp'; 8 | 9 | class Lazerpay { 10 | apiPubKey: string; 11 | apiSecKey: string; 12 | Payment: Payment; 13 | Payout: Payout; 14 | Swap: Swap; 15 | PaymentLinks: PaymentLink; 16 | Misc: Misc; 17 | Onramp: Onramp; 18 | 19 | /** 20 | * This is a constructor for creating Lazerpay Instance 21 | * @param {string} apiPubKey - Your Lazerpay public Key 22 | * @param {string} apiSecKey - Your Lazerpay secret Key 23 | */ 24 | 25 | constructor(apiPubKey: string, apiSecKey: string) { 26 | this.apiPubKey = apiPubKey; 27 | this.apiSecKey = apiSecKey; 28 | this.Payment = new Payment(apiPubKey, apiSecKey); 29 | this.Payout = new Payout(apiSecKey); 30 | this.Swap = new Swap(apiSecKey); 31 | this.PaymentLinks = new PaymentLink(apiSecKey); 32 | this.Misc = new Misc(apiPubKey, apiSecKey); 33 | this.Onramp = new Onramp(apiSecKey); 34 | } 35 | } 36 | 37 | export default Lazerpay; 38 | export { Types }; 39 | -------------------------------------------------------------------------------- /test/onramp.test.ts: -------------------------------------------------------------------------------- 1 | import Lazerpay from '../src/index'; 2 | 3 | describe('Lazerpay Onramp', () => { 4 | const lazer = new Lazerpay( 5 | 'pk_test_zwc4UmoI4Job5Wjs9ZySouPicAuGwT7C04JmWwvpSG1vUgrFyY', 6 | 'sk_test_LG3dTytiANx6ipqO4m8DNfnlx85lIBEL8kDR5k7ejxXwyHYDia' 7 | ); 8 | 9 | let accountId = ''; 10 | 11 | it('should get onramp rate', async () => { 12 | const response = await lazer.Onramp.getOnrampRate({ 13 | currency: 'USD', 14 | }); 15 | expect(typeof response).toBe('object'); 16 | }); 17 | 18 | it('should get onramp accounts', async () => { 19 | const response = await lazer.Onramp.getOnrampAccounts(); 20 | 21 | accountId = response.data[0].id; 22 | expect(typeof response).toBe('object'); 23 | }); 24 | 25 | it('should initiate onramp', async () => { 26 | // generate a unique reference 27 | const reference = 28 | Math.random() 29 | .toString(36) 30 | .substring(2, 15) + 31 | Math.random() 32 | .toString(36) 33 | .substring(2, 15); 34 | 35 | const response = await lazer.Onramp.initiateOnramp({ 36 | amount: 10000, 37 | currency: 'NGN', 38 | accountId, 39 | reference: reference.toString(), 40 | coin: 'USDT', 41 | }); 42 | expect(typeof response).toBe('object'); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.5", 3 | "license": "MIT", 4 | "main": "dist/index.js", 5 | "typings": "dist/index.d.ts", 6 | "files": [ 7 | "dist", 8 | "src" 9 | ], 10 | "engines": { 11 | "node": ">=10" 12 | }, 13 | "scripts": { 14 | "start": "tsdx watch", 15 | "build": "tsdx build", 16 | "test": "tsdx test", 17 | "lint": "tsdx lint", 18 | "prepare": "tsdx build", 19 | "size": "size-limit", 20 | "analyze": "size-limit --why" 21 | }, 22 | "husky": { 23 | "hooks": { 24 | "pre-commit": "tsdx lint" 25 | } 26 | }, 27 | "prettier": { 28 | "printWidth": 80, 29 | "semi": true, 30 | "singleQuote": true, 31 | "trailingComma": "es5" 32 | }, 33 | "name": "lazerpay-node-sdk", 34 | "author": "Njoku Emmanuel", 35 | "module": "dist/lazerpay-node-sdk.esm.js", 36 | "size-limit": [ 37 | { 38 | "path": "dist/lazerpay-node-sdk.cjs.production.min.js", 39 | "limit": "10.5 KB" 40 | }, 41 | { 42 | "path": "dist/lazerpay-node-sdk.esm.js", 43 | "limit": "10.5 KB" 44 | } 45 | ], 46 | "devDependencies": { 47 | "@size-limit/preset-small-lib": "^5.0.5", 48 | "husky": "^7.0.2", 49 | "size-limit": "^5.0.5", 50 | "tsdx": "^0.14.1", 51 | "tslib": "^2.3.1", 52 | "typescript": "^4.4.3" 53 | }, 54 | "dependencies": { 55 | "axios": "^0.22.0", 56 | "dotenv": "^16.0.0" 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Description 4 | 5 | 6 | 7 | ## Motivation and Context 8 | 9 | 10 | 11 | 12 | ## How Has This Been Tested? 13 | 14 | 15 | 16 | 17 | 18 | ## Screenshots (if appropriate): 19 | 20 | ## Types of changes 21 | 22 | 23 | 24 | - [ ] Bug fix (non-breaking change which fixes an issue) 25 | - [ ] New feature (non-breaking change which adds functionality) 26 | - [ ] Breaking change (fix or feature that would cause existing functionality to change) 27 | 28 | ## Checklist: 29 | 30 | 31 | 32 | 33 | - [ ] My code follows the code style of this project. 34 | - [ ] My change requires a change to the documentation. 35 | - [ ] I have updated the documentation accordingly. 36 | - [ ] I have added tests to cover my changes. 37 | - [ ] All new and existing tests passed. 38 | -------------------------------------------------------------------------------- /src/utils/types.ts: -------------------------------------------------------------------------------- 1 | export interface TransactionPayloadData { 2 | reference?: string; 3 | amount: string; 4 | customer_name: string; 5 | customer_email: string; 6 | coin: string; 7 | currency: string; 8 | accept_partial_payment?: boolean; 9 | metadata?: object | {}; 10 | } 11 | export interface ConfirmTransactionPayloadData { 12 | identifier: string; 13 | } 14 | export interface TransferCryptoPayloadData { 15 | amount: number; 16 | recipient: string; 17 | coin: string; 18 | blockchain: string; 19 | metadata?: object | {}; 20 | } 21 | export interface PaymentLinkPayloadData { 22 | title: string; 23 | description: string; 24 | logo?: string; 25 | redirect_url?: string; 26 | amount?: string; 27 | currency?: string; 28 | type?: string; 29 | } 30 | export interface UpdatePaymentLinkPayloadData { 31 | status: string; 32 | identifier: string; 33 | } 34 | 35 | export interface CryptoSwapPayloadData { 36 | amount: number; 37 | fromCoin: string; 38 | toCoin: string; 39 | blockchain: string; 40 | metadata?: object | {}; 41 | } 42 | 43 | export interface GetCryptoSwapAmountOutPayloadData { 44 | amount: number; 45 | fromCoin: string; 46 | toCoin: string; 47 | blockchain: string; 48 | } 49 | 50 | export interface GetOnrampRatePayloadData { 51 | currency: string; 52 | } 53 | 54 | export interface InitiateOnrampPayloadData { 55 | reference: string; 56 | accountId: string; 57 | amount: number; 58 | currency: string; 59 | coin: string; 60 | metadata?: object | {}; 61 | } 62 | -------------------------------------------------------------------------------- /src/services/payment-links/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | PaymentLinkPayloadData, 3 | UpdatePaymentLinkPayloadData, 4 | } from '../../utils/types'; 5 | import createPaymentLink from './lazerpay.createPaymentLink'; 6 | import getPaymentLinks from './lazerpay.getAllPaymentLinks'; 7 | import getPaymentLink from './lazerpay.getPaymentLink'; 8 | import updatePaymentLink from './lazerpay.updatePaymentLink'; 9 | export default class PaymentLink { 10 | apiSecKey: string; 11 | constructor(apiSecKey: string) { 12 | this.apiSecKey = apiSecKey; 13 | } 14 | 15 | /** 16 | * Create a Payment Link 17 | * @param payload 18 | */ 19 | async createPaymentLink(args: PaymentLinkPayloadData): Promise { 20 | return await createPaymentLink({ 21 | ...args, 22 | apiSecKey: this.apiSecKey, 23 | }); 24 | } 25 | /** 26 | * get all Payment Links 27 | * @param payload 28 | */ 29 | async getAllPaymentLinks(): Promise { 30 | return await getPaymentLinks({ 31 | apiSecKey: this.apiSecKey, 32 | }); 33 | } 34 | /** 35 | * get Payment Links 36 | * @param payload 37 | */ 38 | async getPaymentLink(identifier: string): Promise { 39 | return await getPaymentLink({ 40 | identifier, 41 | apiSecKey: this.apiSecKey, 42 | }); 43 | } 44 | /** 45 | * get Payment Links 46 | * @param payload 47 | */ 48 | async updatePaymentLink(args: UpdatePaymentLinkPayloadData): Promise { 49 | return await updatePaymentLink({ 50 | ...args, 51 | apiSecKey: this.apiSecKey, 52 | }); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs 3 | "include": ["src", "types"], 4 | "compilerOptions": { 5 | "module": "esnext", 6 | "lib": ["dom", "esnext"], 7 | "importHelpers": true, 8 | // output .d.ts declaration files for consumers 9 | "declaration": true, 10 | // output .js.map sourcemap files for consumers 11 | "sourceMap": true, 12 | // match output dir to input dir. e.g. dist/index instead of dist/src/index 13 | "rootDir": "./src", 14 | // stricter type-checking for stronger correctness. Recommended by TS 15 | "strict": true, 16 | // linter checks for common issues 17 | "noImplicitReturns": true, 18 | "noFallthroughCasesInSwitch": true, 19 | // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | // use Node's module resolution algorithm, instead of the legacy TS one 23 | "moduleResolution": "node", 24 | // transpile JSX to React.createElement 25 | "jsx": "react", 26 | // interop between ESM and CJS modules. Recommended by TS 27 | "esModuleInterop": true, 28 | // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS 29 | "skipLibCheck": true, 30 | // error out if import and file system have a casing mismatch. Recommended by TS 31 | "forceConsistentCasingInFileNames": true, 32 | // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc` 33 | "noEmit": true, 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/paymentLinks.test.ts: -------------------------------------------------------------------------------- 1 | import Lazerpay from '../src/index'; 2 | import dotenv from 'dotenv'; 3 | 4 | dotenv.config(); 5 | 6 | describe('#Transaction module', () => { 7 | const lazer = new Lazerpay( 8 | 'pk_test_zwc4UmoI4Job5Wjs9ZySouPicAuGwT7C04JmWwvpSG1vUgrFyY', 9 | 'sk_test_LG3dTytiANx6ipqO4m8DNfnlx85lIBEL8kDR5k7ejxXwyHYDia' 10 | ); 11 | jest.setTimeout(300000000); 12 | 13 | it('should create a payment link', async () => { 14 | const transaction_payload = { 15 | title: 'Njoku Test', 16 | description: 'Testing this sdk', 17 | logo: 'https://webhook.site/d1e815d0-0aa4-4bee-aeb5-a5eb0f62701a', 18 | currency: 'USD', 19 | type: 'standard', 20 | }; 21 | try { 22 | const response = await lazer.PaymentLinks.createPaymentLink( 23 | transaction_payload 24 | ); 25 | expect(typeof response).toBe('object'); 26 | } catch (e) { 27 | console.log(e); 28 | } 29 | }); 30 | 31 | it('should get all payment link', async () => { 32 | try { 33 | const response = await lazer.PaymentLinks.getAllPaymentLinks(); 34 | expect(typeof response).toBe('object'); 35 | } catch (e) { 36 | console.log(e); 37 | } 38 | }); 39 | it('should get a single payment link', async () => { 40 | try { 41 | const identifier = 'b9diy0ozda'; 42 | 43 | const response = await lazer.PaymentLinks.getPaymentLink(identifier); 44 | expect(typeof response).toBe('object'); 45 | } catch (e) { 46 | console.log(e); 47 | } 48 | }); 49 | it('should update a payment link', async () => { 50 | try { 51 | const transaction_payload = { 52 | identifier: 'b9diy0ozda', 53 | status: 'active', 54 | }; 55 | 56 | const response = await lazer.PaymentLinks.updatePaymentLink( 57 | transaction_payload 58 | ); 59 | expect(typeof response).toBe('object'); 60 | } catch (e) { 61 | console.log(e); 62 | } 63 | }); 64 | }); 65 | -------------------------------------------------------------------------------- /test/initialize.test.ts: -------------------------------------------------------------------------------- 1 | import Lazerpay from '../src/index'; 2 | import dotenv from 'dotenv'; 3 | 4 | dotenv.config(); 5 | 6 | describe('#Transaction module', () => { 7 | const lazerpay = new Lazerpay( 8 | 'pk_test_zwc4UmoI4Job5Wjs9ZySouPicAuGwT7C04JmWwvpSG1vUgrFyY', 9 | 'sk_test_LG3dTytiANx6ipqO4m8DNfnlx85lIBEL8kDR5k7ejxXwyHYDia' 10 | ); 11 | jest.setTimeout(300000000); 12 | 13 | it('should payout funds to an address', async () => { 14 | const transaction_payload = { 15 | amount: 1, 16 | recipient: '0x0B4d358D349809037003F96A3593ff9015E89efA', 17 | coin: 'BUSD', 18 | blockchain: 'Binance Smart Chain', 19 | }; 20 | try { 21 | const response = await lazerpay.Payout.transferCrypto( 22 | transaction_payload 23 | ); 24 | 25 | expect(typeof response).toBe('object'); 26 | } catch (e) { 27 | console.log(e); 28 | } 29 | }); 30 | it('should get accepted coins', async () => { 31 | try { 32 | const response = await lazerpay.Misc.getAcceptedCoins(); 33 | 34 | expect(typeof response).toBe('object'); 35 | } catch (err) { 36 | return err; 37 | } 38 | }); 39 | 40 | it('should get accepted currencies', async () => { 41 | try { 42 | const response = await lazerpay.Misc.getAcceptedCurrencies(); 43 | 44 | expect(typeof response).toBe('object'); 45 | } catch (err) { 46 | return err; 47 | } 48 | }); 49 | 50 | it('should get wallet balance', async () => { 51 | try { 52 | const response = await lazerpay.Misc.getWalletBalance('BUSD'); 53 | 54 | expect(typeof response).toBe('object'); 55 | } catch (err) { 56 | return err; 57 | } 58 | }); 59 | 60 | it('it should intialize transaction', async () => { 61 | try { 62 | const reference = 63 | Math.random() 64 | .toString(36) 65 | .substring(2, 15) + 66 | Math.random() 67 | .toString(36) 68 | .substring(2, 15); 69 | 70 | const response = await lazerpay.Payment.initializePayment({ 71 | reference: reference.toString(), 72 | amount: '1', 73 | customer_name: 'Njoku Test', 74 | customer_email: 'test@gmail.com', 75 | coin: 'BUSD', 76 | currency: 'USD', 77 | accept_partial_payment: true, 78 | }); 79 | expect(typeof response).toBe('object'); 80 | } catch (e) { 81 | console.log(e); 82 | } 83 | }); 84 | 85 | it('should confirm a transaction', async () => { 86 | const payload = { 87 | identifier: '0xa5138755f3EC3F68a51f15C6b2832Da6d7E98122', 88 | }; 89 | 90 | try { 91 | const response = await lazerpay.Payment.confirmPayment(payload); 92 | expect(typeof response).toBe('object'); 93 | } catch (e) { 94 | console.log(e); 95 | } 96 | }); 97 | 98 | it('should swap crypto for another crypto', async () => { 99 | const payload = { 100 | amount: 1, 101 | fromCoin: 'BUSD', 102 | toCoin: 'USDT', 103 | blockchain: 'Binance Smart Chain', 104 | }; 105 | try { 106 | const response = await lazerpay.Swap.cryptoSwap(payload); 107 | expect(typeof response).toBe('object'); 108 | } catch (e) { 109 | console.log(e); 110 | } 111 | }); 112 | 113 | it('should get crypto swap amount out', async () => { 114 | const payload = { 115 | amount: 1, 116 | fromCoin: 'BUSD', 117 | toCoin: 'USDT', 118 | blockchain: 'Binance Smart Chain', 119 | }; 120 | try { 121 | const response = await lazerpay.Swap.getCryptoSwapAmountOut(payload); 122 | expect(typeof response).toBe('object'); 123 | } catch (e) { 124 | console.log(e); 125 | } 126 | }); 127 | }); 128 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | #### The Lazerpay v1 NodeJS SDK 6 | 7 | ### How to use 8 | 9 | ```bash 10 | npm install lazerpay-node-sdk 11 | ``` 12 | 13 | Using yarn, 14 | 15 | ```bash 16 | yarn add lazerpay-node-sdk 17 | ``` 18 | 19 | ```javascript 20 | const Lazerpay = require('lazerpay-node-sdk'); 21 | 22 | const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY); 23 | ``` 24 | 25 | Use TEST API keys for testing, and LIVE API keys for production 26 | 27 | ## Lazerpay Methods exposed by the sdk 28 | 29 | **1**. **Payment** 30 | 31 | - Initialize Payment 32 | - Confirm Payment 33 | 34 | **2**. **Payout** 35 | 36 | - Crypto Payout 37 | - Bank Payout ~ This is coming to V2 38 | 39 | **3**. **Swap** 40 | 41 | - Crypto swap 42 | - Get Crypto Swap Amount Out 43 | 44 | **4**. **Payment Links** 45 | 46 | - Create payment links 47 | - Get all payment links 48 | - Get a single payment link 49 | - Update a payment Link 50 | 51 | **5**. **Onramp** 52 | - Get Rate 53 | - Get Accounts 54 | - Initiate 55 | 56 | **6**. **Misc** 57 | 58 | - Get all accepted coins 59 | - Get all accepted currencies 60 | - Get wallet balance 61 | 62 | 63 | ## Payment 64 | 65 | #### `Initialize Payment` 66 | 67 | This describes to allow your customers to initiate a crypto payment transfer. 68 | 69 | ```javascript 70 | const payment_tx = async () => { 71 | try { 72 | const transaction_payload = { 73 | reference: 'YOUR_REFERENCE', // Replace with a reference you generated 74 | customer_name: 'Njoku Emmanuel', 75 | customer_email: 'kalunjoku123@gmail.com', 76 | coin: 'BUSD', // BUSD, DAI, USDC or USDT 77 | currency: 'USD', // NGN, AED, GBP, EUR 78 | amount: '100', 79 | accept_partial_payment: true, // By default it's false 80 | metadata: { 81 | type: "Wallet fund" 82 | } // Metadata is an optional param 83 | }; 84 | 85 | const response = await lazerpay.Payment.initializePayment(transaction_payload); 86 | 87 | console.log(response); 88 | } catch (error) { 89 | console.log(error); 90 | } 91 | }; 92 | ``` 93 | 94 | #### `Confirm Payment` 95 | 96 | This describes to allow you confirm your customers transaction after payment has been made. 97 | 98 | ```javascript 99 | const confirm_tx = async () => { 100 | try { 101 | const payload = { 102 | identifier: 103 | 'address generated or the reference generated by you from initializing payment', 104 | }; 105 | 106 | const response = await lazerpay.Payment.confirmPayment(payload); 107 | 108 | console.log(response); 109 | } catch (error) { 110 | console.log(error); 111 | } 112 | }; 113 | ``` 114 | 115 | ## Transfer 116 | 117 | #### `Crypto Payout` 118 | 119 | This describes to allow you withdraw the crypto in their lazerpay balance to an external address 120 | 121 | ```javascript 122 | const crypto_payout_tx = async () => { 123 | const transaction_payload = { 124 | amount: 1, 125 | recipient: '0x0B4d358D349809037003F96A3593ff9015E89efA', // address must be a bep20 address 126 | coin: 'BUSD', 127 | blockchain: 'Binance Smart Chain', 128 | metadata: { 129 | id: "343243243223432" 130 | } // Metadata is an optional param 131 | }; 132 | try { 133 | const response = await lazerpay.Payout.transferCrypto(transaction_payload); 134 | console.log(response.error); 135 | } catch (e) { 136 | console.log(e); 137 | } 138 | }; 139 | ``` 140 | 141 | ## Swap 142 | 143 | #### `Crypto swap` 144 | 145 | This describes to allow you swap swap between two stable coins 146 | 147 | ```javascript 148 | const crypto_swap_tx = async () => { 149 | const swap_payload = { 150 | amount: 100, 151 | fromCoin: 'BUSD', 152 | toCoin: 'USDT', 153 | blockchain: 'Binance Smart Chain', 154 | metadata: { 155 | id: "343243243223432" 156 | } // Metadata is an optional param 157 | }; 158 | try { 159 | const response = await lazerpay.Swap.cryptoSwap(swap_payload); 160 | console.log(response.error); 161 | } catch (e) { 162 | console.log(e); 163 | } 164 | }; 165 | ``` 166 | 167 | #### `Get Crypto Swap Amount Out` 168 | 169 | This describes the amount you will receive on swap even before initiating the swap 170 | 171 | ```javascript 172 | const crypto_swap_tx = async () => { 173 | const swap_payload = { 174 | amount: 100, 175 | fromCoin: 'BUSD', 176 | toCoin: 'USDT', 177 | blockchain: 'Binance Smart Chain', 178 | }; 179 | try { 180 | const response = await lazerpay.Swap.getCryptoSwapAmountOut(swap_payload); 181 | console.log(response.error); 182 | } catch (e) { 183 | console.log(e); 184 | } 185 | }; 186 | ``` 187 | 188 | ## Payment Links 189 | 190 | #### `Create a payment link` 191 | 192 | This describes to allow you create a Payment link programatically 193 | 194 | ```javascript 195 | const create_paymentlink_tx = async () => { 196 | const transaction_payload = { 197 | title: 'Njoku Test', 198 | description: 'Testing this sdk', 199 | logo: 200 | 'https://assets.audiomack.com/fireboydml/bbbd8710eff038d4f603cc39ec94a6a6c2c5b6f4100b28d62557d10d87246f27.jpeg?width=340&height=340&max=true', 201 | currency: 'USD', 202 | type: 'standard', 203 | amount: 100 // Optional 204 | }; 205 | try { 206 | const response = await lazerpay.PaymentLinks.createPaymentLink( 207 | transaction_payload 208 | ); 209 | console.log(response); 210 | } catch (e) { 211 | console.log(e); 212 | } 213 | }; 214 | ``` 215 | 216 | #### `Update a payment link` 217 | 218 | This describes disabling or enabling a payment link by updating it 219 | 220 | ```javascript 221 | const transaction_payload = { 222 | identifier: '7f2vrd8n', 223 | status: 'inactive', // status should either be active or inactive 224 | }; 225 | 226 | const update_paymentLink = async () => { 227 | try { 228 | const response = await lazerpay.PaymentLinks.updatePaymentLink( 229 | transaction_payload 230 | ); 231 | console.log(response); 232 | } catch (e) { 233 | console.log(e); 234 | } 235 | }; 236 | ``` 237 | 238 | #### `Get all payment links` 239 | 240 | This describes to allow you get all Payment links created 241 | 242 | ```javascript 243 | const get_all_paymentlinks = async () => { 244 | try { 245 | const response = await lazerpay.PaymentLinks.getAllPaymentLinks(); 246 | console.log(response); 247 | } catch (e) { 248 | console.log(e); 249 | } 250 | }; 251 | ``` 252 | 253 | #### `Get a single payment link` 254 | 255 | This describes to allow you get a Payment link by it's identifier 256 | 257 | ```javascript 258 | const identifier = '7f2vrd8n'; 259 | 260 | const get_paymentlink = async () => { 261 | try { 262 | const response = await lazerpay.PaymentLinks.getPaymentLink(identifier); 263 | console.log(response); 264 | } catch (e) { 265 | console.log(e); 266 | } 267 | }; 268 | ``` 269 | 270 | ## Onramp 271 | 272 | #### `Get rate` 273 | 274 | This methods lets you get onramp rate 275 | 276 | ```javascript 277 | const get_onramp_rate = async () => { 278 | try { 279 | const response = await lazerpay.Onramp.getOnrampRate({ 280 | currency: 'NGN', 281 | }); 282 | console.log(response); 283 | } catch (error) { 284 | console.log(error); 285 | } 286 | }; 287 | ``` 288 | 289 | #### `Get Accounts` 290 | This methods lets get your onramp bank accounts 291 | ```javascript 292 | const get_onramp_accounts = async () => { 293 | try { 294 | const response = await lazer.Onramp.getOnrampAccounts(); 295 | console.log(response); 296 | } catch (error) { 297 | console.log(error); 298 | } 299 | }; 300 | ``` 301 | 302 | #### `Initiate` 303 | This methods lets you initiate onramp request 304 | ```javascript 305 | const initiate_onramp = async () => { 306 | try { 307 | const response = await lazer.Onramp.initiateOnramp({ 308 | amount: 10000, 309 | currency: 'NGN', 310 | accountId: "Account id", 311 | reference: "Payment reference", 312 | coin: 'USDT', 313 | }); 314 | console.log(response); 315 | } catch (error) { 316 | console.log(error); 317 | } 318 | }; 319 | ``` 320 | 321 | 322 | ## Misc 323 | 324 | #### `Get Accepted Coins` 325 | 326 | This gets the list of accepted cryptocurrencies on Lazerpay 327 | 328 | ```javascript 329 | const get_accepted_coins = async () => { 330 | try { 331 | const response = await lazerpay.Misc.getAcceptedCoins(); 332 | console.log(response); 333 | } catch (error) { 334 | console.log(error); 335 | } 336 | }; 337 | ``` 338 | 339 | 340 | #### `Get Accepted Currencies` 341 | 342 | This gets the list of accepted Currencies on Lazerpay 343 | 344 | ```javascript 345 | const get_accepted_currencies = async () => { 346 | try { 347 | const response = await lazerpay.Misc.getAcceptedCurrencies(); 348 | console.log(response); 349 | } catch (error) { 350 | console.log(error); 351 | } 352 | }; 353 | ``` 354 | 355 | 356 | #### `Get Wallet Balance` 357 | 358 | Get get wallet balance by specifying the coin 359 | 360 | ```javascript 361 | const get_wallet_balance = async () => { 362 | try { 363 | const coin = "USDT" // BUSD, DAI, USDC or USDT 364 | const response = await lazerpay.Misc.getWalletBalance(coin); 365 | console.log(response); 366 | } catch (error) { 367 | console.log(error); 368 | } 369 | }; 370 | ``` 371 | --------------------------------------------------------------------------------