Skip to main content

Checkout SDK

Learn how to harness our collections of tools when integrating payment into your application

Kidapay Checkout SDK

Server-side calls to this API must be done from a secured and trusted environment (e.g. via your backend server, not directly from frontend web).

The Kidapay Checkout SDK provides a collection of methods that allow you accept payment in your website or application.

Introduction

The KidaPay Checkout SDK is an official JavaScript/TypeScript toolkit designed to let developers seamlessly integrate KidaPay’s cryptocurrency payment solutions into their websites or applications. It provides methods for initiating payments, with customizable UI components and robust backend communication — all while handling the complexities of blockchain transactions behind the scenes.

Installation

KidaPay Checkout SDK can be included in your application via CDN, NPM or Yarn:

<script src="https://unpkg.com/kidapay-checkout-sdk@latest/dist/index.umd.js"></script>

If you used NPM or Yarn, ensure you import the library as shown below:

Initialization

// Add for NPM, Yarn
import { Kidapay } from 'kidapay-checkout-sdk';

const kidapay = new Kidapay();

Kidapay object

The Kidapay object gives access to the methods and interfaces available in Kidapay Checkout SDK. It exposes methods, alongside configuration options that can help you accept crypto payment seamlessly in your web application. The methods exposed by the Kidapay object include:

  1. checkout(options: CheckoutOptions): Creates and opens a checkout session (browser only).

  2. createCheckout(request: CreateCheckoutRequest): Creates a checkout session (backend).

  3. getCheckout(checkoutId: string): Retrieves checkout details.

Callbacks

The KidaPay object also exposes callbacks that can be used to monitor certain states during the lifecycle of a transaction.

onSuccess

This is called when the customer successfully completes a transaction. It returns an instance of a transaction object:

OptionTypeDescription
idStringUnique identifier for the checkout session.
order_idStringUnique identifier for the merchant’s order associated with this payment.
pay_amountStringAmount the customer paid (in the crypto currency they selected).
pay_currencyStringThe cryptocurrency used for payment (e.g., BTC, ETH, USDT).
pay_networkStringThe blockchain network used for the payment (e.g., Ethereum, Algo, BTC).
receieve_currencyString | nullThe currency the merchant will receive after conversion, if applicable (e.g., USDT).
receieve_amountString | nullThe amount the merchant will receive in the settlement currency.
addressStringThe crypto wallet address to which the customer sent the payment.
statusStringCurrent payment status (e.g., NEW, SUCCESSFUL, FAILED, EXPIRED, CANCELLED, REFUNDED, PARTIALLY_PAID).

onError

This is called when there is an issue loading the transaction.

interface PaymentError {
code: string; // Short error code (e.g., "INVALID_ADDRESS")
message: string; // Human-readable error description
checkoutId?: string; // The checkout session ID (if available)
details?: any; // Extra context (e.g., validation errors, network logs)
}

onCancel

This is called when the transaction is cancelled. It returns no response.

onCancel: () => {
console.log("User cancelled")
}

onPending

This is called when the checkout has been initialized but no payment has been detected yet, or a payment is still awaiting blockchain confirmations.

OptionTypeDescription
idStringUnique identifier for the checkout session.
order_idStringUnique identifier for the merchant’s order associated with this payment.
pay_amountStringAmount the customer paid in the chosen cryptocurrency.
pay_currencyStringThe cryptocurrency used for payment (e.g., BTC, ETH, USDT).
pay_networkStringThe blockchain network used (e.g., Ethereum, Bitcoin, Polygon).
receieve_currencyString | nullSettlement currency the merchant receives after conversion (nullable).
receieve_amountString | nullSettlement amount the merchant receives (nullable).
addressStringCrypto wallet address used for the payment.
statusStringCurrent payment status (e.g., NEW, SUCCESSFUL, FAILED, EXPIRED, CANCELLED, REFUNDED, PARTIALLY_PAID).

onPartiallyPaid

OptionTypeDescription
idStringUnique identifier for the checkout session.
order_idStringUnique identifier for the merchant’s order associated with this payment.
pay_amountStringAmount the customer has paid so far (partial payment in the selected crypto currency).
pay_currencyStringThe cryptocurrency used for payment (e.g., BTC, ETH, USDT).
pay_networkStringThe blockchain network used for the payment (e.g., Ethereum, Algo, BTC).
receieve_currencyString | nullThe currency the merchant will receive after conversion, if applicable (e.g., USDT).
receieve_amountString | nullThe amount the merchant will receive in the settlement currency for the partial payment.
addressStringThe crypto wallet address to which the customer sent the partial payment.
statusStringCurrent payment status (e.g., PARTIALLY_PAID while awaiting full payment).

Display Modes

Kidapay provides flexible display modes so you can decide how customers interact with the payment interface.

Popup (Default)

Opens the payment interface in a popup window.

await kidapay.checkout({
amount: 10.00,
currency: 'USD',
displayMode: 'popup'
// ... other options
});

Iframe

Embeds the payment interface in an overlay iframe.

await kidapay.checkout({
amount: 10.00,
currency: 'USD',
displayMode: 'iframe'
// ... other options
});

Redirect

Redirects the user to the payment page.

await kidapay.checkout({
amount: 10.00,
currency: 'USD',
displayMode: 'redirect'
// ... other options
});

Supported Currencies

Kidapay enables merchants to accept payments in cryptocurrencies and withdraw funds in either crypto or fiat, depending on their preference.

This dual support allows customers to pay seamlessly with digital assets, while merchants enjoy the flexibility of withdrawing in either their local fiat currency or preferred crypto.

TypeUsageSupported Currencies
FiatWithdrawals only

KES (Kenyan Shilling), NGN (Nigerian Naira), ZAR (South African Rand), GHS (Ghanaian Cedi), LRD (Liberian Dollar), EUR (Euro), USD (US Dollar)

CryptoPayments & Withdrawals

BTC (Bitcoin), LTC (Litecoin), ETH (Ethereum), SOL (Solana), USDC (USD Coin), USDT (Tether), TRON (Tron), ALGO (Algorand), …and more

Error Handling

The SDK provides comprehensive error handling with specific error types:

  • ValidationError: Invalid input parameters

  • ApiError: API request failures

  • NetworkError: Network connectivity issues

  • KidapayError: Base error class

Environment Variables

When using the SDK in a backend environment, ensure you set the following environment variables:

KIDAPAY_SECRET_KEY=sk_test_your_secret_key_here
KIDAPAY_API_KEY=pk_test_your_public_key_here

Testing

The SDK includes comprehensive test coverage:

# Run tests

npm test

# Run tests with coverage

npm run test:coverage

# Run tests in watch mode

npm run test:watch

Development

The SDK provides scripts to streamline both local development and production builds.

# Start backend development server

npm run dev:backend

# Start frontend development server

npm run dev:server

TypeScript Support

The SDK is written in TypeScript and includes full type definitions:

import { Kidapay, CheckoutOptions, PaymentSuccessData } from 'kidapay-checkout-sdk';

const kidapay = new Kidapay({
apiKey: 'your-api-key',
environment: 'sandbox'
});

const options: CheckoutOptions = {
amount: 10.00,
currency: 'USD',
onSuccess: (data: PaymentSuccessData) => {
console.log('Payment successful:', data.transactionHash);
}
};

Contributing

We welcome contributions! Please see our Contributing Guide for details.

  • Fork the repository
  • Create your feature branch (git checkout -b feature/amazing-feature)
  • Commit your changes (git commit -m 'Add some amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request