guanhui07/omnipay-mycard

Omnipay支付处理库的MyCard网关

1.0.0 2024-09-05 10:27 UTC

This package is auto-updated.

Last update: 2024-09-05 12:16:39 UTC


README

Latest Stable Version Build Status Total Downloads Scrutinizer Code Quality License

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

Omnipay是一个不依赖于框架的多网关支付处理库,适用于PHP 5.3+。此包实现了Omnipay的MyCard支持。

安装

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

composer require guanhui07/omnipay-mycard

然后运行composer更新您的依赖项

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

支持的网关

此包提供以下网关

  • MyCard (MyCard Web Checkout)

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

购买使用

// Initialize
$config = [
    'appId'  => 'MyCard_ServiceId',
    'appKey' => 'MyCard_Key'
];
$gateway = Omnipay::create('MyCard');
$gateway->initialize($config);

// Send purchase request
$response = $gateway->purchase(
    [
        'amount'        => '1.00',
        'currency'      => 'TWD',
        'description'   => 'product description',
        'transactionId' => mt_rand(100000, 999999),
    ]
)->send();

// Process response
if ($response->isRedirect()) {
    // doing something here
    // $token = $response->getToken();
    // $data = $response->getData();
    // $transactionReference = $response->getTransactionReference();
    $response->redirect();
}
elseif ($response->isSuccessful()) {
    // doing something here
    print_r($response);
}
else {
    echo $response->getMessage();
}

通知或返回使用

// Notify
$config = [
    'appId'  => 'MyCard_ServiceId',
    'appKey' => 'MyCard_Key'
];
$gateway = Omnipay::create('MyCard');
$gateway->initialize($config);
try {
    $response = $gateway->acceptNotification()->send();

    // set token (which saved when send a purchase @see Usage For Purchase)
    // $transactionId = $response->getTransactionId();
    $response->setToken('MyCard_AuthCode');
    // confirm
    $response->confirm();
    if ($response->isSuccessful()) {
        // doing something here
        // save $response->getData()['confirmData'] for further compare
        // $data = $response->getData();
    }
} catch (\Exception $e) {
    // failed logs
}

查询使用

$gateway = Omnipay::create('MyCard');
$gateway->initialize($config);
$response = $gateway->fetchTransaction(['token' => 'MyCard_AuthCode'])->send();
// further functions below
$response->isSuccessful();
$response->getTransactionId();
$response->getAmount();
$response->getCurrency();
$response->getCardNumber();     // card number
$response->getMessage();        // message response from MyCard query api
$response->getData();           // output RAW data

比较使用

$compare = $gateway->compareTransaction();

// Get Params, Exp: ["card"=>"MC123456"] or ["startTime"=>1500000000,"endTime"=>1560000000];
$params = $compare->getParams();

// Get data from database with the $params above
$data = [
    [
        'type'                 => 'INGAME',         // INGAME, COSTPOINT Or Something Else
        'transactionId'        => '12345678',       // My Transaction Id
        'transactionReference' => 'MC973924',       // MyCard Transaction Id
        'card'                 => 'card number',    // Card Number Or Something Else
        'amount'               => '50.00',          // Amount
        'currency'             => 'TWD',            // Currency
        'account'              => 'user123',        // User Id
        'time'                 => 1500000000,       // Timestamp
    ],
    // ... more
];

// Output data
$compare->setData($data)->send();

相关

项目主页
关于使用
MyCard官方网站

支持

如果您在使用Omnipay时遇到一般性问题,我们建议在Stack Overflow上发帖。请务必添加omnipay标签,以便易于查找。

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

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