zengapay/zengapay-php

一个用于与ZENGAPAY API交互的PHP库。

dev-master 2023-08-11 15:47 UTC

This package is auto-updated.

Last update: 2024-09-11 18:05:47 UTC


README

ZENGAPAY是一个支付网关服务,它使企业能够通过移动货币接收客户的支付,以及向任何移动货币账户持有人进行移动货币支付或购买移动话费或移动数据。

这是官方ZENGAPAY PHP客户端库

入门指南

先决条件

要使用API,您首先必须拥有一个ZENGAPAY账户。

我们拥有生产环境和测试服务器环境。测试服务器环境称为sandbox

建议您在sandbox中注册一个免费账户,通过访问设置→开发者设置获取API令牌,并在将应用程序指向生产环境之前在sandbox环境中测试所有API调用。

要将应用程序指向生产环境,您需要在生产环境中注册一个免费账户,然后仅进行一些小的更改。在大多数情况下,您只需更改API服务的URLAPI令牌

我们sandbox环境的API端点是

https://api.sandbox.zengapay.com/v1/

我们生产环境的API端点是

https://api.zengapay.com/v1/

安装

通过Composer/Packagist可以获取ZENGAPAY PHP库。因此,只需将此行添加到您的composer.json文件中即可

{
  "require": {
    "zengapay/zengapay-php": "*"
  }
}

或者

composer require zengapay/zengapay-php:dev-master

然后在您的PHP脚本中添加以下行

require 'vendor/autoload.php';

手动安装

或者,下载zengapay-php文件夹的内容,并将其解压缩到项目包含路径上的位置。

完成此操作后,按以下方式在您的脚本中包含库

require_once '/path/to/zengaPayAPI.php';

根据您选择的编程环境,您可以按以下方式实例化库

$zengaPayAPI = new zengaPayAPI("api.sandbox.zengapay.com"); // For Sandbox
$zengaPayAPI = new zengaPayAPI("api.zengapay.com"); // For Production

请注意:如果您没有明确指定环境,则默认情况下,库将使用生产环境

集合

ZENGAPAY使用“集合”一词来指代您从移动用户那里收到的资金(或收集的资金)。这区分了您收到的资金(集合)与您发送给移动用户的资金(转账)。

示例支付请求(收集)

requestPayment方法允许您请求/收集来自您的客户或任何移动货币账户持有人的资金,并将资金存入您的ZENGAPAY账户。

//require ZENGAPAY PHP Library
require_once '/path/to/zengaPayAPI.php';
   
//Instantiate the library
$zengaPayAPI = new zengaPayAPI();
$zengaPayAPI->setAPIKey("<YOUR_API_KEY>"); // Obtain this from your ZENGAPAY Dashboard (Settings -> Developer Settings)

$zengaPayAPI->msisdn = "256770000000";
$zengaPayAPI->amount = 15000;
$zengaPayAPI->external_reference = "Your Transfer Reference"; // eg #3001
$zengaPayAPI->narration = "Your Transfer Narration"; //eg Refund for Order #3001

$request = $zengaPayAPI->requestPayment();

if(isset($request->result->code) && ($request->result->code === 202))
{
    //Transaction was initiated successfully
    echo $request->result->transactionReference;  // You will need this to follow up on the status of the transaction in the next step
}
// If you wish, you may print to view the full response.
print_r($request);

获取单个集合(检查集合请求的状态)

要检索单个集合对象(检查集合请求的状态),请提供交易参考,并将返回一个集合对象。

//require ZENGAPAY PHP Library
require_once '/path/to/zengaPayAPI.php';
   
//Instantiate the library
$zengaPayAPI = new zengaPayAPI();   
$zengaPayAPI->setAPIKey("<YOUR_API_KEY>");  // Obtain this from your ZENGAPAY Dashboard (Settings -> Developer Settings)

$zengaPayAPI->transactionReference = "<YOUR_TRANSACTION_REFERENCE>"; 

$request = $zengaPayAPI->getSingleCollection(); 
    
if($request->result->data->transactionStatus === "SUCCEEDED")
{
    //Transaction was successful and funds were deposited onto your ZENGAPAY Account. You can go a head to update your system. 
}
//If you wish, you may print_r to view the full response
print_r($request);

获取所有集合

使用此方法检索您账户上的所有集合列表

//require ZENGAPAY PHP Library
require_once '/path/to/zengaPayAPI.php';
   
//Instantiate the library
$zengaPayAPI = new zengaPayAPI();
   
$zengaPayAPI->setAPIKey("<YOUR_API_KEY>"); // Obtain this from your ZENGAPAY Dashboard (Settings -> Developer Settings)

//$zengaPayAPI->status = ""; could be one of these:  FAILED,SUCCEEDED,PENDING
//$zengaPayAPI->per_page = 50;
//$zengaPayAPI->designation = ""; could be one of these : CHARGES,TRANSACTION
//$zengaPayAPI->start = "YYYY-MM-DD HH:MM:SS";
//$zengaPayAPI->end = "YYYY-MM-DD HH:MM:SS";

$request = $zengaPayAPI->getAllCollections();
  
print_r($request); 

转账

ZENGAPAY使用“转账”一词来指代您发送给移动用户的资金。这区分了您发送给移动用户的资金(即转账)与您从移动用户那里收到的资金(即集合)。

示例转账请求(支付/提款)

sendTransfer方法允许您向任何移动货币账户持有人发送资金或将您的资金(ZENGAPAY账户余额)提款到您自己的移动货币账户。

示例1:向非联系人发送

//require ZENGAPAY PHP Library
require_once '/path/to/zengaPayAPI.php';
   
//Instantiate the library
$zengaPayAPI = new zengaPayAPI();
$zengaPayAPI->setAPIKey("<YOUR_API_KEY>"); // Obtain this from your ZENGAPAY Dashboard (Settings -> Developer Settings)

$zengaPayAPI->msisdn = "256770000000";
$zengaPayAPI->amount = 1500;
$zengaPayAPI->external_reference = "Your Transfer Reference"; // #3001
$zengaPayAPI->narration = "Your Transfer Narration"; //eg Refund for Order #3001

$request = $zengaPayAPI->sendTransfer();

if(isset($request->result->code) && ($request->result->code === 202))
{
    //Transaction was initiated successfully
    echo $request->result->transactionReference;  // You will need this to follow up on the status of the transaction in the next step
}
// If you wish, you may print to view the full response. 
print_r($request);

示例2:向联系人发送

//require ZENGAPAY PHP Library
require_once '/path/to/zengaPayAPI.php';
   
//Instantiate the library
$zengaPayAPI = new zengaPayAPI();
$zengaPayAPI->setAPIKey("<YOUR_API_KEY>"); // Obtain this from your ZENGAPAY Dashboard (Settings -> Developer Settings)

$zengaPayAPI->amount = 1500;
$zengaPayAPI->narration = "Your Transfer Narration"; //eg Refund for Order #3001
$zengaPayAPI->external_reference = "Your Transfer Reference"; // #3001
$zengaPayAPI->use_contact = true;
$zengaPayAPI->contact_id = "9aa3bc79-583e-4eb5-93bf-0e894b07aec9";

$request = $zengaPayAPI->sendTransfer();

if(isset($request->result->code) && ($request->result->code === 202))
{
    //Transaction was initiated successfully
    echo $request->result->transactionReference;  // You will need this to follow up on the status of the transaction in the next step
}
// If you wish, you may print to view the full response.
print_r($request);

获取单个转账(检查转账请求的状态)

要检索单个转账对象(检查转账请求的状态),请提供事务引用,并将返回一个转账对象。

//require ZENGAPAY PHP Library
require_once '/path/to/zengaPayAPI.php';
    
//Instantiate the library
$zengaPayAPI = new zengaPayAPI();
    
$zengaPayAPI->setAPIKey("<YOUR_API_KEY>");
$transfer = $zengaPayAPI->getSingleTransfer("<YOUR_TRANSACTION_REFERENCE>");
  
if($transfer->result->data->transactionStatus === "SUCCEEDED")
{
   //Transaction was successful and funds were deducted from your ZENGAPAY Account. You can go a head to update your system. 
}
//If you wish, you may print_r to view the full response  
print_r($transfer);

获取所有转账

使用此方法检索您账户上所有转账的列表。

//require ZENGAPAY PHP Library
require_once '/path/to/zengaPayAPI.php';
   
//Instantiate the library
$zengaPayAPI = new zengaPayAPI();   
$zengaPayAPI->setAPIKey("<YOUR_API_KEY>"); // Obtain this from your ZENGAPAY Dashboard (Settings -> Developer Settings)

//$zengaPayAPI->status = ""; could be one of these:  FAILED,SUCCEEDED,PENDING
//$zengaPayAPI->per_page = 50;
//$zengaPayAPI->designation = ""; could be one of these : CHARGES,TRANSACTION
//$zengaPayAPI->start = "YYYY-MM-DD HH:MM:SS";
//$zengaPayAPI->end = "YYYY-MM-DD HH:MM:SS";

$transfers = $zengaPayAPI->getAllTransfers();
  
print_r($transfers);

联系人

联系人代表您可以向其转账资金或从中收款的人。联系人API方法允许您在账户中添加、检索、列出和更新联系人。

添加联系人

//require ZENGAPAY PHP Library
require_once '/path/to/zengaPayAPI.php';
   
//Instantiate the library
$zengaPayAPI = new zengaPayAPI();  
$zengaPayAPI->setAPIKey("<YOUR_API_KEY>"); // Obtain this from your ZENGAPAY Dashboard (Settings -> Developer Settings)

$zengaPayAPI->contact_first_name = "Denis";
//$zengaPayAPI->contact_last_name = "Ojok"; // Optional
$zengaPayAPI->contact_phone = "256770000000"; // eg #256770000000
$zengaPayAPI->contact_type = "Beneficiary"; //eg Beneficiary,Employee,Vendor,Other

$request = $zengaPayAPI->registerContact();

if(isset($request->result->code) && ($request->result->code === 201))
{
    //Contact was registered successfully
    echo $request->result->uuid;
}
// If you wish, you may print to view the full response.
print_r($request);

获取所有联系人

//require ZENGAPAY PHP Library
require_once '/path/to/zengaPayAPI.php';
   
//Instantiate the library
$zengaPayAPI = new zengaPayAPI();  
$zengaPayAPI->setAPIKey("<YOUR_API_KEY>"); // Obtain this from your ZENGAPAY Dashboard (Settings -> Developer Settings)

$contacts = $zengaPayAPI->getAllContacts();
// If you wish, you may print to view the full response.
print_r($contacts);

获取单个联系人

//require ZENGAPAY PHP Library
require_once '/path/to/zengaPayAPI.php';
   
//Instantiate the library
$zengaPayAPI = new zengaPayAPI();  
$zengaPayAPI->setAPIKey("<YOUR_API_KEY>"); // Obtain this from your ZENGAPAY Dashboard (Settings -> Developer Settings)

$zengaPayAPI->contact_uuid = "<YOUR_CONTACT_UUID>"; // eg 20a9e36e-075f-5b24-9f87-fa050c9be68f
$contact = $zengaPayAPI->getContact();

// If you wish, you may print to view the full response.
print_r($contact);

账户

账户余额

使用accountGetBalance方法获取您当前ZENGAPAY账户的余额。

//require ZENGAPAY PHP Library
require_once '/path/to/zengaPayAPI.php';
   
//Instantiate the library
$zengaPayAPI = new zengaPayAPI();
   
$zengaPayAPI->setAPIKey("<YOUR_API_KEY>"); // Obtain this from your ZENGAPAY Dashboard (Settings -> Developer Settings)
$balance = $zengaPayAPI->accountGetBalance();
  
print_r($balance);

账户报表

使用accountGetStatement方法检索您账户上执行的所有交易的列表(账户报表)。

//require ZENGAPAY PHP Library
require_once '/path/to/zengaPayAPI.php';
   
//Instantiate the library
$zengaPayAPI = new zengaPayAPI();
$zengaPayAPI->setAPIKey("<YOUR_API_KEY>"); // Obtain this from your ZENGAPAY Dashboard (Settings -> Developer Settings)

//$zengaPayAPI->status = ""; could be one of these:  FAILED,SUCCEEDED,PENDING
//$zengaPayAPI->per_page = 50;
//$zengaPayAPI->designation = ""; could be one of these : CHARGES,TRANSACTION,LIQUIDATION
//$zengaPayAPI->start = "YYYY-MM-DD HH:MM:SS";
//$zengaPayAPI->end = "YYYY-MM-DD HH:MM:SS";
//$zengapayAPI->currency_code = "" could be one of these: UGX-MTNMM,UGX-ATLMM 

$statement = $zengaPayAPI->accountGetStatement();
  
print_r($statement);

相关Webhooks

每当您发起的某个集合发生变化时,都会触发collection.successcollection.failed事件。例如,如果操作成功或失败。

每当您发起的某个转账发生变化时,都会触发transfer.successtransfer.failed事件。例如,如果操作成功或失败。

您可以为这种情况配置一个Web链接来接收通知。这将允许您在集合或转账完成或失败时自动响应。

有关更多信息,请参阅我们的Webhooks API文档。

您在示例文件夹中会发现更多可玩的内容。

就这样!您现在应该准备好使用ZENGAPAY PHP库了。

开发者文档

查看官方ZENGAPAY API文档。

https://developers.zengapay.com

构建工具

  • PHP - PHP编程语言

作者

许可证

本项目采用MIT许可证,详情请参阅LICENSE.md文件。