🉑Accept Payments

Inline Checkout - Popup

The Lazerpay popup provides a convenient and easy way for developers to accept payments on the web. You can start receiving payments on your website with the checkout easily.

1. Add the Inline Checkout

Add the inline checkout to your website using a script tag, it is delivered through a reliable CDN.

<script>https://cdn.jsdelivr.net/gh/LazerPay-Finance/checkout-build@main/[email protected]/dist/index.min.js</script>

2. Collect user Details

To receive payments you will need to pass some parameters which include some functions and optional customer information. They include:

PropsFUNCTIONALITYPriorityType

name

Customers Name

Optional

String

email

Customer email

Optional

String

amount

Customer amount to pay(in USD, AED, GBP, EUR, NGN)

Required

String | Number

reference

Unique case sensitive transaction reference. If you do not pass this parameter, Lazerpay will generate a unique reference for you.

Optional

String | Number

acceptPartialPayment

If you want accept partial payment from customers, By default it's false

Optional

Boolean

key

Lazerpay key. Get you public key from your Lazerpay dashboard. Testnet public keys begin with "pk_test_" and mainnet keys begin with "pk_live_".

Required

String

currency

The currency amount is denominated in. Can be USD, GBP, EUR, AED or NGN.

Required

String

metadata

Stringified JSON object of custom data. eg {type: "Wallet fund"}

Optional

Object

onClose

The function called when the payment modal closes.

Optional

Function

onSuccess

The function called after the payment is confirmed.

Optional

Function

onError

The function that is called if an error occurs during payment confirmation.

Optional

Function

When you add the inline checkout script, you immediately have access to the LazerCheckout function. Pass the information you get in step 2 to the function in an object inside the payWithLazerpay function.

The customer information can be retrieved from your database if you already have it stored, or from a form like in the example below:

<form id="paymentForm">
  <div class="form-group">
    <label for="name">Name</label>
    <input type="text" id="name" />
  </div>
  <div class="form-group">
    <label for="email">Email Address</label>
    <input type="email" id="email-address" />
  </div>
  </div>
  <div class="form-group">
    <label for="amount">Amount</label>
    <input type="number" id="amount" required />
  </div>
  <div class="form-submit">
    <button type="submit" onclick="payWithLazerpay()"> Pay with Lazerpay </button>
  </div>
</form>

<script>
  https: //cdn.jsdelivr.net/gh/LazerPay-Finance/checkout-build@main/[email protected]/dist/index.min.js
</script>

<script>
const paymentForm = document.getElementById('paymentForm');

paymentForm.addEventListener("submit", payWithLazerpay, false);

function payWithLazerpay(e){
  e.preventDefault();
  LazerCheckout({
     reference: 'W6b8hV55l0435t3545435',
     name: document.querySelector("#name").value,
     email: document.querySelector("#email-address").value,
     amount: document.querySelector("#amount").value,
     key: "pk_test_xG0EjfzUsGIUDpMeQKZFItGFEBtR5SzHzsqwrzlsdADVzPrjZb", 
     currency: "USD",
     acceptPartialPayment: true // By default it's false
     onClose: (data)=>{
     },
     onSuccess: (data)=>{
     },
     onError: (data)=>{
     }
  })
}
</script>

In this sample, notice how:

  1. The Lazerpay inline javascript is included using a script tag. This is how you import Lazerpay into your code.

  2. The name and email here can be optional. The PopUp will provide those fields to the customers

  3. The Pay With Lazerpay button has been tied to an onClick function called payWithLazerpay. This is the action that causes the Lazerpay popup to load.

Initialize Payment API

The initialize payment endpoint allows you to initiate payment directly to Lazerpay by passing in the payment details

POST https://api.lazerpay.engineering/api/v1/transaction/initialize

Headers

NameTypeDescription

x-api-key*

String

YOUR_PUBLIC_KEY

Request Body

NameTypeDescription

reference

String

