Home

Awesome

Omnipay: QPay

QPay(QQ Wallet) driver for the Omnipay PHP payment processing library

Build Status Latest Stable Version Latest Unstable Version License

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements QPay support for Omnipay.

Installation

Omnipay is installed via Composer. To install:

composer require kuangjy/omnipay-qpay

Basic Usage

The following gateways are provided by this package:

Usage

Create Order doc

//gateways: QPay_App, QPay_Native, QPay_Js
$gateway = Omnipay::create('QPay_Native');
$gateway->setAppId('app_id'); //required for QPay_App only
$gateway->setAppKey('app_key'); //required for QPay_App only
$gateway->setMchId('mch_id');
$gateway->setApiKey('api_key');

$order = [
    'out_trade_no' => time() . mt_rand(1000, 9999),
    'body' => 'order information',
    'attach' => 'attached information',
    'total_fee' => '100',
    'spbill_create_ip' => '127.0.0.1',
    'notify_url' => 'http://example.com/notify.php',
];

/**
 * @var Omnipay\QPay\Message\CreateOrderRequest $request
 * @var Omnipay\QPay\Message\CreateOrderResponse $response
 */
$request  = $gateway->purchase($order);
$response = $request->send();

//available methods
$response->isSuccessful();
$response->getData(); //For debug
$response->getPrepayId(); //Prepay ID
$response->getAppData(); //For QPay_App
$response->getJsOrderData(); //For QPay_Js
$response->getCodeUrl(); //For QPay_Native

Create MicroPay Order doc

//gateways: QPay_MicroPay
$gateway = Omnipay::create('QPay_MicroPay');
$gateway->setMchId('mch_id');
$gateway->setApiKey('api_key');

$order = [
    'out_trade_no' => time() . mt_rand(1000, 9999),
    'body' => '商品描述',
    'attach' => '附加信息',
    'total_fee' => '100',
    'spbill_create_ip' => '127.0.0.1',
    'notify_url' => 'http://example.com/notify.php',
    'device_info' => '001',
    'auth_code' => '910783818928826810'
];

/**
 * @var Omnipay\QPay\Message\CreateMicroPayOrderRequest $request
 * @var Omnipay\QPay\Message\CreateMicroPayOrderResponse $response
 */
$request  = $gateway->purchase($order);
$response = $request->send();

//available methods
$response->isSuccessful(); //Get result
$response->getData(); //For debug

Create Transfer doc

//gateways: QPay_Transfer
$gateway = Omnipay::create('QPay_Transfer');
$gateway->setMchId('mch_id');
$gateway->setApiKey('api_key');
$gateway->setCertPath($certPath);//证书cert路径
$gateway->setKeyPath($keyPath);//证书key路径

$order = [
    'out_trade_no' => time() . mt_rand(1000, 9999),
    'uin' => '123456789',
    'memo' => '转账描述',
    'total_fee' => '100',
    'spbill_create_ip' => '127.0.0.1',
];

/**
 * @var Omnipay\QPay\Message\CreateTransferRequest $request
 * @var Omnipay\QPay\Message\CreateTransferResponse $response
 */
$request  = $gateway->transfer($order);
$response = $request->send();

//available methods
$response->isSuccessful(); //Get result
$response->getData(); //For debug

Create RedPacket doc

//gateways: QPay_RedPacket
$gateway = Omnipay::create('QPay_RedPacket');
$gateway->setMchId('mch_id');
$gateway->setApiKey('api_key');
$gateway->setCertPath($certPath);//证书cert路径
$gateway->setKeyPath($keyPath);//证书key路径

$order = [
    'mch_billno' => '1441246101201610101234567890',//组成:mch_id+yyyymmdd+10位一天内不能重复的的数字
    'mch_name' => '测试商户',
    're_openid' => '123456789',
    'total_amount' => '100',
    'total_num' => '10',
    'wishing' => '红包祝福语',
    'act_name' => '活动名称',
    'icon_id' => '23',
    'min_value' => '1',
    'max_value' => '100'
];

/**
 * @var Omnipay\QPay\Message\CreateRedPacketRequest $request
 * @var Omnipay\QPay\Message\CreateRedPacketResponse $response
 */
$request  = $gateway->redPacket($order);
$response = $request->send();

//available methods
$response->isSuccessful(); //Get result
$response->getData(); //For debug

Notify doc

$gateway = Omnipay::create('QPay');
$gateway->setAppId('app_id');
$gateway->setMchId('mch_id');
$gateway->setApiKey('api_key');

$response = $gateway->completePurchase([
    'request_params' => file_get_contents('php://input')
])->send();

if ($response->isPaid()) {
    //pay success
    var_dump($response->getRequestData());
}else{
    //pay fail
}

Query Order doc

$response = $gateway->query([
    'transaction_id' => '1217752501201407033233368018',
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());

Close Order doc

$response = $gateway->close([
    'out_trade_no' => '20150806125346',
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());

Refund doc

$gateway->setCertPath($certPath);
$gateway->setKeyPath($keyPath);

$response = $gateway->refund([
    'transaction_id' => '1353933301461607211903715555',
    'out_refund_no' => $outRefundNo,
    'refund_fee' => 100,
    'op_user_id' => '1900000109',
    'op_user_passwd' => 'e47fefadd66e024bb2b85dfeb5fe86ba'
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());

QueryRefund doc

$response = $gateway->queryRefund([
    'refund_id' => '1121218133801201611098791376',
])->send();

var_dump($response->isSuccessful());
var_dump($response->getData());

For general usage instructions, please see the main Omnipay repository.

Related

This project is based on lokielse/omnipay-wechatpay. Thanks for Loki Else's wonderful works.

Support

If you are having general issues with Omnipay, we suggest posting on Stack Overflow. Be sure to add the omnipay tag so it can be easily found.

If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a mailing list which you can subscribe to.

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.