The Payment Company Logo

Getting Started

Integration Samples

AES-256-CBC encryption guidance and integration examples in Node.js, PHP, Python, and Java for The Payment Company APIs.

SectionGetting Started
Topics02
Pathgetting-started / integration-examples

Integration Walkthroughs

The API uses AES-256-CBC encryption to protect sensitive data during transmission. Before sending the payload, encrypt it with your encryption key and a dynamically generated initialization vector (IV). The encrypted payload and IV must then be sent to the API so the server can decrypt the request correctly. This keeps sensitive information, such as card data, secure while in transit.

Each example demonstrates how to:

  • Encrypt the payload with AES-256-CBC.
  • Generate a random IV.
  • Include both the encrypted data and 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: "dean",
      email: "dean@gmail.com",
      address: "64 Hertingfordbury Rd",
      country: "GB",
      city: "Newport",
      state: "Newport",
      zip: "TF10 8DF",
      ip_address: "127.0.0.1",
      phone_number: "7654233212",
      amount: 100,
      currency: "GBP",
      card_number: "4111111111111111",
      card_expiry_month: "12",
      card_expiry_year: "2027",
      card_cvv: "029",
      redirect_url: "https://thepayment.company",
      webhook_url: "https://webhook.site/40be94f4-293e-4d84-a747-8c934557c0e3",
    };

  // 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://api.thepayment.company/api/v1/live/card";
  axios
      .post(
          url,
          { payload: encryptedPayload },
          {
            headers: {
                "Content-Type": "application/json",
                "Authorization":"Bearer TPC_TEST_62d221bba3bbeb4281ec48c70e3446bce31562c860eeb9dbc02f42ee"
            },
          }
      )
      .then((response) => {
          console.log("API Response:", response.data);
      })
      .catch((error) => {
          console.error("Error:", error.response);
      });
  

Encryption key

The encryption key is used with the examples above to encrypt and decrypt sensitive request payloads (AES-256-CBC). You need the same key on your server when building encrypted API calls.

Find it in the merchant dashboard under Settings → API Keys & Webhooks. Use that value wherever the sample code refers to your encryption key. Store it securely—never commit it to source control or expose it in client-side code.

On this page