示例#1
0
 /**
  * Method the add the reward
  *
  * @param Request $request
  * @return boolean
  * @throws \Exception
  */
 public function success(Request $request)
 {
     $user = $this->getUser4Id($request->getUserId());
     if (!$user) {
         throw new \Exception('User not found');
     }
     // we already added add the reward, so skip this =)
     if ($this->isStatusSuccess($request) && $this->isDonateAlreadyAdded($request)) {
         // no exception, or the other side spam the service ...
         throw new AlreadyAddedException('already added');
     }
     // check if donate should add coins or remove
     $request->setAmount(abs($request->getAmount()));
     $coins = $this->isStatusSuccess($request) ? $request->getAmount() : -$request->getAmount();
     $request->setAmount($coins);
     // save the message if gamebackend-service is unavailable
     $errorMessage = '';
     try {
         $this->coinService->addCoins($user, $coins);
     } catch (\Exception $e) {
         $request->setStatus($request::STATUS_ERROR);
         $errorMessage = $e->getMessage();
     }
     if ($request->isReasonToBan()) {
         $expire = (int) $this->collectionOptions->getConfig()['payment-api']['ban-time'] + time();
         $reason = 'Donate - ChargeBack';
         $this->userBlockService->blockUser($user, $expire, $reason);
     }
     $this->saveDonateLog($request, $user, $errorMessage);
     return true;
 }
示例#2
0
 /**
  * @param UserInterface $user
  * @return bool
  */
 protected function isUserBlocked(UserInterface $user)
 {
     $userBlocked = $this->userBlockService->isUserBlocked($user);
     $result = false;
     if ($userBlocked) {
         $message = sprintf('You are blocked because %s!, try it again @ %s', $userBlocked->getReason(), $userBlocked->getExpire()->format($this->getDateTimeFormatTime()));
         $this->getFlashMessenger()->setNamespace($this::ERROR_NAME_SPACE)->addMessage($message);
         $result = true;
     }
     return $result;
 }