e-ghl/ omnipay
eGHL支付网关的Omnipay支付处理库
Requires
- e-ghl/exception: ^1
- e-ghl/merchant-api: ^3
- league/omnipay: ^3
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is auto-updated.
Last update: 2024-09-29 05:28:02 UTC
README
用于与eGHL集成的omnipay包
安装
可以通过以下命令使用Composer安装/要求此包
composer require e-ghl/omnipay
使用以下命令从私有仓库克隆eGHL_hashing包。 (通过联系support.eghl@ghl.com获取私有仓库的访问权限)
git clone https://bitbucket.org/eghl/eghl_hashing.git vendor/e-ghl/merchant-api/src/eghl_hashing
OmniPay框架如何适应任何电子商务支付插件系统?
要理解这一点,我们首先需要确定构建电子商务系统支付插件所需的步骤。
下表显示了开发电子商务支付插件所涉及的所有重要步骤。其中一些步骤完全依赖于电子商务框架,而其余步骤则由OmniPay框架处理。下表还说明了哪些步骤依赖于电子商务框架,哪些由OmniPay框架处理。
| # | 描述 | 是否依赖电子商务框架 | 是否依赖OmniPay框架 |
|---|---|---|---|
| 1 | 构建支付插件配置存储机制,即MerchantID和MerchantPass等 | 是 | - |
| 2 | 获取并准备eGHL交易所需结账订单信息 | 是 | - |
| 3 | 确定回调(服务器到服务器)和返回(服务器到浏览器)URL | 是 | - |
| 4 | 验证eGHL处理支付交易所需订单信息 | - | 是 |
| 5 | 准备包含支付请求信息和有效HashValue的自动提交HTML表单,并将其提交给eGHL支付URL | - | 是 |
| 6 | 使用回调/返回URL中的Hash值匹配验证eGHL支付响应 | - | 是 |
| 7 | 确定交易状态,即成功、失败或挂起 | - | 是 |
| 8 | 根据交易状态更新订单状态、创建发票、通知客户 | 是 | - |
用法
如果已安装omnipay,则开发人员只需执行三个简单的步骤即可与eGHL支付方法集成。
| # | 步骤 | 备注 |
|---|---|---|
| 1 | 向eGHL发送支付请求 | 将生成一个自动提交的HTML表单,将向eGHL发送支付请求 |
| 2 | 处理回调响应 | 这是eGHL从商户网站返回的服务器到服务器响应。这是在支付请求的MerchantCallBackURL参数中指定的商户网站上的URL。此参数不是必需的,但建议包含。此段代码负责更新订单状态。 |
| 3 | 处理返回响应 | 这是eGHL从商户网站返回的服务器到客户端响应。这是在支付请求的MerchantReturnURL参数中指定的商户网站上的URL。此参数是必需的,它主要负责在回调URL未更新订单状态的情况下更新订单状态,并将购物者重定向到适当的着陆页,即成功支付页面或失败支付页面。 |
向eGHL发送支付请求
define('BASE_URL','https:///omni-eghl/demo/');
use Omnipay\Omnipay;
$gateway = Omnipay::create('eGHL');
$gateway->setMerchantId('SIT');
$gateway->setMerchantPassword('sit12345');
$gateway->setTestMode(); // Add tis line only to enable test mode payment
$data = array(
//'TransactionType' => 'AUTH', // Set TransactionType = AUTH in order to authorize the CC transaction
'PymtMethod' => 'ANY',
'OrderNumber' => 'OMNI001',
//'PaymentID' => 'OMNI001', // if not defined, its generated automatically
'PaymentDesc' => 'ominpay test',
'MerchantReturnURL' => BASE_URL.'return.php',
'MerchantCallBackURL' => BASE_URL.'callback.php',
'Amount' => '10.00',
'CurrencyCode' => 'MYR',
'CustName' => 'Jawad Humayun',
'CustEmail' => 'jawad.humayun@ghl.com',
'CustPhone' => '01156301987',
'PageTimeout' => 700
);
$PurchaseResponse = $gateway->purchase($data)->send();
if ($PurchaseResponse->isRedirect()) {
$PurchaseResponse->redirect(); // redirect to offsite payment gateway
}
处理回调响应
use Omnipay\Omnipay;
$gateway = Omnipay::create('eGHL');
$gateway->setMerchantId('SIT');
$gateway->setMerchantPassword('sit12345');
$Response = $gateway->completePurchase($_REQUEST)->send();
if($Response->isSuccessful()){
// Payment successful logic
}
elseif($Response->isCancelled()){
// Payment canceled by buyer
}
elseif($Response->isPending()){
// Payment pending logic
}
else{
// Payment failed logic
}
die('OK'); //acknowlegment sent back to eGHL
处理返回响应
use Omnipay\Omnipay;
$gateway = Omnipay::create('eGHL');
$gateway->setMerchantId('SIT');
$gateway->setMerchantPassword('sit12345');
$Response = $gateway->completePurchase($_REQUEST)->send();
if($Response->isSuccessful()){
// Payment successful logic
// Redirect to Success page
}
elseif($Response->isCancelled()){
// Payment canceled by buyer
// Redirect to failed page
}
elseif($Response->isPending()){
// Payment pending logic
// Redirect to pending page
}
else{
// Payment failed logic
// Redirect to failed page
}
其他功能
eGHL Omnipay集成还支持以下非常有用且常见的支付处理功能。
- 退款(对信用卡交易进行退款)
- 取消/撤销(撤销/取消信用卡交易)
- 捕获(捕获授权的信用卡交易)
以下将解释上述每个功能示例代码。
退款
Omnipay\eGHL\Gateway对象的refund方法向eGHL网关发送信用卡交易的在线退款请求。
如果退款请求成功或处于待处理状态,则返回 eGHL\MerchantAPI\Refund 对象。如果交易已经退款或由于任何原因失败,则抛出异常。
只有信用卡交易可以在线退款,因此直接借记或在线银行交易不会退款。
// Require Autoloader
require_once "../vendor/autoload.php";
// Invoke Omnipay namespace
use Omnipay\Omnipay;
$gateway = Omnipay::create('eGHL');
$gateway->setMerchantId('SIT');
$gateway->setMerchantPassword('sit12345');
$gateway->setTestMode(); // Add tis line only to enable test mode payment
$data = array(
'PymtMethod' => 'CC',
'PaymentID' => '130#1547432197655ef9',
'Amount' => '1005.00',
'CurrencyCode' => 'MYR'
);
try{
$RespData = $gateway->refund($data)->getResponse();
echo "<pre>".print_r($RespData, 1)."</pre>";
}
catch(\Exception $e){
echo "Caught Exception: ".$e->getMessage();
}
取消/撤销
void 方法用于 Omnipay\eGHL\Gateway 对象,向 eGHL 网关发送在线撤销请求,用于信用卡交易。
如果取消请求成功或处于待处理状态,则返回 eGHL\MerchantAPI\Reversal 对象。如果交易已经撤销或由于任何原因失败,则抛出异常。
只有信用卡交易可以在线撤销,因此直接借记或在线银行交易不会撤销。
// Require Autoloader
require_once "../vendor/autoload.php";
// Invoke Omnipay namespace
use Omnipay\Omnipay;
$gateway = Omnipay::create('eGHL');
$gateway->setMerchantId('SIT');
$gateway->setMerchantPassword('sit12345');
$gateway->setTestMode(); // Add tis line only to enable test mode payment
$data = array(
'PymtMethod' => 'CC',
'PaymentID' => 'IPGJAW20190111600016',
'Amount' => '1.00',
'CurrencyCode' => 'MYR'
);
try{
$RespData = $gateway->void($data)->getResponse();
echo "<pre>".print_r($RespData, 1)."</pre>";
}
catch(\Exception $e){
echo "Caught Exception: ".$e->getMessage();
}
抓取
capture 方法用于 Omnipay\eGHL\Gateway 对象,向 eGHL 网关发送在线抓取请求,用于信用卡交易。
如果取消请求成功或处于待处理状态,则返回 eGHL\MerchantAPI\Capture 对象。如果交易已经抓取、未授权或由于任何原因失败,则抛出异常。
只有信用卡交易可以在线抓取,因此直接借记或在线银行交易不会抓取。
// Require Autoloader
require_once "../vendor/autoload.php";
// Invoke Omnipay namespace
use Omnipay\Omnipay;
$gateway = Omnipay::create('eGHL');
$gateway->setMerchantId('SIT');
$gateway->setMerchantPassword('sit12345');
$gateway->setTestMode(); // Add tis line only to enable test mode payment
$data = array(
'PymtMethod' => 'CC',
'PaymentID' => '130#1547432197655ef9',
'Amount' => '1005.00',
'CurrencyCode' => 'MYR'
);
try{
$RespData = $gateway->refund($data)->getResponse();
echo "<pre>".print_r($RespData, 1)."</pre>";
}
catch(\Exception $e){
echo "Caught Exception: ".$e->getMessage();
}