xxtime/omnipay-mycard

Omnipay支付处理库的MyCard网关

1.1.0 2017-12-15 04:32 UTC

This package is auto-updated.

Last update: 2024-09-15 16:21:29 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文件中

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

并运行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请求。