public function actionYadopay() { \Yii::info('start', 'app/payments/yad'); $r = new Request(); $param = $r->post(); $code = 0; $err_msg = null; $order = null; if (!$this->checkMD5($param)) { // кривой md5 $code = 1; //$err_msg = ''; } else { $order = Order::chkOrder($param['orderNumber'], $param['customerNumber']); if ($order) { // ордер нашелся if ($order->price < $param['orderSumAmount'] * 100) { // и даже сумма норм if ($param['action'] == 'paymentAviso' && !$order->closed_at) { // это уже сам платеж и ордер не закрыт еще // значит надо закрыть $order->price = $param['orderSumAmount'] * 100; $order->closed_at = new Expression('NOW()'); if ($order->validate() && $order->save()) { // ok, все сохранилось } else { // что-то пошло не так $code = 200; $err_msg = array_values($order->errors)[0][0]; //vd($order->errors); } } } else { // сумма неправильная $err_msg = 'Неверная сумма'; } } else { // нет такого ордера $err_msg = 'Платеж не найден'; } } if (!$code && $err_msg) { $code = 100; } // \Yii::$app->response->format = \yii\web\Response::FORMAT_XML; $response = \Yii::$app->response; $response->format = Response::FORMAT_RAW; $response->getHeaders()->set('Content-Type', 'application/xml; charset=utf-8'); // return $this->render('sitemap'); return $this->buildResponse($param['action'], $param['invoiceId'], $code, $err_msg); return $this->render('yadopay', ['response' => ['action' => $param['action'], 'invoiceId' => $param['invoiceId'], 'code' => $code, 'msg' => $err_msg, 'shopId' => $this->shopId], 'rrr' => ['param' => $param, 'order' => $order]]); }