Skip to content

Legacy Express Gateway

Silas Xie edited this page Dec 7, 2016 · 8 revisions

Gateway (网关)

/**
 * @var AopWapGateway $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 (同步、异步通知)

$options = array_merge($_POST, $_GET);
//Don't use $_REQUEST for may contain $_COOKIE

$request = $gateway->completePurchase($options);


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

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
}
Clone this wiki locally