Next we will talk about UnionPay payment using this Laravel package, and integrate the UnionPay payment (UnionPay) interface provided by OmniPay-UmniPay UnionPay.
1. Install the UnionPay payment dependency package
If you don't talk much about it, let's get started with the question below. Since the ignited/laravel-omnipay package has been installed in the previous section, here we only need to install the UnionPay payment package:
Composer require lokielse/omnipay-unionpay dev-master
2. Obtain UnionPay payment configuration information
Register an account at the UnionPay payment Developer Center and submit merchant information for review. After the review is passed, obtain the relevant certificate ID and other information to fill in the UnionPay payment configuration options.
If you are testing, UnionPay payment provides the corresponding Test interface and configuration data:
And test bank card information:
Card number card nature organization name mobile phone number password CVN2 validity period certificate number name
6216261000000000018 debit cards Ping An Bank 13552535506 123456 341126197709218366 full-Channel
6221558812340000 loan bank Ping An Bank 13552535506 123456 123 1711 Internet
SMS verification code 111111
Then we go to the slave (such as storage/app/unionpay/certs ):
UnionPay payment verification document
3. Configuration file
Configure config/laravel-omnipay.php (if this profile does not exist refer to the corresponding action in the previous section), add UnionPay payment configuration:
'Unionpa' => [
'Driver '=> 'unionpay _ Express ',
'Options' => [
'Merid' => '123 ',
'Certpath' => '/path/to/storage/app/unionpay/certs/pm_700000000020.acp.pfx ',
'Certpassword' => '123 ',
'Certdir' => '/path/to/certs ',
'Returnurl' => 'Your returnUrl Here ',
'Your url' => 'Your own yurl Here'
]
]
4. Basic use
OmniPay UnionPay provides the following payment gateway interfaces:
Union_Express UnionPay product Gateway (PC, APP, WAP payment)
Union_LegacyMobile old UnionPay Gateway (APP)
Union_LegacyQuickPay old UnionPay Gateway (PC)
In this example, we use the Union_Express gateway.
Define a route
// UnionPay payment processing
Route: get ('unionpay/pay', 'unionpaycontroller @ pay ');
// Callback page after payment
Route: post ('unionpay/return ', 'unionpaycontroller @ result ');
Payment
Create a new controller UnionPayController and define the pay method:
Public function pay (){
$ Gateway = Omnipay: gateway ('unionpay ');
$ Order = [
'Orderid' => date ('ymdhis '),
'Txntime' => date ('ymdhis '),
'Orderdesc' => 'My test order title', // order name
'Txnamt' => '000000', // order price
];
$ Response = $ gateway-> purchase ($ order)-> send ();
$ Response-> redirect ();
}
Callback
Define the result method:
Public function result (){
$ Gateway = Omnipay: gateway ('unionpay ');
$ Response = $ gateway-> completePurchase (['request _ params '= >$ _ request])-> send ();
If ($ response-> isPaid ()){
Exit ('payment successful! ');
} Else {
Exit ('payment failed! ');
}
}
In addition, because the callback request is from a third-party API and cannot pass CSRF verification, you need to exclude this URL in CSRF verification. Otherwise, a TokenMismatchException exception will be thrown, for specific troubleshooting methods, refer to the CSRF attack principle and its protection tutorial. Here we want to exclude the URL unionpay/return.
5. UnionPay payment test
Access in browsingHttp://laravel.app: 8000/unionpay/pay
, The page will jump to the UnionPay payment page:
Enter the test bank card number in the input box and click next:
Enter the ID card number corresponding to the test card number in the input box, click "get for free", and then enter mobile phone verification code 111111 in the verification code input box, and then click "confirm payment ", the page will jump to the successful payment page:
Click "return to merchant" to go to the pageHttp://laravel.app: 8000/unionpay/return
And display:
Payment successful!
Here we have tested the payment and callback interfaces.