becopay / invoice_sdk_php
Becopay支付网关API PHP库
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ^4
This package is not auto-updated.
Last update: 2024-09-30 20:40:58 UTC
README
这是为Becopay支付网关提供的PHP库
"php": ">=5.3.0"
安装
通过Composer获取此包。
{
"require": {
"becopay/invoice_sdk_php": "1.*"
}
}
或在终端中运行:composer require becopay/invoice_sdk_php
用法
创建类
首先使用以下命名空间使用库 use Becopay\PaymentGateway;。
要获取构造函数参数,您首先需要在becopay网站上注册(立即注册)
如果输入了无效的数据类型类,将抛出异常。
use Becopay\PaymentGateway; try { $payment = new PaymentGateway( 'api service url', 'api key', 'mobile' ); } catch (Exception $e) { //Add yours exception handling echo $e->getMessage(); }
创建支付重定向URL
要创建支付网关URL,请使用 create() 方法。
参数值的类型必须是字符串。
如果输入了无效的数据类型类,将抛出异常。如果响应成功,将返回对象,如果不成功,则返回false
$payment->error 返回错误消息
try { /* * This function is used to create an invoice. * Return result data type is object * * Note: default value of `merchantCur`and `currency` currency is 'IRR' */ $invoice = $payment->create('order id','price','description','currency','merchantCur'); if($invoice) { /* * Save invoice id in your database * For checking the invoice status you need invoice id * Then redirect user to gateway url for doing the payment process */ //echo the result echo json_encode($invoice); //Get invoice id and insert to database /* $invoiceId = $invoice->id; echo 'invoice id:'.$invoiceId.'<br>'; */ //Get gateway url /* $redirectUrl = $invoice->gatewayUrl; echo 'gateway url'.$invoiceId.'<br>'; */ }else{ //Add your error handling echo $payment->error; } } catch (Exception $e) { //Add your exception handling echo $e->getMessage(); }
响应
{
"id": "ID29_61a5",
"shopName": "New Shop",
"status": "waiting",
"remaining": 40,
"payerAmount": 15000,
"payerCur": "IRR",
"merchantAmount": 15000,
"merchantCur": "IRR",
"date": "2018-10-13 06:45:36",
"timestamp": 1539413136148,
"timeout": 40,
"description": "test payment",
"gatewayUrl": "https://gateway.url.com/invoice/ID29_61a5",
"callback": "http://www.your-website.com/invoice?orderid=12324320",
"orderId": "12324320"
}
使用发票ID检查发票状态
要检查发票状态,您可以使用 check() 方法。
如果输入了无效的数据类型,将抛出异常
如果响应成功,将返回对象,如果不成功,则返回false
$payment->error 返回错误消息
函数参数
check($invoiceId) // Set the Becopay InvoiceId
/* * Use this function to check the invoice status. * This function gets invoice id (which has been created by `create()` function) as parameter * and returns status of that */ try { /* * This function will be used on your callback page or when you want to check the invoice status. * * First you must get orderId from path or query string using $_GET * then find related becopay Invoice id from your database * and use it to check the invoice status */ //Check invoice with InvoiceId $fetchedInvoice = $payment->check($invoiceId); if($fetchedInvoice) { /* * Insert your code here for updating order status */ if($fetchedInvoice->status == "success") { // success msg }else{ //error msg } //echo the result echo json_encode($fetchedInvoice); }else{ //Add your error handling echo $payment->error; } } catch (Exception $e) { //Add your exception handling echo $e->getMessage(); }
响应
{
"id": "ID29_61a5",
"shopName": "New Shop",
"status": "success",
"remaining": 30,
"payerAmount": 15000,
"payerCur": "IRR",
"date": "2018-10-13 06:45:36",
"timestamp": 1539413136148,
"timeout": 40,
"description": "test payment",
"gatewayUrl": "https://gateway.url.com/invoice/ID29_61a5",
"callback": "http://www.your-website.com/invoice?orderid=12324320",
"orderId": "12324320"
}
使用订单ID检查发票状态
要使用您的订单ID检查发票状态,您可以使用 checkByOrderId() 方法。
如果输入了无效的数据类型,将抛出异常
如果响应成功,将返回对象,如果不成功,则返回false
$payment->error 返回错误消息
函数参数
checkByOrderId($orderId) // Set the your orderId
/* * Use this function to check the invoice status. * This function gets invoice id (which has been created by `create()` function) as parameter * and returns status of that */ try { /* * This function will be used on your callback page or when you want to check the invoice status. * * You must get orderId from path or query string using $_GET * and use it to check the invoice status */ //Check invoice with OrderId $fetchedInvoice = $payment->checkByOrderId($orderId); if($fetchedInvoice) { /* * Insert your code here for updating order status */ if($fetchedInvoice->status == "success") { // success msg }else{ //error msg } //echo the result echo json_encode($fetchedInvoice); }else{ //Add your error handling echo $payment->error; } } catch (Exception $e) { //Add your exception handling echo $e->getMessage(); }
响应
{
"id": "ID29_61a5",
"shopName": "New Shop",
"status": "success",
"remaining": 30,
"payerAmount": 15000,
"payerCur": "IRR",
"merchantAmount": 15000,
"merchantCur": "IRR",
"date": "2018-10-13 06:45:36",
"timestamp": 1539413136148,
"timeout": 40,
"description": "test payment",
"gatewayUrl": "https://gateway.url.com/invoice/ID29_61a5",
"callback": "http://www.your-website.com/invoice?orderid=12324320",
"orderId": "12324320"
}
许可证
此软件包是开源软件,根据Apache License 2.0许可。
联系
对于任何问题、错误、建议或功能请求,请使用GitHub问题系统或提交一个拉取请求。在提交问题时,请始终提供有关您的问题的详细说明,以及您收到的任何响应或反馈。记录可能相关的消息或显示问题的代码示例。如果没有这些,我们可能无法帮助您解决问题。请在提交问题或拉取请求之前查看贡献指南。
对于任何其他问题,请随时使用以下凭据
- Email: io@becopay.com