A
A
Alexander Stepanov2021-12-20 09:17:38
Yii
Alexander Stepanov, 2021-12-20 09:17:38

What is the correct way to get a response from the API?

Dear specialists, I'm trying to add payment on the site from LiqPay, the payment itself goes through, but in response I can't get the payment status - passed or not... I
use borysenko/yii2-liqpay
Controller code:

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'    => 'Оплата заказа ' . $order->id,
            'order_id'       => $order->id,
            'version'        => '3',
            'server_url'     => Url::home('https') .  'cabinet/order/result',
            'result_url'     => Url::home('https') .  'cabinet/order/result'
        ));

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

    public function actionResult()
    {
        $arr = json_decode(base64_decode(Yii::$app->request->post('data')), true, 2,JSON_OBJECT_AS_ARRAY);
var_dump($arr);die();
        $order = Order::findOne(['id' => $arr['order_id']]);

        if ($arr['status'] == 'sandbox') {
            $this->service->pay($arr['order_id']);
            $office = $this->mailer->compose(
                [
                    'html' => 'shop/checkout-html',
                    'text' => 'shop/checkout-text'
                ],
                ['order' => $order]
            )
                ->setTo('[email protected]')
                ->setSubject('Новый заказ ' . \Yii::$app->name)
                ->send();

            if (!$office) {
                throw new \RuntimeException('Ошибка при отправке email.');
            }

            $sent = $this->mailer->compose(
                [
                    'html' => 'shop/checkout-html',
                    'text' => 'shop/checkout-text'
                ],
                ['order' => $order]
                )
                ->setTo('[email protected]')
                ->setSubject('Новый заказ ' . \Yii::$app->name)
                ->send();

            if (!$sent) {
                throw new \RuntimeException('Ошибка при отправке email.');
            }
        }

        return $this->redirect(['view', 'id' => $arr['order_id'],
            'order' => $order,
            'arr' => $arr,
        ]);
    }

    /**
     * @inheritdoc
     */
    public function beforeAction($action)
    {
        if ($action->id == 'result') {
            $this->enableCsrfValidation = false;
        }

        return parent::beforeAction($action);
    }


I suspect that somehow I accept the request in a wrong way (inside yii I pass all sorts of id, slug parameters to the URL ...), but how to do it "so" - niasilil ...
Please explain in more detail

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question