/** * Deletes the subscription with given mobile and uniqueness. * * @param string $mobile * @param string $uniqueness * * @throws NonExistentMobileAndUniquenessApiException */ public function delete($mobile, $uniqueness) { $subscription = $this->connectToStorageInternalWorker->connect()->findOne(['mobile' => $mobile, 'uniqueness' => $uniqueness]); if (!$subscription) { throw new NonExistentMobileAndUniquenessApiException(); } // Increase to the balance what the subscription balance has $this->increaseBalanceInternalWorker->increase($uniqueness, $subscription['balance']); // Remove subscription $this->connectToStorageInternalWorker->connect()->remove(['mobile' => $mobile, 'uniqueness' => $uniqueness]); $this->logOperationInternalWorker->logDelete($mobile, $uniqueness, $subscription['topics'], $subscription['trial'], $subscription['balance'], time()); }
/** * @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'])); }