PayAgency Logo
Crypto PaymentsCrypto payin

Crypto Payin API

This document provides a comprehensive guide to integrate with the Pay Agency's Crypto Payin API. The Crypto Payin API allows seamless cryptocurrency payment processing. The API endpoint and payload details are provided below, along with examples in multiple programming languages.

API Endpoint

POST https://backend.pay.agency/api/v1/live/crypto/payin

Parameters

ParameterTypeDescriptionRequired
first_nameStringFirst name of the payerYes
last_nameStringLast name of the payerYes
emailStringEmail address of the userYes
amountNumberTransaction amount in smallest currency unitYes
currencyStringCurrency code (ISO 4217 format)Yes
crypto_currencyStringCryptocurrency code (e.g., BTC, ETH, USDT)Yes
ip_addressStringIP address of the userYes
phone_numberStringPhone number of the payerYes
addressStringBilling addressYes
order_idStringUnique order from merchant sideYes
redirect_urlStringURL to redirect users after paymentYes
webhook_urlStringURL for server-to-server webhook notificationsNo
terminal_idStringConnector unique terminal_id (It's useful when you want to bypass all routing and cascading logic)No

Payload

The payload should be sent in JSON format. Below is the structure of the payload:

{
  "first_name": "James",
  "last_name": "Crypto",
  "email": "james.crypto@gmail.com",
  "amount": 100,
  "currency": "USD",
  "crypto_currency": "BTC",
  "ip_address": "127.0.0.1",
  "phone_number": "7654233212",
  "address": "64 Hertingfordbury Rd",
  "order_id": "CRYPTO_12524",
  "redirect_url": "https://pay.agency",
  "webhook_url": "https://pay.agency/webhook",
  "terminal_id": "T7244234",
}

Example Responses

Success Response

{
  "status": "SUCCESS",
  "message": "Payment processed successfully",
  "redirect_url": "https://example.com/success",
  "data": {
    "amount": 100.50,
    "currency": "USD",
    "order_id": "ORD123456",
    "transaction_id": "TXN789012",
    "customer": {
      "first_name": "John",
      "last_name": "Doe",
      "email": "john@example.com"
    },
    "crypto_currency": "BTC"
  }
}

Error Response

{
  "status": "FAILED",
  "message": "The cryptocurrency is not supported for this region.",
  "data": {
    "amount": 100,
    "currency": "USD",
    "crypto_currency": "BTC",
    "order_id": "CRYPTO_12524",
    "transaction_id": "CP0279243486998947",
    "customer": {
      "first_name": "James",
      "last_name": "Crypto",
      "email": "james.crypto@gmail.com"
    }
  }
}

Integration Examples

The API uses AES-256-CBC encryption to ensure secure transmission of sensitive data. Before sending the payload, you need to encrypt it using your encryption key and a dynamically generated initialization vector (IV). The encrypted payload and the IV must be sent to the API for proper decryption on the server side.

Each integration example demonstrates:

  • How to encrypt the payload using AES-256-CBC.
  • How to generate a random IV.
  • How to include both the encrypted data and the IV in the API request.
const { randomBytes, createCipheriv } = require("crypto");
const axios = require("axios");
 
// AES Encryption function
function encryptData(data, key) {
  const iv = randomBytes(16);
  const cipher = createCipheriv(
      "aes-256-cbc",
      Buffer.from(key, "utf-8"),
      iv
  );
  let encrypted = cipher.update(data, "utf-8");
  encrypted = Buffer.concat([encrypted, cipher.final()]);
  return iv.toString("hex") + ":" + encrypted.toString("hex");
}
 
const payload = {
  first_name: "James",
  last_name: "Crypto",
  email: "james.crypto@gmail.com",
  amount: 100,
  currency: "USD",
  crypto_currency: "BTC",
  ip_address: "127.0.0.1",
  phone_number: "7654233212",
  address: "64 Hertingfordbury Rd",
  order_id: "CRYPTO_12524",
  redirect_url: "https://pay.agency",
  webhook_url: "https://pay.agency/webhook",
  terminal_id: "T7244234",
};
 
const encryptionKey = "your-encryption-key-here";
const encryptedPayload = encryptData(JSON.stringify(payload), encryptionKey);
 
const response = await axios.post(
  "https://backend.pay.agency/api/v1/test/crypto/payin",
  { data: encryptedPayload },
  {
    headers: {
      "Content-Type": "application/json",
      "Authorization": "Bearer your-secret-key-here"
    }
  }
);
 
console.log(response.data);

On this page