Exebeche
@Exebeche
Осваиваю программирование

Как правильно получить ответ от API?

Уважаемые специалисты, пытаюсь прикрутить оплату на сайте от LiqPay сама оплата проходит, но в ответ не могу получить статус оплаты - прошла или нет...
Использую borysenko/yii2-liqpay
Код контроллера:
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('office@manufacture17.com.ua')
                ->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('elmira@psstudiomodel.com')
                ->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);
    }


Подозреваю, что как-то не так принимаю запрос (внутри yii передаю в УРЛ параметры всякие id, slug...) , но как сделать "так" - ниасилил...
Пожалуйста объясните по-подробнее
  • Вопрос задан
  • 46 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы