redde / php-api-sdk
Redde API 封装器
v1.2.0
2021-07-06 17:00 UTC
Requires
- php: >=5.5.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2024-09-18 07:50:36 UTC
README
Redde-php-sdk
Redde REST API 的 PHP SDK,允许商家接收、发送、检查交易状态以及执行大量支付交易。
在您可以使用 API 之前,您需要注册并创建一个账户。所有请求的头部都应该包含 {"apikey": "string"}:,并且此 API 密钥将在您的应用配置由 Wigal 设置后发送给商家。
有关文档的更多信息,请访问 developers.reddeonline.com
安装
要使用此库,您需要创建一个 Redde 账户。
要安装此库并在您的项目中使用,我们建议使用 Composer。
composer require redde/php-api-sdk
您不需要克隆此仓库即可在您的项目中使用此库。使用 Composer 从 Packagist 安装它。
如果您是 Composer 新手,以下是一些您可能觉得有用的资源
- Composer 入门页面,来自 Composer 项目文档。
- Composer 入门指南,来自 ScotchBox 的朋友们。
使用
如果您正在使用 Composer,请确保自动加载器包含在您的项目引导文件中
require_once "vendor/autoload.php";
使用您的 API 密钥和 App ID 创建一个 API 对象,这些信息将由 Redde 团队提供
$api = new ReddeApi(API_KEY, APP_ID);
示例
从客户或客户接收资金
要使用 API 从客户接收资金,请使用 receiveMoney() 方法,它使用简单的参数数组,键与 API 的参数相匹配。
/** * An example of using the Redde Api to receive money */ require_once 'vendor/autoload.php'; //Configuration file contains apikey and appid $config = include 'config.php'; use Redde\Exceptions\ReddeApiException; use Redde\Exceptions\ReddeException; use Redde\ReddeApi; /* Replace this with your API key and App Id You can also insert the apikey and appid here directly and ignore the config.php file */ $apikey = $config['apikey']; $app_id = $config['appid']; $api = new ReddeApi($apikey, $app_id); /* Note that the clienttransid and clientreference is generated by the developer. The nickname is your identity name eg. Wigal */ $params = [ "amount" => 1, //amount to receive "appid" => $config['appid'], //your app id "clientreference" => client_reference_here, //client reference from your side "clienttransid" => client_transaction_id_here, //client transaction id from your side "description" => "Recieving payment from {$client_reference_here}", //A description for the transaction performed "nickname" => "nickname_here", //a name to give to who is paying "paymentoption" => "MTN", //payment options are MTN|AIRTELTIGO|VODAFONE "vouchercode" => "", //this is optional for vodafone "walletnumber" => "024XXXXXXX" //the mobile number to use ]; /** * Call receiveMoney function and pass * the payload as parameter. This will * return a response which you can save * in any storage of your choice */ $api->receiveMoney($params);
向客户或客户发送资金
要使用 API 向客户发送资金,请使用 sendMoney() 方法,它使用简单的参数数组,键与 API 的参数相匹配。
/** * An example of using the Redde Api to send money */ require_once 'vendor/autoload.php'; //Configuration file contains apikey and appid $config = include 'config.php'; use Redde\Exceptions\ReddeApiException; use Redde\Exceptions\ReddeException; use Redde\ReddeApi; /* Replace this with your API key and App Id You can also insert the apikey and appid here directly and ignore the config.php file */ $apikey = $config['apikey']; $app_id = $config['appid']; $api = new ReddeApi($apikey, $app_id); /* Note that the clienttransid and clientreference is generated by the developer. The nickname is your identity name eg. Wigal */ $params = [ "amount" => 1, //amount to receive "appid" => $config['appid'], //your app id "clientreference" => client_reference_here, //client reference from your side "clienttransid" => client_transaction_id_here, //client transaction id from your side "description" => "Sending payment from {$client_reference_here}", //A description for the transaction performed "nickname" => "nickname_here", //a name to give to who is paying "paymentoption" => "MTN", //payment options are MTN|AIRTELTIGO|VODAFONE "walletnumber" => "024XXXXXXX" //the mobile number to use ]; /** * Call receiveMoney function and pass * the payload as parameter. This will * return a response which you can save * in any storage of your choice */ $api->sendMoney($params);
回调
大多数 API 实现了回调以方便跟踪 API 交易,因此我们为您提供了一个简单的解决方案。查看它
/** * A simple implementation of callback * on Redde Api */ require_once '../vendor/autoload.php'; use Redde\Exceptions\ReddeApiException; use Redde\Exceptions\ReddeException; use Redde\Webhooks\WebHookStatus; $status = new WebHookStatus(); //instantiate an object $data = $status->callback(); //get callback and set it to a variable echo $data->reason; //output any data e.g. status|reason| etc
许可
此库根据 MIT 许可证发布