A
A
Alexander Stepanov2019-02-21 11:08:09
Yii
Alexander Stepanov, 2019-02-21 11:08:09

How to get liqpay payment status in yii2?

Created a store on yii2 with payment via liqpay.
Everything is fine, except that it is impossible to figure out how to get the payment status so that the status of the order in the store automatically changes.
Action code with payment:

public function actionView($id)
    {
        if (!$order = $this->orders->findOwn(\Yii::$app->user->id, $id)) {
            throw new NotFoundHttpException('The requested page does not exist.');
        }

        $liqpay = new LiqPay($this->public_key, $this->private_key);
        $html = $liqpay->cnb_form(array(
            'action'         => 'pay',
            'amount'         => $order->cost,
            'currency'       => 'UAH',
            'sandbox'        => true,
            'description'    => 'Оплата заказа на Manufacture17.com.ua',
            'order_id'       => $order->id,
            'version'        => '3',
            'server_url'     => 'http://shop.loc/cabinet/order/result'
        ));

        return $this->render('view', [
            'order' => $order,
            'html' => $html,
        ]);
    }

I'm trying to get a response in actionResult:
public function actionResult()
    {
        var_dump(base64_decode(Yii::$app->request->post('data')));
    }

The maximum that happened was an error 400 (yii\web\BadRequestHttpException: Failed to check the transmitted data). Although the request contains a long encoded string in $_POST data
Please explain how to get it without an error, otherwise data is decrypted with a bang, and passing it to the controller does not work.
Please provide more details and/or examples if possible. And then I read the doc, but niasilil ((

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2019-02-21
@Exebeche

error 400

disable csrf token check in this action. Surely liqPay sends a post, and all posts in yii2 are checked for csrf Token, and naturally it is not there. Therefore, it doesn’t even come to the action. Before the action, the csrf Token check is triggered and throws a 400 error.
But there is another nuance here, if liqPay sends a request, then what will var_dump give you? You won't see it, liqPay will get it. You have to write to the logs. For example, if debugging is enabled, it is convenient to do
$data = yii\helpers\Json::encode(base64_decode(Yii::$app->request->post('data')));
Yii::info('liqpay',$data)

or something similar

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question