예제 #1
0
 /**
  * @param integer $id
  * @return OrderTransaction
  * @throws \yii\web\NotFoundHttpException
  */
 protected function loadTransaction($id)
 {
     if (null === ($model = OrderTransaction::findOne($id))) {
         throw new NotFoundHttpException();
     }
     return $this->transaction = $model;
 }
예제 #2
0
 /**
  * Open OrderTransaction with rendering payment form
  * @param null $id
  * @param null $othash
  * @return string
  * @throws BadRequestHttpException
  */
 public function actionTransaction($id = null, $othash = null)
 {
     if (null === $id) {
         throw new BadRequestHttpException();
     }
     /** @var OrderTransaction $transaction */
     if (null === ($transaction = OrderTransaction::findOne(['id' => $id]))) {
         throw new BadRequestHttpException();
     }
     if (!$transaction->checkHash($othash)) {
         throw new BadRequestHttpException();
     }
     return $this->render('transaction', ['transaction' => $transaction]);
 }
예제 #3
0
 /**
  * @param string $hash
  * @throws BadRequestHttpException
  * @throws HttpException
  * @throws \yii\base\ExitException
  */
 public function checkResult($hash = '')
 {
     if (isset($_GET['result'])) {
         if (in_array($_GET['result'], [-1, 0])) {
             $this->redirect(true);
         } else {
             $this->redirect(false);
         }
     }
     $requiredFields = ['IPN_PID', 'IPN_PNAME', 'IPN_DATE', 'ORDERSTATUS', 'HASH', 'REFNOEXT', 'ORDERSTATUS'];
     foreach ($requiredFields as $field) {
         if (!isset($_POST[$field])) {
             throw new BadRequestHttpException();
         }
     }
     $hash = $_POST['HASH'];
     unset($_POST['HASH']);
     if ($this->getSignature($_POST) == $hash) {
         throw new BadRequestHttpException();
     }
     $transaction = OrderTransaction::findOne($_POST['REFNOEXT']);
     $transaction->result_data = Json::encode($_POST);
     if ($_POST['ORDERSTATUS'] == 'COMPLETE') {
         $transaction->status = OrderTransaction::TRANSACTION_SUCCESS;
     }
     if (!$transaction->save(true, ['status', 'result_data'])) {
         throw new HttpException(500);
     }
     $date = date('YmdHis');
     $returnHash = $this->getSignature(['IPN_PID' => $_POST['IPN_PID'][0], 'IPN_PNAME' => $_POST['IPN_PNAME'][0], 'IPN_DATE' => $_POST['IPN_DATE'], 'DATE' => $date]);
     echo '<EPAYMENT>' . $date . '|' . $returnHash . '</EPAYMENT>';
     \Yii::$app->end();
 }
예제 #4
0
 public static function renderEcommerceCounters(Event $event)
 {
     /** @var OrderTransaction $orderTransaction */
     $orderTransaction = OrderTransaction::findOne($event->data['transactionId']);
     $config = Config::getModelByKey('ecommerceCounters');
     if (empty($event->data['transactionId']) || empty($config) || !isset($orderTransaction->order)) {
         return;
     }
     if (!empty($orderTransaction->order->items)) {
         $products = [];
         foreach ($orderTransaction->order->items as $item) {
             $product = Product::findById($item->product_id, null, null);
             if (empty($product)) {
                 continue;
             }
             $category = Category::findById($product->main_category_id);
             $category = empty($category) ? 'Магазин' : str_replace('\'', '', $category->name);
             $products[] = ['id' => $product->id, 'name' => str_replace('\'', '', $product->name), 'price' => number_format($product->price, 2, '.', ''), 'category' => $category, 'qnt' => $item->quantity];
         }
         $order = ['id' => $orderTransaction->order->id, 'total' => number_format($orderTransaction->order->total_price, 2, '.', '')];
         echo Yii::$app->view->renderFile(Yii::getAlias('@app/modules/seo/views/manage/_ecommerceCounters.php'), ['order' => $order, 'products' => $products, 'config' => Json::decode($config->value)]);
     }
 }
예제 #5
0
 /**
  * @return bool
  */
 private function executePayment()
 {
     $result = false;
     try {
         $request = \Yii::$app->request;
         $result = Payment::get($request->get('paymentId'), $this->apiContext)->execute((new PaymentExecution())->setPayerId($request->get('PayerID')), $this->apiContext);
         $status = static::STATE_APPROVED === $result->getState() ? OrderTransaction::TRANSACTION_SUCCESS : OrderTransaction::TRANSACTION_ERROR;
         $detail = Payment::get($request->get('paymentId'), $this->apiContext);
         foreach ($detail->getTransactions() as $transaction) {
             /** @var Transaction $transaction */
             if (null !== ($orderTransaction = OrderTransaction::findOne(['id' => $transaction->getInvoiceNumber()]))) {
                 /** @var OrderTransaction $orderTransaction */
                 $orderTransaction->updateStatus($status);
                 $this->transaction = $orderTransaction;
                 $result = OrderTransaction::TRANSACTION_SUCCESS === $status ? true : false;
             }
         }
     } catch (\Exception $e) {
     }
     return $result;
 }