kipolaboratory / kipo-kpg
Kipopay支付网关库 OOP (PHP)
0.5.7
2020-03-04 17:00 UTC
Requires
README
PHP Kipo KPG 库使与 KIPO 网关建立支付变得简单。
安装
要安装 PHP Kipo KPG 库,只需
$ composer require kipolaboratory/kipo-kpg
对于最新提交版本
$ composer require kipolaboratory/kipo-kpg @dev
要求
PHP Kipo KPG 库与 PHP 5.6, 7.0, 7.1, 7.2 兼容。
快速入门和示例
初始化 Kipo KPG 并从 KIPO 服务器请求购物密钥。
use kipolaboratory\KipoPay\KipoKPG; /** * Initial Kipo Library and craete object from that class * Merchant key is merchant phone number */ $kipo = new KipoKPG(['merchant_key' => '09*********']); /** * Replace "YOUR CALLBACK URL" and "AMOUNT" with what you want * KPGInitiate return ARRAY for result * Successful - ['status' => true, 'shopping_key' => SHOPING_KEY] * Failed - ['status' => false, 'message' => ERROR_MESAGE, 'code' => ERROR_CODE] */ $kpg_initiate = $kipo->KPGInitiate(AMOUNT, 'YOUR CALLBACK URL'); if ($kpg_initiate['status']) { /** * Store $kpg_initiate['shopping_key'] to session to verfiy * payment after user came back from gateway * * Call renderForm function to render a html form and send * user to Kipo KPG Gateway (you can create this form manually * where you want - form example is at the end of Quick Start */ $kipo->renderForm($kpg_initiate['shopping_key']); } else { /** * Show error to user * * You can call getErrorMessage and send error code to that * and get error message * $kipo->getErrorMessage(ERROR_CODE) */ }
在用户返回到 CALLBACK URL 后验证支付
/** * Replace "SHOPPING_KEY" with your SHOPPING_KEY that you taken from * Initiate function * * KPGInquery return ARRAY for result * Successful - ['status' => true, 'referent_code' => REFERENT_CODE, 'amount' => PAYMENT_AMOUNT] * Failed - ['status' => false, 'message' => ERROR_MESAGE, 'code' => ERROR_CODE] */ $kpg_inquery = $kipo->KPGInquery(SHOPPING_KEY);
// Get shopping key after KPGInitiate called $curl->getShoppingKey();
// Get referent code after KPGInquery called $curl->getReferentCode();
属性
// URL of Kipo KPG - https://webgate.kipopay.com/ // Shopping key must post to this url with SK name $kipo->kipo_webgate_url;
HTML 表单将用户传输到 KPG
<form id="kipopay-gateway" method="post" action="KIPO_WEBGATE_URL" style="display: none;"> <input type="hidden" id="sk" name="sk" value="SHOPING_KEY"/> </form> <script language="javascript">document.forms['kipopay-gateway'].submit();</script>
错误代码和信息
- -1: 请求参数存在问题,请检查它们(初始支付)
- -2: 解析请求数据存在问题(请稍后再次请求)
- -3: 连接错误,API 无法连接到 KIPO 服务器
- -4: 请求参数存在问题,请检查它们(验证支付)
- -5: 用户取消支付或存在问题
- -6: 无效的商户密钥 (商户手机号码)
- -7: 最小支付金额至少为 1.000 里尔
- -8: 最大支付金额为 100.000.000 里尔
- -9: 无效的支付令牌 (购物密钥) 格式