Skip to main content

Payment With Crypto

Overview

The Banksy Payment SDK supports cryptocurrency payments, allowing users to pay with digital assets like USDT (Tether), USDC (USD Coin), or ETH (Ethereum).

This section provides guidance on how to implement and handle crypto payments within your application, supporting both USDT and USDC on the Ethereum and Polygon blockchains, along with native currency payments (ETH on Ethereum and POL on Polygon)

Payload Parameters

ParameterTypeRequiredDescription
amountnumberYesAmount to be charged
currencystringYesCurrency in which the amount to be charged
currencyType"crypto" | "fiat"YesCurrency type. Valid values are "fiat" or "crypto"
providerstringNoSpecify payment provider
customerNamestringNoCustomer name
successCallbackstringYesOn payment success portal will be redirected to this url
failureCallbackstringYesOn payment failure portal will be redirected to this url
externalClientIdstringNoExternal client id, you will receive this on webhook
isKycOptionalbooleanYesIndicates if KYC is optional. Must be true
customerEmailstringYesCustomer's email (required if isKycOptional is true).
customerPhonestringYesCustomer's phone number (required if isKycOptional is true).
contextanyNoAny extra context JSON data, you will receive this on webhook
cryptoobjectYesCryptocurrency configuration object
crypto.tokenNamestringYesName of the cryptocurrency token (e.g., "USDC", "USDT")
crypto.blockchainSymbolstringYesSymbol of the blockchain (e.g., "ETH", "POL")
crypto.blockchainNamestringYesName of the blockchain (e.g., "ethereum", "polygon")

Steps to Implement Payment with Crypto

Payment Process Example

1. Initialize the Banksy SDK

Set up the SDK with your API key and specify the environment (production or sandbox).

2. Create a Crypto Payment

Prepare the payment payload specifically for a crypto transaction, including details like the currency type, amount, and cryptocurrency details.

3. Handle Payment Success/Failure

Use the provided callback URLs to manage the outcome of the payment.

Code Example

import { Banksy } from "banksy-sdk";

// Step 1: Initialize the Banksy SDK
const apiKey = "your-client-key";
const banksy = new Banksy(apiKey); // Use "sandbox" for testing

// Step 2: Create a crypto payment
async function initiateCryptoPayment() {
const paymentPayload = {
currencyType: "banksy-pay", // Specifies that this is a Banksy Pay transaction
amount: 100, // Amount to charge in the specified currency
currency: "INR", // Currency for the transaction
successCallback: "http://localhost:3000/success", // URL to redirect on success
failureCallback: "http://localhost:3000/failure", // URL to redirect on failure
externalClientId: "cd99d68f-db08-485a-ac74-b8b64a55a3c2", // Optional external client ID
isKycOptional: true, // Specifies whether KYC is optional for this transaction
customerEmail: "parth25@nes.tech", // Customer's email
crypto: {
tokenName: "USDC", // Name of the cryptocurrency token
blockchainSymbol: "ETH",
blockchainName: "ethereum"
}
};


try {
const payment = await banksy.createPayment(paymentPayload);
console.log("Crypto Payment Created: ", payment);
// Redirect to the payment provider's gateway
window.location.href = payment.paymentLink;
} catch (error) {
console.error("Error creating crypto payment: ", error.message);
}
}

initiateCryptoPayment();

Supported Options

When configuring the crypto field in the payment payload, you can use the following options for tokenName,blockchainSymbol,blockchainName:

  • tokenName:

    • USDT (Tether)
    • USDC (USD Coin)
    • ETH (Ethereum, if using native currency)
    • POL (Polygon, if using native currency)
    • TRON (Tron, if using native currency)
    • AVAX (Avalanche, if using native currency)
    • ARB (Arbitrum, if using native currency)
    • BSC (Binance Smart Chain, if using native currency)
  • blockchainSymbol:

    • ETH (for transactions on the Ethereum blockchain)
    • POL (for transactions on the Polygon blockchain)
    • TRON (for transactions on the Tron blockchain)
    • AVAX (for transactions on the Avalanche blockchain)
    • ARB (for transactions on the Arbitrum blockchain)
    • BSC (for transactions on the Binance Smart Chain)
  • blockchainName:

    • ethereum (for transactions on the Ethereum blockchain)
    • polygon (for transactions on the Polygon blockchain)
    • tron (for transactions on the Tron blockchain)
    • avalanche (for transactions on the Avalanche blockchain)
    • arbitrum (for transactions on the Arbitrum blockchain)
    • binance-smart-chain (for transactions on the Binance Smart Chain)

Key Concepts

  • Currency Type: The currencyType is set to "banksy-pay" to specify that the payment will be processed using the Banksy Payment SDK.
  • Cryptocurrency Details: The crypto field includes the name of the cryptocurrency token, the blockchain symbol, and the blockchain name.
  • KYC Optionality: The isKycOptional flag can be set to true or false, depending on whether KYC is required for the transaction.

Handling Success and Failure

  • Success Callback: If the payment is successful, the user will be redirected to the URL specified in successCallback.
  • Failure Callback: If the payment fails, the user will be redirected to the URL specified in failureCallback.