Example #1
0
 /**
  * @Req\Route("/recharge-card/me/pick-profile")
  * @Req\Method({"GET"})
  *
  * @return JsonResponse
  */
 public function pickAction()
 {
     /** @var UsernamePasswordToken $token */
     $token = $this->tokenStorage->getToken();
     $uniqueness = $token->getUsername();
     return new JsonResponse($this->pickProfileApiWorker->pick($uniqueness));
 }
Example #2
0
 /**
  * Consumes given card, increasing the credit balance of given uniqueness
  * and marking the card as consumed.
  *
  * @param string $uniqueness
  * @param string $card
  *
  * @throws NonExistentCodeApiException
  * @throws NonExistentUniquenessApiException
  * @throws AlreadyConsumedApiException
  */
 public function consume($uniqueness, $card)
 {
     // Check card code
     try {
         $card = $this->pickCardInternalWorker->pick($card);
     } catch (NonExistentCodeInternalException $e) {
         throw new NonExistentCodeApiException();
     }
     // Check uniqueness
     try {
         $this->pickProfileApiWorker->pick($uniqueness);
     } catch (NonExistentUniquenessApiException $e) {
         throw $e;
     }
     // Check card status
     if ($card['consumed']) {
         throw new AlreadyConsumedApiException();
     }
     // Get category
     $category = $this->pickCategoryInternalWorker->pick($card['category']);
     // Increase credit balance
     $this->increaseCreditBalanceSharedWorker->increase($uniqueness, $category['utility'], sprintf("Recarga de saldo con tarjeta de recarga \"%s\"", $card['code']));
     // Mark card as consumed
     $this->punchCardInternalWorker->punch($card['code']);
 }
Example #3
0
 /**
  * @param string $uniqueness
  * @param string $package
  *
  * @throws NonExistentUniquenessApiException
  * @throws NonExistentIdApiException
  */
 public function lend($uniqueness, $package)
 {
     // Verify uniqueness
     try {
         $this->pickProfileApiWorker->pick($uniqueness);
     } catch (NonExistentUniquenessApiException $e) {
         throw $e;
     }
     // Get package
     try {
         $package = $this->pickPackageInternalWorker->pick($package);
     } catch (NonExistentIdInternalException $e) {
         throw new NonExistentIdApiException();
     }
     // Generate cards
     $cards = $this->createCardsInternalWorker->create($package['category'], $package['amount']);
     // Assign cards
     $this->assignCardsInternalWorker->assign($uniqueness, $cards);
     // Increase debt
     $category = $this->pickCategoryInternalWorker->pick($package['category']);
     $this->increaseDebtInternalWorker->increase($uniqueness, $package['price'], sprintf("Préstamo de %s tarjetas de categoría \"%s\"", $package['amount'], $category['name']));
 }