'TopUp into Company Wallet', 'message' => 'You have successfully created a topup request for company\'s wallet' ]; } /** @var FetchesCompany */ private $fetchesCompany; /** @var GeneratesWalletCode */ private $generatesWalletCode; /** @var CreatesWallet */ private $createsWallet; /** @var GeneratesTransactionBillNumber */ private $generatesTransactionBillNumber; /** @var CreatesBillplzBill */ private $createsBillplzBill; /** @var CreatesTransaction */ private $createsTransaction; /** @var BookingToVoucherifyProcessor */ private $bookingToVoucherifyProcessor; /** * TopUpWalletLogic constructor. * @param FetchesCompany $fetchesCompany * @param GeneratesWalletCode $generatesWalletCode * @param CreatesWallet $createsWallet * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber * @param CreatesBillplzBill $createsBillplzBill * @param CreatesTransaction $createsTransaction * @param BookingToVoucherifyProcessor $bookingToVoucherifyProcessor */ public function __construct(FetchesCompany $fetchesCompany, GeneratesWalletCode $generatesWalletCode, CreatesWallet $createsWallet, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesBillplzBill $createsBillplzBill, CreatesTransaction $createsTransaction, BookingToVoucherifyProcessor $bookingToVoucherifyProcessor) { $this->fetchesCompany = $fetchesCompany; $this->generatesWalletCode = $generatesWalletCode; $this->createsWallet = $createsWallet; $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; $this->createsBillplzBill = $createsBillplzBill; $this->createsTransaction = $createsTransaction; $this->bookingToVoucherifyProcessor = $bookingToVoucherifyProcessor; } /** * @param Request $request * @return JsonResponse * @throws \App\Classes\Exceptions\MalformedRequestException */ public function logic(Request $request) : JsonResponse { $amount = floatval(str_replace(',', '', $request->input('amount'))); $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); /** @var Wallet $wallet */ $wallet = $company->wallets()->first(); if (!$wallet) { $object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute()); /** @var Wallet $wallet */ $wallet = $this->createsWallet->execute($object, $company); } $user = $company->employees()->first(); $billNumber = $this->generatesTransactionBillNumber->execute('TOPUP-'); if($amount < 0) { throw new MalformedRequestException('Top up credit value must be greater than zero.'); } $billPlzBill = $this->createsBillplzBill->execute($company->name, $user->email, 'This payment is credit topup for company ref. ' . $company->reference, $amount, $billNumber, $request->input('bank_code'), true); $transaction_object = new TransactionObject($billNumber, TransactionType::TOP_UP, 1, $company->id, 1, PaymentMethodType::PAYMENT_GATEWAY, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, [], $billPlzBill->id); $transaction = $this->createsTransaction->execute($wallet, $transaction_object); $this->bookingToVoucherifyProcessor->execute($company->employees()->first(), $transaction, $company->id, $amount, 0); return $this->resourceResponse(new WalletTransactionResource($transaction)); } }