Ejemplo n.º 1
0
 /**
  * Check payment result by PaymentType id
  * @param null $id
  * @param null $paymentId
  * @param string $othash
  * @return mixed
  * @throws BadRequestHttpException
  * @throws \yii\base\UnknownClassException
  */
 public function actionResult($id = null, $paymentId = null, $othash = '')
 {
     $id = null === $id ? $paymentId : $id;
     if (null === $id) {
         throw new BadRequestHttpException();
     }
     /** @var PaymentType $paymentType */
     if (null === ($paymentType = PaymentType::findOne(['id' => $id]))) {
         throw new BadRequestHttpException();
     }
     /**
      * Redirect on one of those methods
      */
     return $paymentType->getPayment()->checkResult($othash);
 }
Ejemplo n.º 2
0
 /**
  * @param $event OrderStageLeafEvent
  */
 public static function handlePayment(OrderStageLeafEvent $event)
 {
     $event->setStatus(false);
     if (\Yii::$app->request->isPost) {
         $order = Order::getOrder();
         if (empty($order)) {
             return null;
         }
         /** @var PaymentType $paymentType */
         $paymentType = PaymentType::findOne(['id' => \Yii::$app->request->post('PaymentType'), 'active' => 1]);
         if (empty($paymentType)) {
             return null;
         }
         $order->payment_type_id = $paymentType->id;
         if ($order->save()) {
             $event->setStatus(true);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param $id
  * @return array
  * @throws BadRequestHttpException
  * @throws NotFoundHttpException
  */
 public function actionUpdatePaymentType($id)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $post = Yii::$app->request->post();
     if (!isset($post['Order']['payment_type_id'])) {
         throw new BadRequestHttpException();
     }
     $value = $post['Order']['payment_type_id'];
     $order = $this->findModel($id);
     $order->payment_type_id = $value;
     /** @var PaymentType $paymentType */
     $paymentType = PaymentType::findOne($value);
     if ($paymentType === null || !$order->save(true, ['payment_type_id'])) {
         return ['message' => Yii::t('app', 'Cannot change a payment type')];
     }
     return ['output' => Html::tag('span', $paymentType->name)];
 }
Ejemplo n.º 4
0
 /**
  * @param int|null $type
  * @return null|string
  * @throws BadRequestHttpException
  * @throws \yii\base\UnknownClassException
  */
 public function actionCustomCheck($type = null)
 {
     if (empty($type)) {
         throw new BadRequestHttpException();
     }
     /** @var PaymentType $payment */
     if (null === ($payment = PaymentType::findOne(['id' => $type, 'active' => 1]))) {
         throw new BadRequestHttpException();
     }
     return $payment->getPayment()->customCheck();
 }
 /**
  * Finds the PaymentType model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return PaymentType the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PaymentType::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }