UnionPay driver for the Omnipay PHP payment processing library

Overview

Omnipay: UnionPay

Build Status Latest Stable Version Total Downloads

UnionPay driver for the Omnipay PHP payment processing library

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

Installation

Omnipay is installed via Composer. To install, simply add it to your composer.json file:

{
    "require": {
        "lokielse/omnipay-unionpay": "^0.4"
    }
}

And run composer to update your dependencies:

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

Basic Usage

The following gateways are provided by this package:

  • Union_Wtz (Union No Redirect Payment) 银联无跳转支付(alpha)
  • Union_Express (Union Express Payment) 银联全产品网关(PC,APP,WAP支付)
  • Union_LegacyMobile (Union Legacy Mobile Payment) 银联老网关(APP)
  • Union_LegacyQuickPay (Union Legacy QuickPay Payment) 银联老网关(PC)

Usage

Sandbox Param can be found at: UnionPay Developer Center

Prepare

How to get PrivateKey, PublicKey, Cert ID:

0. Prepare cert.pfx and its password, verify_sign_acp.cer

1. Get Private Key
$ openssl pkcs12 -in cert.pfx  -nocerts -nodes | openssl rsa -out private_key.pem

2. Public key is verify_sign_acp.cer

3. Get Cert ID
$ openssl pkcs12 -in cert.pfx -clcerts -nokeys | openssl x509 -serial -noout // result hex eg: XXXXXXXXXX
$ visit https://lokielse.github.io/hex2dec //Convert hex to decimal online

Consume

$gateway    = Omnipay::create('UnionPay_Express');
$gateway->setMerId($config['merId']);
$gateway->setCertId($config['certId']);
$gateway->setPrivateKey($config['privateKey']); // path or content
$gateway->setReturnUrl($config['returnUrl']);
$gateway->setNotifyUrl($config['notifyUrl']);

$order = [
    'orderId'   => date('YmdHis'), //Your order ID
    'txnTime'   => date('YmdHis'), //Should be format 'YmdHis'
    'orderDesc' => 'My order title', //Order Title
    'txnAmt'    => '100', //Order Total Fee
];

//For PC/Wap
$response = $gateway->purchase($order)->send();
$response->getRedirectHtml();

//For APP
$response = $gateway->createOrder($order)->send();
$response->getTradeNo();

Return/Notify

$gateway    = Omnipay::create('UnionPay_Express');
$gateway->setMerId($config['merId']);
$gateway->setPublicKey($config['publicKey']); // path or content

$response = $gateway->completePurchase(['request_params'=>$_REQUEST])->send();

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

Query Order Status

$response = $gateway->query([
    'orderId' => '20150815121214', //Your site trade no, not union tn.
    'txnTime' => '20150815121214', //Order trade time
    'txnAmt'  => '200', //Order total fee
])->send();

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

Consume Undo

$response = $gateway->consumeUndo([
    'orderId' => '20150815121214', //Your site trade no, not union tn.
    'txnTime' => date('YmdHis'), //Regenerate a new time
    'txnAmt'  => '200', //Order total fee
    'queryId' => 'xxxxxxxxx', //Order total fee
])->send();

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

Refund

// 注意:
1. 银联退款时,必须加上 queryId, 
2. 作为商户生成的订单号orderId与退款时的订单号是不一样的。也就意味着退款时的订单号必须重新生成。
3. txnAmt 这个参数银联是精确到分的。直接返回元为单位的值,将会出现报错信息。
// get the queryId first
$response = $gateway->query([
    'orderId' => '20150815121214', //Your site trade no, not union tn.
    'txnTime' => '20150815121214', //Order trade time
    'txnAmt'  => 200 * 100, //Order total fee; notice that: you should multiply the txnAmt by 100 with the Unionpay gateway. Such as 200 * 100;
])->send();
$queryId = ($response->getData())['queryId'];
$response = $gateway->refund([
    'orderId' => '20150815121214', //Your site trade no, not union tn. notice: this orderId must not be the same with the order's created orderId.
    'txnTime' => date('YmdHis'), //Order trade time
    'txnAmt'  => 200 * 100, //Order total fee; notice that: you should multiply the txnAmt by 100 with the Unionpay gateway. Such as 200 * 100;
    'queryId' => $queryId
])->send();

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

File Transfer

$response = $gateway->fileTransfer([
    'txnTime'    => '20150815121214', //Order trade time
    'settleDate' => '0119', //Settle Date
    'fileType'   => '00', //File Type
])->send();

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

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

Related

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.

