-
Notifications
You must be signed in to change notification settings - Fork 155
Legacy APP Gateway
Fayland Lam edited this page Nov 19, 2016
·
3 revisions
/**
* @var LegacyAppGateway $gateway
*/
$gateway = Omnipay::create('Alipay_LegacyApp');
$gateway->setPartner('the_partner_id');
$gateway->setSellerId('the_partner_id');
$gateway->setPrivateKey('the_private_key');
$gateway->setNotifyUrl('https://www.example.com/notify');
$request = $gateway->purchase([
'subject' => 'test',
'out_trade_no' => date('YmdHis') . mt_rand(1000, 9999),
'total_fee' => '0.01',
]);
/**
* @var LegacyAppPurchaseResponse $response
*/
$response = $request->send();
$orderString = $response->getOrderString();
$request = $gateway->completePurchase();
$request->setParams([
'memo' => '',
'result' => '_input_charset="UTF-8"&alipay_sdk="lokielse/omnipay-alipay"¬ify_url="https://www.example.com/notify"&out_trade_no="2016092309184123456"&partner="80123456789"&payment_type="1"&seller_id="80123456789"&service="mobile.securitypay.pay"&subject="test"&total_fee="0.01"&success="true"',
'resultStatus' => '9000'
]);
/**
* @var LegacyCompletePurchaseResponse $response
*/
try {
$response = $request->send();
if($response->isPaid()){
/**
* Payment is successful
*/
}else{
/**
* Payment is not successful
*/
}
} catch (Exception $e) {
/**
* Payment is not successful
*/
}
$request = $gateway->completePurchase();
$request->setParams($_POST);
/**
* @var LegacyCompletePurchaseResponse $response
*/
try {
$response = $request->send();
if($response->isPaid()){
/**
* Payment is successful
*/
die('success'); //The response should be 'success' only
}else{
/**
* Payment is not successful
*/
die('fail');
}
} catch (Exception $e) {
/**
* Payment is not successful
*/
die('fail');
}