PayAgency Logo

Alternative Payment Methods (APM)

This document provides a comprehensive guide to integrate with the Pay Agency's Alternative Payment Methods (APM). The APM API allows seamless payment processing using various payment methods beyond traditional cards. 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/apm

Parameters

ParameterTypeDescriptionRequired
first_nameStringFirst name of the payerYes
last_nameStringLast name of the payerYes
emailStringEmail address of the userYes
addressStringBilling addressYes
countryStringCountry code (ISO 3166-1 alpha-3 format)Yes
cityStringCity of the payerYes
stateStringState of the payerYes
zipStringZIP or postal codeYes
ip_addressStringIP address of the userYes
phone_numberStringPhone number of the payerYes
amountNumberTransaction amount in smallest currency unitYes
currencyStringCurrency code (ISO 4217 format)Yes
redirect_urlStringURL to redirect users after paymentYes
webhook_urlStringURL for server-to-server webhook notificationsNo
order_idStringUnique order from merchant sideNo
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": "Karlo",
  "email": "james.karlo@gmail.com",
  "address": "Drovers,Llandrindod Wells",
  "country": "GB",
  "city": "London",
  "state": "PW",
  "zip": "LD1 5PT",
  "ip_address": "127.0.0.1",
  "phone_number": "6567453421",
  "amount": 10,
  "currency": "USD",
  "redirect_url": "https://pay.agency",
  "webhook_url": "https://webhook.url",
  "order_id": "Te52643",
  "terminal_id": "T56353"
}

Example Responses

Success Response

{
  "status": "REDIRECT",
  "message": "Please redirect user to complete the payment.",
  "redirect_url": "https://backend.pay.agency/api/v1/test/apm/checkout/AP0186280974141637",
  "data": {
    "amount": 10,
    "currency": "USD",
    "order_id": "Te52643",
    "transaction_id": "AP0186280974141637",
    "customer": {
      "first_name": "James",
      "last_name": "Karlo",
      "email": "james.karlo@gmail.com"
    },
    "refund": {
      "status": false,
      "refund_date": null
    },
    "chargeback": {
      "status": false,
      "chargeback_date": null
    }
  }
}

Error Response

{
  "status": "FAILED",
  "message": "The payment method is not available for this region.",
  "data": {
    "amount": 10,
    "currency": "USD",
    "order_id": "Te52643",
    "transaction_id": "AP0279243486998947",
    "customer": {
      "first_name": "James",
      "last_name": "Karlo",
      "email": "james.karlo@gmail.com"
    },
    "refund": {
      "status": false,
      "refund_date": null
    },
    "chargeback": {
      "status": false,
      "chargeback_date": null
    }
  }
}

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: "Karlo",
    email: "james.karlo@gmail.com",
    address: "Drovers,Llandrindod Wells",
    country: "GB",
    city: "London",
    state: "PW",
    zip: "LD1 5PT",
    ip_address: "127.0.0.1",
    phone_number: "6567453421",
    amount: 10,
    currency: "USD",
    redirect_url: "https://pay.agency",
    webhook_url: "https://webhook.url",
    order_id: "Te52643",
    terminal_id: "T56353"
  };
 
// Encryption key (replace with your actual key)
const encryptionKey = process.env.ENCRYPTION_KEY || "2542b322a40ada01489c5491fe379512";
 
// Encrypt the payload
const encryptedPayload = encryptData(JSON.stringify(payload), encryptionKey);
 
// API request
const url = "https://backend.pay.agency/api/v1/live/apm";
axios
    .post(
        url,
        { payload: encryptedPayload },
        {
          headers: {
              "Content-Type": "application/json",
              "Authorization":"Bearer FS_TEST_62d221bba3bbeb4281ec48c70e3446bce31562c860eeb9dbc02f42ee"
          },
        }
    )
    .then((response) => {
        console.log("API Response:", response.data);
    })
    .catch((error) => {
        console.error("Error:", error.response);
    });

Encryption Key in Settings

The encryption key, used for securing sensitive data, can be found on the Settings page. This key is essential for encryption and decryption processes, ensuring data confidentiality. Make sure to store it securely and avoid sharing it with unauthorized users.

On this page