PHP
This repository contains PHP scripts for interacting with the ZenoPay API. The scripts demonstrate how to create an order and check the status of an order.
Order Creation Script
This script sends a POST
request to the ZenoPay API
to create an order. It includes a basic error logging function to capture any issues during the request.
Script Components
API Endpoint
URL: https://api.zeno.africa
This is the endpoint for creating an order.
Order Data
The following data is sent in the POST
request:
Body request data
create_order
Integer
Set to 1
to initiate order creation.
buyer_email
String
Customer's email address.
buyer_name
String
Customer's full name.
buyer_phone
String
Customer's phone number.
amount
Interger
The amount to be paid (in smallest currency unit, e.g., cents).
account_id
String
Your unique account ID for authentication.
api_key
String
Your API key for authentication.
secret_key
String
Your secret key for authentication.
cURL Configuration
Request Format
To initiate a payment transaction, send a POST
request to the API
with a JSON
payload that includes the following parameters:
buyer_name
string
Full name of the buyer
"John Doe"
buyer_phone
string
Phone number of the buyer
"255742920510"
buyer_email
string
Email address of the buyer
"johndoe@example.com"
amount
float
Amount to be paid by the buyer in the transaction
3500.00
account_id
string
Unique account identifier for the transaction
"zp_12345xyz"
api_key
string
Your API key for authentication.
"api_key"
secret_key
string
Your secret key for authentication.
"secret_key"
The script uses cURL
to make the POST
request:
Error Logging Function
Logs errors to a file:
Error Handling
To enhance error handling:
Check cURL Errors:
Check HTTP Status Code:
Example Usage
Update Order Data: Replace placeholder values with actual information.
Save the Script: Save the file as
create_order.php
or another preferred filename.Run the Script: Execute it via command line or web server.
Notes
Ensure that
error_log.txt
is writable by the script.Handle sensitive information such as API keys and secret keys securely.
Order Status Check Script
Overview
This script checks the status of an order by sending a POST request to the ZenoPay API endpoint for order status.
Script Components
API Endpoint
URL: https://api.zeno.africa/order-status
This is the endpoint for checking the status of an order.
Post Data
The following data is sent in the POST
request:
check_status
Interger
Set to 1
to request the status.
order_id
String
The ID of the order whose status you want to check.
api_key
String
Your API key for authentication.
secret_key
String
Your secret key for authentication.
cURL Configuration
The script uses cURL to perform the POST
request:
Error Handling
Check
cURL
Errors:
Handle Response: Decode and format the
JSON
response based on the status:
Webhook Handling
After a payment is processed, ZenoPay
may send a webhook to notify you about the status of the transaction. You can use the following PHP
code to handle the webhook and log the incoming data for further processing or debugging.
Webhook PHP
Example:
PHP
Example:How the Webhook Works:
Receiving Webhook Data: This script listens for incoming POST requests (which ZenoPay sends for webhooks) and reads the raw data from the request body using
file_get_contents('php://input')
.Logging Webhook Data: The webhook data is logged to a file (
weblogs.txt
) along with a timestamp for reference. This log will help you debug and track transaction statuses or other data sent via the webhook.
Example Usage
Update Post Data: Replace placeholder values with actual data.
Save the Script: Save the file as
check_order_status.php
or another preferred filename.Run the Script: Execute it via command line or web server.
Notes
Ensure that
error_log.txt
is writable if you are using error logging.Secure sensitive information such as API keys and secret keys.
Feel free to modify or expand this as needed for your specific requirements.
Last updated