예제 #1
0
 public function actionUpdate($id)
 {
     $notification = Notification::findOne($id);
     $this->checkAccess("update", $notification);
     $notification->status = "read";
     $notification->save();
     return ApiHelper::successResponse($notification);
 }
예제 #2
0
 public function actionRefund()
 {
     $this->checkAccess("create");
     $modelClass = new $this->modelClass();
     $class_id = Yii::$app->request->get('class_id');
     $class = Classes::findOne($class_id);
     if (!is_object($class)) {
         throw new Exception("Class not found", 404);
     }
     if ($class->class_stime - 3600 <= time()) {
         throw new Exception("You cannot do this, time out for refund.", 400);
     }
     $user = User::findIdentityByAccessToken(Yii::$app->request->get('access-token'));
     if ($user->user_type !== "student") {
         throw new Exception("You cannot do this", 404);
     }
     $order = $user->getRefundedClass($class);
     $modelClass->setRefund($order->transation_id);
     $user->setRefund($class->class_id);
     $transactionData = array("user_id" => $user->user_id, "description" => "Refunded class {$class->class_name}", "transation_id" => $order->transation_id, "status" => 'REFUNDED', "amount" => $order->amount * -1, "currency" => 'USD', "class_id" => $class->class_id, "transaction_refund" => true);
     $transactionHistoty = new TransactionHistory();
     $transactionHistoty->load($transactionData, '');
     if (!$transactionHistoty->save()) {
         return ApiHelper::errorResponse($transactionHistoty->getErrors(), 422);
     }
     $notification = new Notification();
     $notification->load(array("user_id" => $user->user_id, "title" => "You successfuly refunded class {$class->class_name}", "text" => "You successfuly refunded class {$class->class_name}", "status" => "new"), '');
     $notification->save();
     $name = base64_encode($user->user_id);
     $notificationTrainer = new Notification();
     $notificationTrainer->load(array("user_id" => $class->class_trainer_id, "title" => "User successfuly refunded your class.", "text" => "<a href='/public_profile/{$name}'>User</a> successfuly refunded your class '{$class->class_name}'.", "status" => "new"), '');
     $notificationTrainer->save();
     return ApiHelper::successResponse($transactionHistoty);
 }