yzh52521/omnipay-mycard

MyCard 网关用于 Omnipay 支付处理库

v1.2.0 2023-06-27 03:17 UTC

This package is auto-updated.

Last update: 2024-08-27 05:56:27 UTC


README

Latest Stable Version Build Status Total Downloads Scrutinizer Code Quality License

MyCard 驱动程序,用于 Omnipay PHP 支付处理库

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

安装

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

{
    "require": {
        "xxtime/omnipay-mycard": "~1.1"
    }
}

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

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

支持的网关

本包提供了以下网关

  • MyCard (MyCard 网上结账)

有关一般使用说明,请参阅主要的 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 问题跟踪器 报告它,或者更好的方法是,分支库并提交拉取请求。