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
        
        return $this->getBlock()->startPayment();
T
Terry 已提交
35 36 37 38 39 40
    }
    /**
     * 2.Review  从paypal确认后返回的部分
     */
    public function actionReview()
    {
T
Terry 已提交
41 42 43
        if(Yii::$app->request->getMethod() === 'OPTIONS'){
            return [];
        }
T
Terry 已提交
44 45
        $payment_method = Yii::$service->payment->paypal->standard_payment_method;
        Yii::$service->payment->setPaymentMethod($payment_method);
T
Terry 已提交
46
        
T
Terry 已提交
47 48 49 50 51 52 53
        return $this->getBlock('placeorder')->getLastData();
    }
    /**
     * IPN,paypal消息接收部分
     */
    public function actionIpn()
    {
T
Terry 已提交
54 55 56
        if(Yii::$app->request->getMethod() === 'OPTIONS'){
            return [];
        }
T
Terry 已提交
57
        \Yii::info('paypal ipn begin standard', 'fecshop_debug');
T
Terry 已提交
58 59
        $payment_method = Yii::$service->payment->paypal->standard_payment_method;
        Yii::$service->payment->setPaymentMethod($payment_method);
T
Terry 已提交
60 61 62 63 64 65 66 67
        $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');
68
            Yii::$service->payment->paypal->receiveIpn($post);
T
Terry 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
        }
    }
    /**
     * 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');
    }
    */
}