Skip to content

Legacy Express Gateway

heui edited this page Jul 25, 2017 · 8 revisions

Gateway (网关)

/**
 * @var LegacyExpressGateway $gateway
 */
$gateway = Omnipay::create('Alipay_LegacyExpress');
$gateway->setSellerEmail('the_seller_email');
$gateway->setPartner('the_partner_id');
$gateway->setKey('the_md5_sign_key'); //For MD5 sign type
//$gateway->setPrivateKey('the_rsa_sign_key'); //For RSA sign type
//$gateway->setAlipayPublicKey('the_alipay_public_key'); //For RSA sign type
$gateway->setReturnUrl('https://www.example.com/return');
$gateway->setNotifyUrl('https://www.example.com/notify');

Purchase (购买)

$request = $gateway->purchase([
  'out_trade_no' => date('YmdHis').mt_rand(1000,9999),
  'subject'      => 'test',
  'total_fee'    => '0.01',
]);

/**
 * @var LegacyExpressPurchaseResponse $response
 */
$response = $request->send();

$redirectUrl = $response->getRedirectUrl();
//or 
$response->redirect();

Return && Notify (同步、异步通知)

$request = $gateway->completePurchase();
$request->setParams($_REQUEST);

try {
    /**
     * @var AopTradeAppPayResponse $response
     */
    $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
}