YOUR_REFERENCE

customer_name*

String

Your Customer's name

customer_email*

String

Your Customer's email

coin*

String

Stablecoins you want your customers to pay you in.

currency*

String

Currency should be in the currency you accept on your store, or application

amount*

String | Number

The amount you want to charge the customer in the currency specified above

accept_partial_payment

Boolean

This parameter is set to "false" by default. When you want to accept partial payments and ensure customers complete the required amount they are supposed to pay, it should be set to true

{
  "message": "Transaction initialized successfully",
  "status": "success",
  "data": {
    "reference": "wfqweweqrtwerwrtwer45354545",
    "businessName": "Lazerpay Finance",
    "businessEmail": "[email protected]",
    "businessLogo": "https://res.cloudinary.com/lazer/image/upload/v1637512933/logo-default_ufyz0x.svg",
    "customerName": "Abdulfatai Suleiman",
    "customerEmail": "[email protected]",
    "address": "0xcA20e971400F81F97fEc5416A963e8FA7F81aaE3",
    "coin": "BUSD",
    "cryptoAmount": 50.5,
    "currency": "USD",
    "fiatAmount": 50,
    "feeInCrypto": 0.5,
    "network": "testnet",
    "acceptPartialPayment": true
  },
  "statusCode": 201
}

Important Note

  1. The coin field must either be "BUSD", "DAI", "USDT", or "USDC".

  2. It's ideal to generate a unique reference from your system for every transaction to avoid duplicate attempts.

  3. The accept_partial_payment field is used to enforce payment completion by your customers. A scenario is when a customer is trying to pay for a service worth a fixed amount of $100 USD. When accept_partial_payment is set to false, the customer must pay the exact amount before the funds will be sent to you. Read more about Partial Payments here

  4. The amount field should be in your fiat currency. The currencies we support are USD, AED, GBP, EUR and NGN. Please reach out to [email protected] if you would want us to support a currency.

  5. The amount during initialization is converted to the coin equivalent of the currency specified.

Never call the Lazerpay API directly from your frontend to avoid exposing your secret key on the frontend. All requests to the Lazerpay API should be initiated from your server, and your frontend gets the response from your server.

Lazerpay's NodeJS SDK

The SDK allows you to initialise a payment transaction and to confirm payment. It's an NPM package so you can use it in a node environment.

Here's a sample code on how to use the NodeJS SDK

const LazerPay = require('lazerpay-node-sdk');

const lazerpay = new LazerPay(LAZER_PUBLIC_KEY, LAZER_SECRET_KEY);

const payment_tx = async () => {
  try {
     const transaction_payload = {
      reference: 'W6b8hV55l0435t3545435', // Replace with a reference you generated
      customer_name: 'iamnotstatic.eth',
      customer_email: '[email protected]',
      coin: 'USDC',
      currency: 'USD',
      amount: '100',
      acceptPartialPayment: true // By default it's false
    };

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

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

Response Object

{
   "reference": "wfqweweqrtwerwrtwer45354545",
    "businessName": "Lazerpay Finance",
    "businessEmail": "[email protected]",
    "businessLogo": "https://res.cloudinary.com/lazer/image/upload/v1637512933/logo-default_ufyz0x.svg",
    "customerName": "Abdulfatai Suleiman",
    "customerEmail": "[email protected]",
    "address": "0xcA20e971400F81F97fEc5416A963e8FA7F81aaE3",
    "coin": "BUSD",
    "cryptoAmount": 50.5,
    "currency": "USD",
    "fiatAmount": 50,
    "feeInCrypto": 0.5,
    "fiatRate": 0.9988,
    "cryptoRate": 1.001,
    "network": "testnet",
    "acceptPartialPayment": true
}

When a payment is successful, Lazerpay sends a DEPOSIT_TRANSACTION webhook event to the webhook URL that you provide. It is highly recommended that you use webhooks to confirm the payment status before delivering value to your customers.

Last updated