Skip to content

LazerpayHQ/lazerpay-node-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Lazerpay v1 NodeJS SDK

How to use

npm install lazerpay-node-sdk

Using yarn,

yarn add lazerpay-node-sdk
const Lazerpay = require('lazerpay-node-sdk');

const lazerpay = new Lazerpay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

Use TEST API keys for testing, and LIVE API keys for production

Lazerpay Methods exposed by the sdk

1. Payment

  • Initialize Payment
  • Confirm Payment

2. Payout

  • Crypto Payout
  • Bank Payout ~ This is coming to V2

3. Swap

  • Crypto swap
  • Get Crypto Swap Amount Out

4. Payment Links

  • Create payment links
  • Get all payment links
  • Get a single payment link
  • Update a payment Link

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.

const payment_tx = async () => {
  try {
    const transaction_payload = {
      reference: 'YOUR_REFERENCE', // Replace with a reference you generated
      customer_name: 'Njoku Emmanuel',
      customer_email: '[email protected]',
      coin: 'BUSD', // BUSD, DAI, USDC or USDT
      currency: 'USD', // NGN, AED, GBP, EUR
      amount: '100',
      accept_partial_payment: true, // By default it's false
      metadata: { 
        type: "Wallet fund"
      } // Metadata is an optional param
    };

    const response = await lazerpay.Payment.initializePayment(transaction_payload);

    console.log(response);
  } catch (error) {
    console.log(error);
  }
};

Confirm Payment

This describes to allow you confirm your customers transaction after payment has been made.

const confirm_tx = async () => {
  try {
    const payload = {
      identifier:
        'address generated or the reference generated by you from initializing payment',
    };

    const response = await lazerpay.Payment.confirmPayment(payload);

    console.log(response);
  } catch (error) {
    console.log(error);
  }
};

Transfer

Crypto Payout

This describes to allow you withdraw the crypto in their lazerpay balance to an external address

const crypto_payout_tx = async () => {
  const transaction_payload = {
    amount: 1,
    recipient: '0x0B4d358D349809037003F96A3593ff9015E89efA', // address must be a bep20 address
    coin: 'BUSD',
    blockchain: 'Binance Smart Chain',
    metadata: {
      id: "343243243223432"
    } // Metadata is an optional param
  };
  try {
    const response = await lazerpay.Payout.transferCrypto(transaction_payload);
    console.log(response.error);
  } catch (e) {
    console.log(e);
  }
};

Swap

Crypto swap

This describes to allow you swap swap between two stable coins

const crypto_swap_tx = async () => {
  const swap_payload = {
      amount: 100,
      fromCoin: 'BUSD',
      toCoin: 'USDT',
      blockchain: 'Binance Smart Chain',
      metadata: {
      id: "343243243223432"
    } // Metadata is an optional param
  };
  try {
    const response = await lazerpay.Swap.cryptoSwap(swap_payload);
    console.log(response.error);
  } catch (e) {
    console.log(e);
  }
};

Get Crypto Swap Amount Out

This describes the amount you will receive on swap even before initiating the swap

const crypto_swap_tx = async () => {
  const swap_payload = {
      amount: 100,
      fromCoin: 'BUSD',
      toCoin: 'USDT',
      blockchain: 'Binance Smart Chain',
  };
  try {
    const response = await lazerpay.Swap.getCryptoSwapAmountOut(swap_payload);
    console.log(response.error);
  } catch (e) {
    console.log(e);
  }
};

Payment Links

Create a payment link

This describes to allow you create a Payment link programatically

const create_paymentlink_tx = async () => {
  const transaction_payload = {
    title: 'Njoku Test',
    description: 'Testing this sdk',
    logo:
      'https://assets.audiomack.com/fireboydml/bbbd8710eff038d4f603cc39ec94a6a6c2c5b6f4100b28d62557d10d87246f27.jpeg?width=340&height=340&max=true',
    currency: 'USD',
    type: 'standard',
    amount: 100 // Optional
  };
  try {
    const response = await lazerpay.PaymentLinks.createPaymentLink(
      transaction_payload
    );
    console.log(response);
  } catch (e) {
    console.log(e);
  }
};

Update a payment link

This describes disabling or enabling a payment link by updating it

const transaction_payload = {
  identifier: '7f2vrd8n',
  status: 'inactive', // status should either be active or inactive
};

const update_paymentLink = async () => {
  try {
    const response = await lazerpay.PaymentLinks.updatePaymentLink(
      transaction_payload
    );
    console.log(response);
  } catch (e) {
    console.log(e);
  }
};

Get all payment links

This describes to allow you get all Payment links created

const get_all_paymentlinks = async () => {
  try {
    const response = await lazerpay.PaymentLinks.getAllPaymentLinks();
    console.log(response);
  } catch (e) {
    console.log(e);
  }
};

Get a single payment link

This describes to allow you get a Payment link by it's identifier

const identifier = '7f2vrd8n';

const get_paymentlink = async () => {
  try {
    const response = await lazerpay.PaymentLinks.getPaymentLink(identifier);
    console.log(response);
  } catch (e) {
    console.log(e);
  }
};

Onramp

Get rate

This methods lets you get onramp rate

 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

 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

 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

const get_accepted_coins = async () => {
  try {
    const response = await lazerpay.Misc.getAcceptedCoins();
    console.log(response);
  } catch (error) {
    console.log(error);
  }
};

Get Accepted Currencies

This gets the list of accepted Currencies on Lazerpay

const get_accepted_currencies = async () => {
  try {
    const response = await lazerpay.Misc.getAcceptedCurrencies();
    console.log(response);
  } catch (error) {
    console.log(error);
  }
};

Get Wallet Balance

Get get wallet balance by specifying the coin

const get_wallet_balance = async () => {
  try {
    const coin = "USDT" // BUSD, DAI, USDC or USDT
    const response = await lazerpay.Misc.getWalletBalance(coin);
    console.log(response);
  } catch (error) {
    console.log(error);
  }
};