Comments
  • UpopRsaCert.cer 无法打开

    UpopRsaCert.cer 无法打开

    Hi,

    $gateway->setEnvironment('production'); 使用正式环境,验证付款成功后 回调的签名签名验证出错了: UpopRsaCert.cer 无法打开。 openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! 用openssl命令行 也无法读取这个文件。。

    然而,银联的help上说用不到UpopRsaCert.cer这个文件,可以删除。

    下载的正式环境证书目录里有3个文件: EbppRsaCert.cer , encryptpub.cer, UpopRsaCert.cer

    然而,下载的正式环境证书的帮助里写: ebpp.cer 生产验签证书 encryptpub.cer 生产加密证书

    已经搞不清这些了。。求帮助。

    opened by unizhu 6
  • *curl_error* OpenSSL was built without SSLv3 support

    *curl_error* OpenSSL was built without SSLv3 support

    嗨, @lokielse 。

    版本 v0.3.8

    我在执行$gateway->purchase()->send()时,返回结果为false。通过排查追踪,发现在sendHttpRequest方法中出现错误,用curl_error($ch)得到这个提示信息。

    OpenSSL was built without SSLv3 support

    这个猜测是我的环境关于openssl的安装有问题,我需要再查一下资料。

    版本 0.4.0

    如果升级到 v0.4.0,代码一点不动,可以收到正常的结果,也可以成功付款,但是在回调时验证签名失败。我不知道如何去排查。我用的是在v0.3.8下的配置方法,没有按照新的README上所说的设置公钥,私钥及证书ID,是不是这个原因呢?

    bug 
    opened by SuccessGo 4
  • 你好,有关生产环境的问题

    你好,有关生产环境的问题

    https://gateway.test.95516.com/gateway/api/frontTransReq.do
    交易失败 11[9100004]Signature verification failed
    

    我配置了生产环境的证书,现在请求的地址还是

    https://gateway.test.95516.com/gateway/api/frontTransReq.do
    

    不知道是否应该请求为

    https://gateway.95516.com/gateway/api/frontTransReq.do
    

    如果是的话 这个配置哪里修改或者文档哪里查看(我暂没有找到) 秘钥是按照邮件给的生产的 其他证书(是上传秘钥的界面下载的) 测试环境没有问题、生产环境 验签失败、这是我第一次做此类项目 如果问题问的不好、也希望能回答一下、非常感谢

    opened by FatherGodHz 2
  • 退款时报出异常需要4个参数,但是本项目中退款只需要3个参数

    退款时报出异常需要4个参数,但是本项目中退款只需要3个参数

    根据您此项目中的 退款,需要的参数是:'orderId', 'txnTime', 'txnAmt' 但是,调用refund()方法时,出现下面异常:

    /data/www/benefits-platform/vendor/lokielse/omnipay-
    unionpay/src/Message/ExpressRefundRequest.php(22): Omnipa
    y\Common\Message\AbstractRequest->validate('orderId', 'txnTime', 'txnAmt', 'queryId')
    

    需要4个参数的不是undo(撤销)方法吗?

    opened by jiker-burce 2
  • Update Wtz Gateway

    Update Wtz Gateway

    1. add encryptSensitive params
    2. update requests to support "standard" version and "token" version
    3. update TestCase, replace WtzGatewayTest with WtzStandardGatewayTest and WtzTokenGatewayTest
    4. update Readme.md, add Wtz Gateway example.
    5. Change ResponseVerifyHelper::verify, only check if response is valid.
    opened by kongkx 1
  • 退款接口提示一下错误 重复交易[2010002]

    退款接口提示一下错误 重复交易[2010002]

    退款接口提示一下错误 重复交易[2010002] 根据官方提示 操作无效

    如果有要求一定要用同一个订单号的话,建议按一定格式修改原订单号,比如在原订单号前面加个“T”、后面加个“1”来表示是第一次退货。

    /** * [unionpayRefund 银联退款] * @param [type] $order [description] * @param [type] $gateway [description] * @return [type] [description] */ protected function unionpayRefund($order, $gateway) { $biz = [ 'orderId' => $order['order_id'], 'txnTime' => date('YmdHis', strtotime($order['created_at']['date'])), 'txnAmt' => $order['fee'] * 100, 'queryId' => $order['query_id'], ]; return $gateway->refund($biz)->send(); }

    opened by bigrocs 1
  • 调用银联支付通用网关支付消费接口后,可不可以将错误的结果作为异常丢出?

    调用银联支付通用网关支付消费接口后,可不可以将错误的结果作为异常丢出?

    @lokielse 嗨,你好。

    前言:

    银联支付消费接口,返回的结果当中,如果发生错误时,

    $this->data['respCode'] !== '00'
    

    其中还有比较有意义的返回错误信息,我希望能将此信息报出异常,方便排查错误,因此说比直接判断有没有tn字段,来得友好(或不友好)。

    我建议添加以下改进:

        public function isSuccessful()
        {
            if ('00' !== $this->data['respCode']) {
                throw new \Exception(sprintf('Err: code %s, message %s', $this->data['respCode'], $this->data['respMsg']));
            }
    
            return isset($this->data['tn']);
        }
    
    opened by SuccessGo 1
  • 让潜在的错误[curl related],暴露在用户面前的建议

    让潜在的错误[curl related],暴露在用户面前的建议

    嗨,@lokielse ,你好。

    关于 issue #11 ,排查过程有些艰难,(maybe just for my only),因此,如果在以下文件:

    omnipay-unionpay/src/Helper.php
    

    里的 sendHttpRequest 方法中,添加以下代码行:

    if (curl_error($ch)) {
        throw new \RuntimeException(curl_error($ch));
    }
    

    因为,curl如果发生错误,只会返回false结果,用户层不知在哪里返回的false,唯有沿着代码调用栈层层往上debug。

    没有v0.3.8的分支,v0.4.x也不再使用这个方法,因此我不知道怎么发PR。

    opened by SuccessGo 1
  • 银联网关支付是否支付成功的判断有点问题

    银联网关支付是否支付成功的判断有点问题

    如下图所示,开发包里是通过respCode等于00判断是否支付 image 但是在实际支付过程中,如果用户输入了错误的,用户在未正确支付的情况下,收到的通知结果如下: { "accNo": "6216***********0018", "merId": "777290058176106", "certId": "69026276696", "txnAmt": "1", "bizType": "000201", "orderId": "101720042913364919949986965519", "queryId": "302004291336490032748", "respMsg": "成功[0000000]", "traceNo": "003274", "txnTime": "20200429133649", "txnType": "01", "version": "5.0.0", "encoding": "utf-8", "respCode": "00", "settleAmt": "1", "signature": "gwKTt2Udcl32uaYZVbxfTQJXQXvxv1wFgucYIFbcNH15Zfa45hTdDaXnPjGZ8iR28tYkYL12XMZxX4/0SaVhsKHXTS+/RUAqa5MeqHm78ZQhRbwY/QITsjEKHpEHxo1/Yit114L3IVV5rECwIfeI2ZknMx+t3bJku6589MNRMxn2i8FGBCVCVKR9MFNBwNrvBWvw5BI/vXxb7Ksf6fqPujGtlGduSmZi22Lk00hMlAzL9nUympiUVIstt6pyfDOzi9v1enK4YzH2zzGjxp/6xSJYPMHKnOQ1zqKMRfMSJv/dxS12xPO49KO6QvaQCW4fbf3errZoKDaM8FTYYIrlgQ==", "traceTime": "0429133649", "accessType": "0", "settleDate": "0429", "signMethod": "01", "txnSubType": "01", "origRespMsg": "持卡人身份信息、手机号或CVN2输入不正确,验证失败[1000005]", "currencyCode": "156", "origRespCode": "66", "issuerIdentifyMode": "0", "settleCurrencyCode": "156" } 其中,respCode等于00,但是origRespMsg显示支付出错,其实这是没有支付成功的,是否应该判断一下origRespCode?

    opened by duanjin123 0
  • certId读取问题

    certId读取问题

              if (is_file($cert)) {
                $certs = file_get_contents($cert);
            }
           //需要加上这两行才行
           openssl_pkcs12_read($certData, $certs, $pass)
           $cert = $certs['cert'];
    
            
            $certData = openssl_x509_parse($cert);
    
            return $certData['serialNumber'];
    
    
    opened by q707180869 0
  • 你好,无跳转支付支持 基础版 和 token版 两个版本切换吗?

    你好,无跳转支付支持 基础版 和 token版 两个版本切换吗?

    demo中无跳转支付现在是基于token版本开发,没有看到基础版相关代码。 官方最新参数(以下以消费为例,对应当前vendor/lokielse/omnipay-unionpay/src/Message/WtzConsumeRequest.php;其余无跳转支付文件也有不同参数): token版:txnType=01,txnSubType=01,bizType=000902,tokenPayData=... 基础版数:txnType=01,txnSubType=01,bizType=000301,accNo=...,customerInfo=...

    opened by pengyuanhong 0
  • 測試 UnionPay_Express 5.1 版的證書似乎會有 sign error 的問題

    測試 UnionPay_Express 5.1 版的證書似乎會有 sign error 的問題

    https://github.com/lokielse/omnipay-unionpay/blob/0e4cb1d4ea491635d36b7f763764ef9485dfa2c1/src/Message/ExpressPurchaseRequest.php#L32 這邊的 column 是不是帶錯 function

    https://github.com/lokielse/omnipay-unionpay/blob/0e4cb1d4ea491635d36b7f763764ef9485dfa2c1/src/Message/ExpressPurchaseRequest.php#L67 5.1 版的 sign 要多傳 RSA2

    opened by ChenHom 0
