PHPackages                             pleungkh/omnipay-unionpay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. pleungkh/omnipay-unionpay

ActiveLibrary

pleungkh/omnipay-unionpay
=========================

UnionPay gateway for Omnipay payment processing library

00PHP

Since Jul 31Pushed 1y agoCompare

[ Source](https://github.com/pleungkh/omnipay-unionpay)[ Packagist](https://packagist.org/packages/pleungkh/omnipay-unionpay)[ RSS](/packages/pleungkh-omnipay-unionpay/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Omnipay: UnionPay
=================

[](#omnipay-unionpay)

[![Build Status](https://camo.githubusercontent.com/8a1139cda11ed94a697124a1ece2542d00d1fbf45156170409f3a1c6e94e5362/68747470733a2f2f7472617669732d63692e6f72672f6c6f6b69656c73652f6f6d6e697061792d756e696f6e7061792e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/lokielse/omnipay-unionpay)[![Latest Stable Version](https://camo.githubusercontent.com/8fc71ec48a0bb736b4ebc7b8b7ea199e2084988c5dea8dc24482cae537656adc/68747470733a2f2f706f7365722e707567782e6f72672f6c6f6b69656c73652f6f6d6e697061792d756e696f6e7061792f76657273696f6e2e706e67)](https://packagist.org/packages/lokielse/omnipay-unionpay)[![Total Downloads](https://camo.githubusercontent.com/37792cffe1127c930ec7adabc93d06f9ac30766af112b6cd2e47ac8da0aef68f/68747470733a2f2f706f7365722e707567782e6f72672f6c6f6b69656c73652f6f6d6e697061792d756e696f6e7061792f642f746f74616c2e706e67)](https://packagist.org/packages/lokielse/omnipay-unionpay)

**UnionPay driver for the Omnipay PHP payment processing library**

[Omnipay](https://github.com/omnipay/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 7.1+. This package implements UnionPay support for Omnipay.

Installation
------------

[](#installation)

Omnipay is installed via [Composer](http://getcomposer.org/). 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
-----------

[](#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
-----

[](#usage)

Sandbox Param can be found at: [UnionPay Developer Center](https://open.unionpay.com/ajweb/account/testPara)

Prepare
-------

[](#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

[](#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

[](#returnnotify)

```
$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

[](#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

[](#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

[](#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

[](#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](https://github.com/omnipay/omnipay)repository.

Related
-------

[](#related)

- [Laravel-Omnipay](https://github.com/ignited/laravel-omnipay)
- [Omnipay-Alipay](https://github.com/lokielse/omnipay-alipay)
- [Omnipay-WechatPay](https://github.com/lokielse/omnipay-wechatpay)

Support
-------

[](#support)

If you are having general issues with Omnipay, we suggest posting on [Stack Overflow](http://stackoverflow.com/). Be sure to add the [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) 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](https://groups.google.com/forum/#!forum/omnipay) which you can subscribe to.

If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/lokielse/omnipay-unionpay/issues), or better yet, fork the library and submit a pull request.

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 Bus Factor1

Top contributor holds 94% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/990a8526e71b074865d1759fe303cdbc30f30d3aba5375305e434e26965657f8?d=identicon)[pleungkh](/maintainers/pleungkh)

---

Top Contributors

[![lokielse](https://avatars.githubusercontent.com/u/1573211?v=4)](https://github.com/lokielse "lokielse (79 commits)")[![pleungkh](https://avatars.githubusercontent.com/u/60848874?v=4)](https://github.com/pleungkh "pleungkh (3 commits)")[![jiker-burce](https://avatars.githubusercontent.com/u/24581223?v=4)](https://github.com/jiker-burce "jiker-burce (2 commits)")

### Embed Badge

![Health badge](/badges/pleungkh-omnipay-unionpay/health.svg)

```
[![Health](https://phpackages.com/badges/pleungkh-omnipay-unionpay/health.svg)](https://phpackages.com/packages/pleungkh-omnipay-unionpay)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
