ZenoPay Card Php
ZenoPay Card API Integration
Overview
The ZenoPay Card API allows you to seamlessly integrate card payment functionality into your application. This API enables you to create and process payment transactions by sending buyer details, transaction amount, and a unique account identifier. The API will process the payment and return a response that indicates the success or failure of the transaction.
This repository contains a simple PHP implementation for interacting with the ZenoPay Card API, making it easy to integrate card payment services into your PHP-based applications.
Note: All amounts should be provided in TZS
(Tanzanian Shillings).
Requirements
PHP 7.0
or highercURL
extension enabled inPHP
An active
ZenoPay
account to obtainAPI
access credentials
Ensure that your PHP
environment meets the following prerequisites:
PHP 7.0
or higher is required for compatibility with modern API features.The
cURL
extension must be enabled to sendHTTP
requests to theZenoPay API
.
To check if cURL
is installed and enabled, you can run:
If the curl
module is not installed, you can install it. On Ubuntu, use the following command:
Installation
Step 1: Clone the Repository
Clone the repository or download the zenopay-card-api
folder to your project directory.
Step 2: Enable cURL Extension in PHP
Ensure that the cURL extension is enabled. If you're using Ubuntu, you can install it as follows:
For other systems, follow the appropriate method to enable cURL.
Step 3: Configure API Credentials
Open the provided PHP example file and update the buyer_name
, buyer_phone
, buyer_email
, amount
, and account_id
fields with the correct data. You’ll need to replace these values with real buyer information and the unique account ID provided by ZenoPay.
API Documentation
Endpoint
The ZenoPay Card API endpoint is:
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
1500.00
billing.country
string
country short code
"TZ , KE , US , UK , UG , etc"
account_id
string
Unique account identifier for the transaction
"acc_12345xyz"
webhook_url
string
URL to receive payment notifications
"https://example.com/webhook"
redirect_url
string
URL to redirect to after successful payment
"https://example.com/success"
cancel_url
string
URL to redirect to if the payment is cancelled
"https://example.com/cancel"
Note: All fields are required unless otherwise specified.
Response Format
The API responds with a JSON object. A successful response looks like this:
Response Parameters
status
string
The status of the transaction (success
or failure
)
"success"
transaction_id
string
The unique transaction identifier
"txn_abc123xyz"
message
string
A message describing the result of the transaction
"Payment processed successfully"
data
object
The transaction data that was sent with the request
See example above
Error Handling
If there's an issue with the request or the processing of the transaction, the response might look like:
Error Parameters
status
string
The error status (error
)
"error"
message
string
A description of the error
"Invalid account_id"
PHP Example Code
The following PHP code demonstrates how to interact with the ZenoPay Card API.
How to Use the Example
Edit the Parameters: Modify the
buyer_name
,buyer_phone
,buyer_email
,amount
,account_id
,redirect_url
, andcancel_url
fields in the$data
array with your own test data or real data from your application.Run the Script: Upload the script to a server that supports PHP and has cURL enabled. Then, execute it via a browser or a command-line tool to make the POST request to the ZenoPay API.
View the Response: After executing the script, the response from the API will be printed. If the transaction is successful, it will contain transaction details. Otherwise, it will include error information.
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
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.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Support
For any issues or questions, please contact us at support@zenopay.net
Final Thoughts
This guide provides an easy-to-follow approach to integrating ZenoPay Card API into your PHP-based applications. With this integration, you can begin processing payments securely and efficiently. Always ensure that the amount
, buyer_email
, and other parameters are properly sanitized and validated in your production environment to prevent security issues.
Last updated