Start.php 2.0 KB
Newer Older
T
Terry 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?php
/**
 * FecShop file.
 *
 * @link http://www.fecshop.com/
 * @copyright Copyright (c) 2016 FecShop Software LLC
 * @license http://www.fecshop.com/license/
 */

namespace fecshop\app\appserver\modules\Payment\block\paypal\standard;

use Yii;

/**
 * @author Terry Zhao <2358269014@qq.com>
 * @since 1.0
 */
class Start
{
T
Terry 已提交
20
    public function startPayment($increment_id)
T
Terry 已提交
21 22 23 24
    {
        $methodName_ = 'SetExpressCheckout';
        $return_url = Yii::$app->request->post('return_url');
        $cancel_url = Yii::$app->request->post('cancel_url');
T
Terry 已提交
25
        $nvpStr_ = Yii::$service->payment->paypal->getStandardTokenNvpStr('Login',$return_url,$cancel_url);
T
Terry 已提交
26 27
        //echo $nvpStr_;exit;
        // 通过接口,得到token信息
T
Terry 已提交
28 29 30 31
        $checkoutReturn = Yii::$service->payment->paypal->PPHttpPost5($methodName_, $nvpStr_);
        //var_dump($checkoutReturn);
        if (strtolower($checkoutReturn['ACK']) == 'success') {
            $token = $checkoutReturn['TOKEN'];
T
Terry 已提交
32
            //$increment_id = Yii::$service->order->getSessionIncrementId();
T
Terry 已提交
33
            //echo $increment_id ;exit;
T
Terry 已提交
34 35
            # 将token写入到订单中
            Yii::$service->order->updateTokenByIncrementId($increment_id,$token);
T
Terry 已提交
36
            $redirectUrl = Yii::$service->payment->paypal->getStandardCheckoutUrl($token);
T
Terry 已提交
37 38 39
            $code = Yii::$service->helper->appserver->status_success;
            $data = [
                'redirectUrl' => $redirectUrl,
T
Terry 已提交
40
            ];
S
Success Gao 已提交
41
            $responseData = Yii::$service->helper->appserver->getResponseData($code, $data);
T
Terry 已提交
42
            
S
Success Gao 已提交
43
            return $responseData;
T
Terry 已提交
44
        
T
Terry 已提交
45
        } else {
T
Terry 已提交
46 47
            $code = Yii::$service->helper->appserver->order_paypal_standard_get_token_fail;
            $data = [
T
Terry 已提交
48
                'error' => isset($checkoutReturn['L_LONGMESSAGE0']) ? $checkoutReturn['L_LONGMESSAGE0'] : '',
T
Terry 已提交
49
            ];
S
Success Gao 已提交
50
            $responseData = Yii::$service->helper->appserver->getResponseData($code, $data);
T
Terry 已提交
51
            
S
Success Gao 已提交
52
            return $responseData;
T
Terry 已提交
53 54 55
        }
    }
}