StandardController.php 2.6 KB
Newer Older
T
Terry 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?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\controllers\paypal;

use fecshop\app\appserver\modules\AppserverController;
use Yii;

/**
 * @author Terry Zhao <2358269014@qq.com>
 * @since 1.0
 */
class StandardController extends AppserverController
{
    public $enableCsrfValidation = false;
    
    /**
     * 1.start部分,跳转到paypal前的部分
     */
    public function actionStart()
    {
T
Terry 已提交
28 29 30
        if(Yii::$app->request->getMethod() === 'OPTIONS'){
            return [];
        }
T
Terry 已提交
31 32
        $payment_method = Yii::$service->payment->paypal->standard_payment_method;
        Yii::$service->payment->setPaymentMethod($payment_method);
T
Terry 已提交
33 34 35 36 37 38 39
        return $this->getBlock()->startExpress();
    }
    /**
     * 2.Review  从paypal确认后返回的部分
     */
    public function actionReview()
    {
T
Terry 已提交
40 41 42
        if(Yii::$app->request->getMethod() === 'OPTIONS'){
            return [];
        }
T
Terry 已提交
43 44
        $payment_method = Yii::$service->payment->paypal->standard_payment_method;
        Yii::$service->payment->setPaymentMethod($payment_method);
T
Terry 已提交
45 46 47 48 49 50 51
        return $this->getBlock('placeorder')->getLastData();
    }
    /**
     * IPN,paypal消息接收部分
     */
    public function actionIpn()
    {
T
Terry 已提交
52 53 54
        if(Yii::$app->request->getMethod() === 'OPTIONS'){
            return [];
        }
T
Terry 已提交
55
        \Yii::info('paypal ipn begin', 'fecshop_debug');
T
Terry 已提交
56 57
        $payment_method = Yii::$service->payment->paypal->standard_payment_method;
        Yii::$service->payment->setPaymentMethod($payment_method);
T
Terry 已提交
58 59 60 61 62 63 64 65
        $post = Yii::$app->request->post();
        if (is_array($post) && !empty($post)) {
            $post = \Yii::$service->helper->htmlEncode($post);
            ob_start();
            ob_implicit_flush(false);
            var_dump($post);
            $post_log = ob_get_clean();
            \Yii::info($post_log, 'fecshop_debug');
66
            Yii::$service->payment->paypal->receiveIpn($post);
T
Terry 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
        }
    }
    /**
     * paypal 取消后的部分。
     */
    /*
    public function actionCancel()
    {
        $innerTransaction = Yii::$app->db->beginTransaction();
        try {
            if(Yii::$service->order->cancel()){
                $innerTransaction->commit();
            }else{
                $innerTransaction->rollBack();
            }
        } catch (Exception $e) {
            $innerTransaction->rollBack();
        }
        return Yii::$service->url->redirectByUrlKey('checkout/onepage');
    }
    */
}