Giter VIP home page Giter VIP logo

omnipay-unionpay's Introduction

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.

omnipay-unionpay's People

Contributors

jiker-burce avatar lokielse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

omnipay-unionpay's Issues

签名错误

交易失败 11[9100004]Signature verification failed

无论我用沙盒环境的商户号和证书,还是正式的,都报这个错误

PHP 7.4
"lokielse/omnipay-unionpay": "^3.0"

你好,无跳转支付支持 基础版 和 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=...

让潜在的错误[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。

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

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

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

退款时报出异常需要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(撤销)方法吗?

代码BUG反馈

文件:omnipay-unionpay/src/Message/ExpressPurchaseRequest.php
行数:32
如图:
企业微信截图_7f601277-5574-47de-ba2c-2e36f567e611

*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,是不是这个原因呢?

异步通知签名验证成功,同步通知签名验证失败

测试时,同步通知和异步通知,都返回 respCode = 00,但是经过 Singer->verifyWithRSA() 验证签名时,同步失败!!异步成功!!导致同步的 verify_success = false,is_paid() 调用返回失败!

大家有没有遇到类似的问题!

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

如下图所示,开发包里是通过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?

退款接口提示一下错误 重复交易[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(); }

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

@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']);
    }

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'];

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 生产加密证书

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.