PHP code example of wjminions / omnipay-global-alipay
1. Go to this page and download the library: Download wjminions/omnipay-global-alipay library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wjminions / omnipay-global-alipay example snippets
/**
* @var Omnipay\GlobalAlipay\WebGateway $gateway
*/
//gateways: GlobalAlipay_Web, GlobalAlipay_Wap, GlobalAlipay_App
$gateway = Omnipay::create('GlobalAlipay_Web');
$gateway->setPartner('8888666622221111');
$gateway->setKey('your**key**here'); //for sign_type=MD5
$gateway->setPrivateKey($privateKeyPathOrData); //for sign_type=RSA
$gateway->setReturnUrl('http://www.example.com/return');
$gateway->setNotifyUrl('http://www.example.com/notify');
$gateway->setEnvironment('sandbox'); //for Sandbox Test (Web/Wap)
$params = [
'out_trade_no' => date('YmdHis') . mt_rand(1000,9999), //your site trade no, unique
'subject' => 'test', //order title
'total_fee' => '0.01', //order total fee
'currency' => 'USD', //default is 'USD'
];
/**
* @var Omnipay\GlobalAlipay\Message\WebPurchaseResponse $response
*/
$response = $gateway->purchase($params)->send();
//$response->redirect();
var_dump($response->getRedirectUrl());
var_dump($response->getRedirectData());
var_dump($response->getOrderString()); //for GlobalAlipay_App
/**
* @var Omnipay\GlobalAlipay\WebGateway $gateway
*/
$gateway = Omnipay::create('GlobalAlipay_Web');
$gateway->setPartner('8888666622221111');
$gateway->setKey('your**key**here'); //for sign_type=MD5
$gateway->setPrivateKey($privateKeyPathOrData); //for sign_type=RSA
$gateway->setEnvironment('sandbox'); //for Sandbox Test (Web/Wap)
$params = [
'request_params' => array_merge($_GET, $_POST), //Don't use $_REQUEST for may contain $_COOKIE
];
$response = $gateway->completePurchase($params)->send();
/**
* @var Omnipay\GlobalAlipay\Message\CompletePurchaseResponse $response
*/
if ($response->isPaid()) {
// Paid success, your statements go here.
//For notify, response 'success' only please.
//die('success');
} else {
//For notify, response 'fail' only please.
//die('fail');
}