Owner
Loki Else
加关注,不迷路 (´∀`*)
Loki Else
First Data driver for the Omnipay PHP payment processing library

Omnipay: First Data First Data driver for the Omnipay PHP payment processing library Omnipay is a framework agnostic, multi-gateway payment processing

The League of Extraordinary Packages 20 Oct 23, 2022
A framework agnostic, multi-gateway payment processing library for PHP 5.6+

Omnipay An easy to use, consistent payment processing library for PHP Omnipay is a payment processing library for PHP. It has been designed based on i

The League of Extraordinary Packages 5.7k Dec 30, 2022
PHP 7+ Payment processing library. It offers everything you need to work with payments: Credit card & offsite purchasing, subscriptions, payouts etc. - provided by Forma-Pro

Supporting Payum Payum is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and our

Payum 1.7k Dec 27, 2022
Omnipay for Laravel

Omnipay for Laravel 5/6/7/8 & Lumen Integrates the Omnipay PHP library with Laravel 5 via a ServiceProvider to make Configuring multiple payment tunne

Ignited Labs 463 Dec 13, 2022
The whmcs payment module for TigoPesa Payment Gateway.

whmcs-tigopesa INSTALLATION INSTRUCTIONS TIGOPESA WHMCS Please follow the instructions below to setup the whmcs-tigopesa gateway module. Download zipp

Medson Naftali 3 Dec 11, 2021
The Laravel eCommerce Accept Payment Gateway allows the customer to make use of Accept payment gateway in the Bagisto eCommerce website.

Introduction Bagisto WeAccept add-on allow customers to pay for others using WeAccept payment gateway. Requirements: Bagisto: 1.3.2 Installation with

Bagisto 2 May 31, 2022
The Laravel eCommerce ABA Payment Gateway module allows the admin to integrate the ABA payment gateway to the online store.

Introduction Bagisto ABA Payment Gateway. Requirements: Bagisto: v1.3.2. Installation with composer: Run the following command composer require bagist

Bagisto 3 May 31, 2022
With the help of the Laravel eCommerce CashU Payment Gateway, the admin can integrate the CashU payment method in the Bagisto store.

Introduction Bagisto CashU Payment add-on allow customers to pay for others using CashU payment gateway. Requirements: Bagisto: v1.3.2 Installation wi

Bagisto 2 Aug 22, 2022
PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP language

php-text-analysis PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP l

null 464 Dec 28, 2022
iOrder is a light weight prototype for a order processing MIS.

Order Processing MIS. iOrder is a light weight prototype for a order processing MIS. Features Centralized order management Merchants definitely benefi

MartDevelopers Inc 4 Feb 8, 2022
The Simple Result Type simply returns the processing result as an object.

The Simple Result Type The Simple Result Type simply returns the processing result as an object. Enjoy! Example This is a basic usage example. use Tak

null 1 Mar 23, 2022
Melek Berita Backend is a service for crawling data from various websites and processing the data to be used for news data needs.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Chacha Nurholis 2 Oct 9, 2022
A PHP library to integrate with eWAY's Rapid Payment API.

A PHP library to integrate with eWAY's Rapid Payment API.

null 0 Jul 15, 2022
The official SingleStore Laravel driver.

SingleStore Driver for Laravel This repository contains a SingleStore Driver for Laravel. This package is currently in a pre-release beta, please use

SingleStore Labs 197 Jan 1, 2023
PHP package to communicate with the CMI payment plateform in Morocco

CMI PHP Payment bindings CMI PHP PAYMENT is an open source PHP payment handling library. it provides an easier way to communicate with CMI PAYMENT PLA

medhi rochdi 45 Dec 26, 2022
CPAY is a sdk that encapsulates the Orange Money api with an intuitive syntax allowing you to integrate the Orange Money payment into your PHP project.

CPAY CHOCO PAY is a sdk that encapsulates the Orange Money api with an intuitive syntax allowing you to integrate the Orange Money payment into your P

faso-dev 1 Oct 26, 2022
Integrate Paytm Payment gateway to php website.

paytm-integration-kit-project-for-PHP Integrate Paytm Payment gateway to php website. Copy PaytmKit folder in document root of your server (like /var/

Er. Dipankar Mohanta 1 Feb 11, 2022
ShurjoPay payment gateway integration for PHP applications.

ShurjoPay PHP Library Using this library you can integrate ShurjoPay payment gateway into your PHP applications. If you face any problem then create i

Raziul Islam 6 Jun 17, 2022
WHMCS Payment Gateway Module for Coinify

vrcoinify WHMCS Payment Gateway Module for Coinify Installing guide You should copy all contents from module folder to your WHMCS application folder u

VR DEV TEAM 3 Mar 15, 2022