public function actionTryNow($objectId, $modelClass) { if (self::TrialExist()) { Yii::$app->session->setFlash('error', 'Sorry, You already have a trial hybrizy code'); return $this->redirect(['/#packages']); } $order = new OrderForm(['scenario' => OrderForm::SCENARIO_TRIAL]); $order->user_id = Yii::$app->user->id; $request = Yii::$app->request; if ($request->isPost) { if ($order->load($request->post()) && $order->validate()) { $result = $order->save(); $result = Yii::$app->controller->run('/api/process-order/process', ['objectId' => $objectId, 'modelClass' => $modelClass, 'orderId' => $result->id]); if ($result) { return $this->redirect(['/profile/index']); } } $package = Package::findOne($objectId); return $this->render('index', ['model' => $order, 'package' => $package]); } $package = Package::findOne($objectId); $profile = Yii::$app->user->identity->profile; $order->firstname = $profile->firstname; $order->lastname = $profile->lastname; $order->email = Yii::$app->user->identity->email; return $this->render('index', ['model' => $order, 'package' => $package]); }
public function actionProcess($objectId, $modelClass, $orderId) { $package = Package::findOne($objectId); $op = new OrderProduct(); $op->modelClass = $modelClass; $op->objectId = $objectId; $op->name = $package->name; $op->order_id = $orderId; $op->mask = $package->mask; if ($op->save()) { if ($modelClass === 'Package') { return $this->createCodeBank($package->duration, $op->id, $package->maxCallOut, $package->minBalance); } elseif ($modelClass == 'Topup') { return $this->createTopupBank($op->id); } } return false; }
/** * Finds the Package model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Package the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Package::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }