yo-uganda/yopaymentsphp8x

A PHP 8.x Library 交互 Yo! Payments API。

1.2 2024-07-23 13:03 UTC

This package is auto-updated.

Last update: 2024-09-23 13:38:54 UTC


README

Yo! Payments 是一款革命性的移动支付网关服务。Yo! Payments 使企业能够通过移动货币从客户那里接收付款,以及向任何移动货币账户持有人进行移动货币付款。Yo! Payments 还能够直接向用户发送移动通话信用(“话费”)。

Yo! Payments API PHP 库是一个 PHP 库,可以包含到您的 PHP 项目中,以便实现与网站和 Web 系统的无缝集成。

入门指南

先决条件

要使用 API,您必须首先拥有 Yo! Payments 商业账户。API 对个人账户不可用。

  • Yo! Payments API 用户名
  • Yo! Payments API 密码
$yoAPI = new YoAPI($username, $password);

安装

Yo! Payments API PHP 库可通过 Composer/Packagist 获取(使用语义版本控制),因此只需将此行添加到您的 composer.json 文件中

"yo-uganda/yopaymentsphp": "^1.2.0" 

composer require yo-uganda/yopaymentsphp8x

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

require 'vendor/autoload.php';

然后,Voilà!现在可以使用 Yo! Payments PHP API 了。

或者,将 YoPaymentsPHP 文件夹的内容复制到 PHP 配置中指定的 include_path 目录之一。

如果您不使用 git,请点击 GitHub 页面顶部的 'zip' 按钮。

最小安装

虽然手动或使用 composer 安装整个包很简单、方便且可靠,但您可能只想在项目中包含必要文件。至少您需要 YoAPI.php。如果您正在进行即时支付通知,那么您还需要为生产环境提供 Yo_Uganda_Public_Certificate.crt 以及为沙箱环境提供 Yo_Uganda_Public_Sandbox_Certificate.crt

然后您可以通过 require '/path/to/YoAPI.php'; 来加载库,一切应该都能正常工作。

一个简单的例子

启动移动货币用户以提示输入 PIN 进行资金转账

$yoAPI = new YoAPI($username, $password);
$yoAPI->set_nonblocking("TRUE");
$response = $yoAPI->ac_deposit_funds('256770000000', 10000, 'Reason for transfer of funds');
if($response['Status']=='OK'){
	// Transaction was successful and funds were deposited onto your account
	echo "Transaction Reference = ".$response['TransactionReference'];
}

在付款完成后接收付款通知。

$yoAPI = new YoAPI($username, $password);
if(isset($_POST)){
	$response = $yoAPI->receive_payment_notification();
	if($response['is_verified']){
		// Notification is from Yo! Uganda Limited
		echo "Payment from ".$response['msisdn']." on ".$response['date_time']." for ".$response['narrative']." with an amount of ".$response['amount'].". Mobile Network Reference = ".$response['network_ref']." and external reference of ".$response['external_ref'];
	}
}

在付款失败时接收通知。

$yoAPI = new YoAPI($username, $password);
if(isset($_POST)){
	$response = $yoAPI->receive_payment_failure_notification();
	if($response['is_verified']){
		// Notification is from Yo! Uganda Limited
		echo "Payment on ".$response['transaction_init_date']." with a FAILED transaction status ".$response['failed_transaction_reference']." closed.";
	}
}

您将在 examples 文件夹中找到更多可以玩耍的内容。

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

使用

  • PHP - PHP 编程语言

作者

许可

本项目使用 MIT 许可证授权 - 有关详细信息,请参阅 LICENSE.md 文件

致谢

  • Gerald Begumisa
  • Grace Kyeyune
  • Joseph Tabajjwa