You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 14, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+55-4Lines changed: 55 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -29,16 +29,67 @@ And run composer to update your dependencies:
29
29
30
30
The following gateways are provided by this package:
31
31
32
-
* WeChat Express (WeChat JSAPI)
32
+
* WeChat Express (WeChat NATIVE)
33
33
34
34
For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
35
35
repository.
36
36
37
-
WeChat JSAPI require OAuth openid to submit a new order, use `$WeChat_Express->getAuthCode($callback)` to get an url for WeChat OAuth and `$WeChat_Express-->getOpenid($code)` in callback page to get openid.
37
+
## Example
38
38
39
-
p.s. the url for WeChat OAuth must be opened in WeChat In-App broswer, you can use `strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === false` to check if the page were not opened in it, and generate a QR code for user.
39
+
### Make a payment
40
40
41
-
All methods for WeChat OAuth will be removed in next stable version and I'll publish a WeChat MP library package for composer.
41
+
The WeChat NATIVE payment gateway return a URI which can be opened within WeChat In-App broswer, you can generate a QR code with the URI.
42
+
43
+
```php
44
+
$omnipay = Omnipay::create('Wechat_Express');
45
+
46
+
$omnipay->setAppId('app_id'); // App ID of your WeChat MP account
47
+
$omnipay->setAppKey('app_key'); // App Key of your WeChat MP account
48
+
$omnipay->setMchId('partner_id'); // Partner ID of your WeChat merchandiser (WeChat Pay) account
49
+
50
+
$params = array(
51
+
'out_trade_no' => time() . rand(100, 999), // billing id in your system
52
+
'notify_url' => $notify_url, // URL for asynchronous notify
53
+
'body' => $billing_desc, // A simple description
54
+
'total_fee' => 0.01, // Amount with less than 2 decimals places
55
+
'fee_type' => 'CNY', // Currency name from ISO4217, Optional, default as CNY
56
+
);
57
+
58
+
$response = $omnipay->purchase($params)->send();
59
+
60
+
$qrCode = new Endroid\QrCode\QrCode(); // Use Endroid\QrCode to generate the QR code
61
+
$qrCode
62
+
->setText($response->getRedirectUrl())
63
+
->setSize(120)
64
+
->setPadding(0)
65
+
->render();
66
+
```
67
+
68
+
### Verify a payment (especially for asynchronous notify)
69
+
70
+
`completePurchase` for Omnipay-WeChat does not require the same arguments as when you made the initial `purchase` call. The only required parameter is `out_trade_no` (the billing id in your system) or `transaction_id` (the trade number from WeChat).
71
+
72
+
```php
73
+
$omnipay = Omnipay::create('Wechat_Express');
74
+
75
+
$omnipay->setAppId('app_id'); // App ID of your WeChat MP account
76
+
$omnipay->setAppKey('app_key'); // App Key of your WeChat MP account
77
+
$omnipay->setMchId('partner_id'); // Partner ID of your WeChat merchandiser (WeChat Pay) account
78
+
79
+
$params = array(
80
+
'out_trade_no' => $billing_id, // billing id in your system
81
+
//or you can use 'transaction_id', the trade number from WeChat
0 commit comments