-
Notifications
You must be signed in to change notification settings - Fork 155
Aop Page Gateway
Kuang Jiaye edited this page Jul 9, 2018
·
2 revisions
/**
* @var AopPageGateway $gateway
*/
$gateway = Omnipay::create('Alipay_AopPage');
$gateway->setSignType('RSA2'); //RSA/RSA2
$gateway->setAppId('the_app_id');
$gateway->setPrivateKey('the_app_private_key');
$gateway->setAlipayPublicKey('the_alipay_public_key');
$gateway->setReturnUrl('https://www.example.com/return');
$gateway->setNotifyUrl('https://www.example.com/notify');
$request = $gateway->purchase();
$request->setBizContent([
'out_trade_no' => date('YmdHis') . mt_rand(1000, 9999),
'total_amount' => 0.01,
'subject' => 'test',
'product_code' => 'FAST_INSTANT_TRADE_PAY',
]);
/**
* @var AopTradePagePayResponse $response
*/
$response = $request->send();
$redirectUrl = $response->getRedirectUrl();
//or
$response->redirect();
$request = $gateway->completePurchase();
$request->setParams(array_merge($_POST, $_GET)); //Don't use $_REQUEST for may contain $_COOKIE
/**
* @var AopCompletePurchaseResponse $response
*/
try {
$response = $request->send();
if($response->isPaid()){
/**
* Payment is successful
*/
die('success'); //The notify response should be 'success' only
}else{
/**
* Payment is not successful
*/
die('fail'); //The notify response
}
} catch (Exception $e) {
/**
* Payment is not successful
*/
die('fail'); //The notify response
}