Skip to main content

Overview

This quickstart guide will walk you through:
  1. Installing the InventPay SDK
  2. Getting your API credentials
  3. Creating your first payment
  4. Checking payment status
By the end of this guide, you’ll have a working integration that can accept cryptocurrency payments.

Prerequisites

Before you begin, make sure you have:
  • An InventPay account (sign up at inventpay.io)
  • Node.js 14+ (for JavaScript/TypeScript) or Python 3.7+ (for Python)
  • Your API key from the InventPay Dashboard

Step 1: Install the SDK

Choose your preferred language and install the InventPay SDK:
npm install inventpay

Step 2: Get Your API Key

  1. Log in to your InventPay Dashboard
  2. Navigate to SettingsAPI Keys
  3. Click Generate New API Key
  4. Copy your API key and store it securely
Never expose your API key in client-side code or public repositories. Always use environment variables to store sensitive credentials.

Step 3: Initialize the SDK

Set up the SDK with your API key:
import { PaymentSDK } from "inventpay";

const sdk = new PaymentSDK({
  apiKey: process.env.INVENTPAY_API_KEY, // Use environment variables
});

// Test the connection
const connection = await sdk.testConnection();
console.log(connection.message); // "API connection successful"
Testing the connection is optional but recommended to verify your API key is valid before proceeding.

Step 4: Create Your First Payment

Now let’s create a payment request. You have two options:

Option A: Fixed Currency Payment

Create a payment for a specific cryptocurrency (customer must pay in that currency):
const payment = await sdk.createPayment({
  amount: 29.99,
  amountCurrency: "USD",
  currency: "USDT_BEP20", // or BTC, ETH, LTC, USDT_ERC20
  orderId: "order-12345",
  description: "Premium Plan Subscription",
  expirationMinutes: 30, // Optional: payment expires in 30 minutes
});

console.log("Payment Address:", payment.data.address);
console.log("Amount Due:", payment.data.amount);
console.log("Invoice URL:", payment.data.invoiceUrl);
console.log("Payment ID:", payment.data.paymentId);

Option B: Multi-Currency Invoice

Create an invoice where customers can choose their preferred cryptocurrency:
const invoice = await sdk.createInvoice({
  amount: 49.99,
  amountCurrency: "USD",
  orderId: "order-67890",
  description: "E-commerce Purchase",
  expirationMinutes: 60,
});

console.log("Invoice URL:", invoice.data.invoiceUrl);
console.log("Payment ID:", invoice.data.paymentId);
console.log("Available currencies:", Object.keys(invoice.data.conversionRates));
// Output: ['BTC', 'ETH', 'LTC', 'USDT_ERC20', 'USDT_BEP20']
The invoiceUrl is a hosted payment page where your customer can complete the payment. You can redirect them to this URL or display it in an iframe.

Step 5: Check Payment Status

You can check the status of any payment at any time:
// This endpoint is public - no API key required
const status = await sdk.getPaymentStatus("your-payment-id");

console.log("Status:", status.status); // PENDING, COMPLETED, EXPIRED, FAILED
console.log("Current Balance:", status.currentBalance);
console.log("Confirmations:", status.confirmations);

// Check if payment is complete
if (status.status === "COMPLETED") {
  console.log("Payment received and confirmed!");
}

Payment Status Values

StatusDescription
PENDINGWaiting for payment to be received
COMPLETEDPayment received and confirmed
EXPIREDPayment window expired without receiving full payment
FAILEDPayment failed due to an error
Instead of polling for payment status, configure webhooks to receive real-time notifications:
await sdk.configureWebhook({
  webhookUrl: "https://yourapp.com/api/webhooks/inventpay",
});

// Test webhook delivery
const testResult = await sdk.testWebhook();
console.log(testResult.message); // "Webhook test successful"
Learn more about handling webhooks in the Webhooks Guide.

Next Steps

Congratulations! You’ve successfully created your first crypto payment with InventPay. Here’s what to explore next:

Supported Cryptocurrencies

InventPay supports the following cryptocurrencies:
CurrencyNetworkCodeDescription
BitcoinBitcoinBTCNative Bitcoin network
EthereumEthereumETHNative Ethereum network
LitecoinLitecoinLTCNative Litecoin network
TetherEthereum (ERC-20)USDT_ERC20USDT on Ethereum
TetherBSC (BEP-20)USDT_BEP20USDT on Binance Smart Chain

Complete Example

Here’s a complete example showing payment creation and status checking:
import { PaymentSDK } from "inventpay";

async function createAndMonitorPayment() {
  const sdk = new PaymentSDK({
    apiKey: process.env.INVENTPAY_API_KEY,
  });

  try {
    // Create payment
    const payment = await sdk.createPayment({
      amount: 50,
      amountCurrency: "USD",
      currency: "USDT_BEP20",
      orderId: `order-${Date.now()}`,
      description: "Product Purchase",
    });

    console.log("Payment created!");
    console.log("Send customer to:", payment.data.invoiceUrl);

    // Monitor payment status
    const paymentId = payment.data.paymentId;

    // Poll every 30 seconds (in production, use webhooks instead)
    const checkStatus = setInterval(async () => {
      const status = await sdk.getPaymentStatus(paymentId);

      console.log(`Status: ${status.status}`);

      if (status.status === "COMPLETED") {
        console.log("Payment received!");
        clearInterval(checkStatus);
      } else if (status.status === "EXPIRED" || status.status === "FAILED") {
        console.log("Payment not completed");
        clearInterval(checkStatus);
      }
    }, 30000);
  } catch (error) {
    console.error("Error:", error.message);
  }
}

createAndMonitorPayment();
The example above uses polling for demonstration purposes. In production, always use webhooks for real-time notifications instead of polling.

Troubleshooting

Authentication Errors

If you get a 401 Unauthorized error:
  • Verify your API key is correct
  • Ensure the API key is properly set in environment variables
  • Check that the API key hasn’t been revoked in the dashboard

Payment Not Found

If you get a 404 error when checking payment status:
  • Verify the payment ID is correct
  • Ensure the payment was created successfully
  • Check that you’re using the correct environment (test/production)

Timeout Errors

If requests are timing out:
  • Check your internet connection
  • Verify the InventPay API status
  • Try increasing the timeout value in SDK configuration

Need Help?