PHP code example of zenopay / zenopay-php

1. Go to this page and download the library: Download zenopay/zenopay-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zenopay / zenopay-php example snippets


$url = "https://api.zeno.africa";

// Data to send for creating the order 
$orderData = [
    'buyer_email' => 'CUSTOMER_EMAIL',
    'buyer_name' => 'CUSTOMER_NAME',
    'buyer_phone' => 'CUSTOMER_PHONE_NUMBER',
    'amount' => 10000, // AMOUNT_TO_BE_PAID
    'account_id' => 'YOUR_ACCOUNT_ID',
    'api_key' => 'YOUR_API_KEY',
    'webhook_url' => 'https://example.com/webhook',
    'secret_key' => 'YOUR_SECRET_KEY',
    'metadata' => json_encode([
        "product_id" => "12345",
        "color" => "blue",
        "size" => "L",
        "custom_notes" => "Please gift-wrap this item."
    ])
];


$options = [
    'http' => [
        'method'  => 'POST',
        'header'  => "Content-Type: application/x-www-form-urlencoded\r\n",
        'content' => $queryString,
    ],
];

function logError($message) 
{
    file_put_contents('error_log.txt', $message . "\n", FILE_APPEND);
}

   if ($response === false) {
       logError('cURL Error: ' . curl_error($ch));
   }
   

   $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
   if ($httpCode != 200) {
       logError('HTTP Error: ' . $httpCode);
   }
   

$endpointUrl = "https://api.zeno.africa/order-status";

// Order ID that you want to check the status for
$order_id = "66d5e374ccaab";

// Data to be sent in the POST request
$postData = [
    'check_status' => 1,
    'order_id' => $order_id,
    'api_key' => 'YOUR_API_KEY',
    'secret_key' => 'YOUR_SECRET_KEY'
];

$options = [
    'http' => [
        'method'  => 'POST',
        'header'  => "Content-Type: application/x-www-form-urlencoded\r\n",
        'content' => $queryString,
    ],
];

if (curl_errno($ch)) {
    echo json_encode([
        "status" => "error",
        "message" => 'cURL error: ' . curl_error($ch)
    ]);
} else {
    $responseData = json_decode($response, true);
    if ($responseData['status'] === 'success') {
        echo json_encode([
            "status" => "success",
            "order_id" => $responseData['order_id'],
            "message" => $responseData['message'],
            "payment_status" => $responseData['payment_status']
        ]);
    } else {
        echo json_encode([
            "status" => "error",
            "message" => $responseData['message']
        ]);
    }
}
curl_close($ch);

   if (curl_errno($ch)) {
       echo json_encode([
           "status" => "error",
           "message" => 'cURL error: ' . curl_error($ch)
       ]);
   }
   

   if ($responseData['status'] === 'success') {
       echo json_encode([
           "status" => "success",
           "order_id" => $responseData['order_id'],
           "message" => $responseData['message'],
           "payment_status" => $responseData['payment_status']
       ]);
   } else {
       echo json_encode([
           "status" => "error",
           "message" => $responseData['message']
       ]);
   }
   



// Webhook handling
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Get the raw POST data from the incoming webhook
    $data = file_get_contents('php://input');
    
    // Log the raw data with a timestamp
    file_put_contents('weblogs.txt', "[" . date('Y-m-d H:i:s') . "] WebHook Data: ".$data."\n", FILE_APPEND);
}