/** * @Req\Route("/info-sms/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)); }
/** * @Req\Route("/info-sms/me/create-subscription-and-compute") * @Req\Method({"POST"}) * * @param Request $request * * @return JsonResponse */ public function createAction(Request $request) { /** @var UsernamePasswordToken $token */ $token = $this->tokenStorage->getToken(); $uniqueness = $token->getUsername(); $response = $this->create($request); if ($response->getStatusCode() != '200') { return $response; } return new JsonResponse(['subscriptionsAmount' => $this->computeSubscriptionsApiWorker->compute($uniqueness), 'infoSmsProfile' => $this->pickInfoSmsProfileApiWorker->pick($uniqueness)]); }
/** * @Req\Route("/info-sms/me/buy-package") * @Req\Method({"POST"}) * * @param Request $request * * @return JsonResponse */ public function buyAction(Request $request) { /** @var UsernamePasswordToken $token */ $token = $this->tokenStorage->getToken(); $uniqueness = $token->getUsername(); $data = $request->request->all(); foreach (array('id') as $key) { Assertion::keyExists($data, $key); } try { $this->buyPackageApiWorker->buy($uniqueness, $data['id']); } catch (InsufficientBalanceApiException $e) { return new JsonResponse(array('code' => 'INFO_SMS.PROFILE.INSUFFICIENT_BALANCE'), 400); } return new JsonResponse(['infoSmsProfile' => $this->pickInfoSmsProfileApiWorker->pick($uniqueness), 'creditProfile' => $this->pickCreditProfileApiWorker->pick($uniqueness)]); }
/** * @param string $uniqueness * @param string $package * * @throws NonExistentUniquenessApiException * @throws NonExistentPackageApiException * @throws InsufficientBalanceApiException */ public function buy($uniqueness, $package) { try { $this->pickProfileApiWorker->pick($uniqueness); } catch (NonExistentUniquenessApiException $e) { throw $e; } // Get package info try { $package = $this->pickPackageInternalWorker->pick($package); } catch (NonExistentPackageApiException $e) { throw $e; } // Check if there is enough balance in credit profile if (!$this->checkCreditBalanceSharedWorker->check($uniqueness, $package['price'])) { throw new InsufficientBalanceApiException(); } // Increase amount of sms in profile $this->increaseBalanceInternalWorker->increase($uniqueness, $package['amount']); // Decrease balance in credit profile $this->decreaseCreditBalanceSharedWorker->decrease($uniqueness, $package['price'], sprintf("Compra de paquete de noticias por sms \"%s\"", $package['name'])); }
/** * @param string $mobile * @param string $uniqueness * @param string $alias * @param string[] $topics * @param string $resellPackage * * @throws NonExistentUniquenessApiException * @throws InvalidMobileApiException * @throws BlankAliasApiException * @throws ExistentMobileApiException * @throws NoTopicsApiException * @throws NonExistentTopicApiException * @throws NoResellPackageApiException * @throws NonExistentResellPackageApiException * @throws TrialNotAcceptedApiException * @throws InsufficientBalanceApiException */ public function create($mobile, $uniqueness, $alias, $topics, $resellPackage) { try { $this->pickProfileApiWorker->pick($uniqueness); } catch (NonExistentUniquenessApiException $e) { throw $e; } try { $this->validateMobileAndAliasInternalWorker->validate($mobile, $alias); } catch (InvalidMobileInternalException $e) { throw new InvalidMobileApiException(); } catch (BlankAliasInternalException $e) { throw new BlankAliasApiException(); } catch (ExistentMobileInternalException $e) { throw new ExistentMobileApiException(); } try { $this->validateTopicsInternalWorker->validate($topics); } catch (NoTopicsInternalException $e) { throw new NoTopicsApiException(); } catch (NonExistentTopicInternalException $e) { throw new NonExistentTopicApiException(); } $mobile = PhoneNumberFixer::fix($mobile); if (!$resellPackage) { throw new NoResellPackageApiException(); } try { $resellPackage = $this->pickResellPackageInternalWorker->pick($resellPackage); } catch (NonExistentResellPackageInternalException $e) { throw new NonExistentResellPackageApiException(); } if ($resellPackage['price'] == 0) { try { $this->createTrialSubscriptionInternalWorker->create($mobile, $uniqueness, $alias, $topics, 10); } catch (TrialNotAcceptedInternalException $e) { throw new TrialNotAcceptedApiException(); } } else { try { $this->createPaidSubscriptionInternalWorker->create($mobile, $uniqueness, $alias, $topics, $resellPackage); } catch (InsufficientBalanceInternalException $e) { throw new InsufficientBalanceApiException(); } } }