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
Parameter | Type | Required | Description |
---|---|---|---|
amount | number | Yes | Amount to be charged |
currency | string | Yes | Currency in which the amount to be charged |
currencyType | "crypto" | "fiat" | Yes | Currency type. Valid values are "fiat" or "crypto" |
provider | string | No | Specify payment provider |
customerName | string | No | Customer name |
successCallback | string | Yes | On payment success portal will be redirected to this url |
failureCallback | string | Yes | On payment failure portal will be redirected to this url |
externalClientId | string | No | External client id, you will receive this on webhook |
isKycOptional | boolean | Yes | Indicates if KYC is optional. Must be true |
customerEmail | string | Yes | Customer's email (required if isKycOptional is true). |
customerPhone | string | Yes | Customer's phone number (required if isKycOptional is true). |
context | any | No | Any extra context JSON data, you will receive this on webhook |
crypto | object | Yes | Cryptocurrency configuration object |
crypto.tokenName | string | Yes | Name of the cryptocurrency token (e.g., "USDC", "USDT") |
crypto.blockchainSymbol | string | Yes | Symbol of the blockchain (e.g., "ETH", "POL") |
crypto.blockchainName | string | Yes | Name of the blockchain (e.g., "ethereum", "polygon") |
Steps to Implement Payment with Crypto
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 totrue
orfalse
, 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
.