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