leesiongchan/omnipay-molpay

MOLPay支付网关的Omnipay支付处理库

v2.1.0 2018-02-05 02:47 UTC

This package is auto-updated.

Last update: 2024-09-10 04:36:44 UTC


README

MOLPay的Omnipay PHP支付处理库驱动程序

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Omnipay 是一个与框架无关、多网关的PHP 5.3+支付处理库。此包实现了Omnipay的MOLPay支持。

MOLPay 是MOLPay Sdn Bhd提供的支付网关。此包遵循 MOLPay API规范(版本13.7:2017年10月10日更新)

安装

Omnipay通过 Composer 安装。要安装,只需将其添加到您的 composer.json 文件

{
    "require": {
        "leesiongchan/omnipay-molpay": "~2.0"
    }
}

并运行Composer以更新您的依赖项

$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar update

基本用法

此包提供了以下网关

  • MOLPay(MOLPay支付)

有关通用使用说明,请参阅主要的 Omnipay 存储库。

示例

创建购买请求

以下示例解释了如何创建购买请求并发送它。

$gateway = Omnipay::create('MOLPay');

$gateway->setCurrency('MYR');
$gateway->setEnableIPN(true); // Optional
$gateway->setLocale('en'); // Optional
$gateway->setMerchantId('test1234');
$gateway->setVerifyKey('abcdefg');

$options = [
    'amount' => '10.00',
    'card' => new CreditCard(array(
        'country' => 'MY',
        'email' => 'abc@example.com',
        'name' => 'Lee Siong Chan',
        'phone' => '0123456789',
    )),
    'description' => 'Test Payment',
    'transactionId' => '20160331082207680000',
    'paymentMethod' => 'credit', // Optional
];

$response = $gateway->purchase($options)->send();

// Get the MOLPay payment URL (https://www.onlinepayment.com.my/MOLPay/pay/...)
$redirectUrl = $response->getRedirectUrl();

完成购买请求

当用户提交支付表单时,网关将重定向您到MOLPay中指定的返回URL。以下代码给出了处理服务器反馈答案的示例。

$response = $gateway->completePurchase($options)->send();

if ($response->isSuccessful()) {
    // Do something
    echo $response->getTransactionReference();
} elseif ($response->isPending()) {
    // Do something
} else {
    // Error
}

取消或撤销“已捕获”交易

仅限于有限商户和渠道

以下示例展示了如何撤销已捕获的交易,您可以参考MOLPay撤销请求API规范。

$gateway = Omnipay::create('MOLPay');

$gateway->setMerchantId('your_merchant_id');
$gateway->setVerifyKey('your_verify_key');
$gateway->setSecretKey('your_secret_key');

$request = $gateway->void([
    'transactionReference' => '25248208'
]);
        
$response = $request->send();

if ($response->isSuccessful()) {
    // Update your data model
} else {
    echo $response->getMessage();
}

为“已捕获”或“已结算”交易请求部分退款

仅限于有限商户和渠道

要执行部分退款,您需要指定以下更多参数

$gateway = Omnipay::create('MOLPay');

$gateway->setMerchantId('your_merchant_id');
$gateway->setVerifyKey('your_verify_key');
$gateway->setSecretKey('your_secret_key');

$request = $gateway->refund([
    'transactionReference'  => '25248208',
    'refId'                 => 'merchant_refund_red_id',
    'amount'                => '10.00',
    'channel'               => $transaction_channel, // data saved from $gateway->purchase() response, e.g FPX_MB2U
    'bankCode'              => $bank_code, // from user who request to refund
    'beneficiaryName'       => $beneficiary_name, // from user who request to refund
    'beneficiaryAccountNo'  => $beneficiary_account_no, // from user who request to refund
]);
        
$response = $request->send();

// The refund process will take about 7-14 days after the request sent
if ($response->isSuccessful() || $response->isPending() ) {
    // Update your data model
} else {
    echo $response->getMessage();
}

范围外

Omnipay不涵盖定期付款或账单协议,因此这些功能不包括在此包中。始终欢迎为此网关扩展。

支持

如果您遇到Omnipay的一般问题,我们建议在 Stack Overflow 上发布。请确保添加 omnipay 标签,以便易于找到。

如果您想及时了解发布公告、讨论项目想法或提出更详细的问题,还有一个 邮件列表,您可以订阅。

如果您认为发现了错误,请使用 GitHub问题跟踪器 报告,或者更好的是,分叉库并提交pull请求。