mirror of
https://gitlab.com/uldvstar/exchange-2.0.git
synced 2026-08-19 12:34:24 +00:00
e3e4b490b0
# Conflicts: # resources/views/partials/header.blade.php # routes/web.php
132 lines
4.3 KiB
PHP
132 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Wallets\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
|
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
|
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
|
use App\Classes\Modules\Wallets\Services\CreatesWallet;
|
|
use App\Classes\Modules\Wallets\Services\GeneratesWalletCode;
|
|
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
|
use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill;
|
|
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Http\Resources\WalletResource;
|
|
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class TopUpWalletLogic extends AbstractControllerLogic
|
|
{
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'TopUp into Company Wallet',
|
|
'message' => 'You have successfully topup company wallet'
|
|
];
|
|
}
|
|
|
|
|
|
/** @var FetchesCompany */
|
|
private $fetchesCompany;
|
|
|
|
/** @var GeneratesWalletCode */
|
|
private $generatesWalletCode;
|
|
|
|
/** @var CreatesWallet */
|
|
private $createsWallet;
|
|
|
|
/** @var GeneratesTransactionBillNumber */
|
|
private $generatesTransactionBillNumber;
|
|
|
|
/** @var CreatesWalletTransaction */
|
|
private $createsWalletTransaction;
|
|
|
|
/** @var CreatesBillplzBill */
|
|
private $createsBillplzBill;
|
|
|
|
/** @var CreatesTransaction */
|
|
private $createsTransaction;
|
|
|
|
/**
|
|
* CreateWalletLogic constructor.
|
|
* @param FetchesCompany $fetchesCompany
|
|
* @param GeneratesWalletCode $generatesWalletCode
|
|
* @param CreatesWallet $createsWallet
|
|
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
|
*/
|
|
public function __construct(
|
|
FetchesCompany $fetchesCompany,
|
|
GeneratesWalletCode $generatesWalletCode,
|
|
CreatesWallet $createsWallet,
|
|
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
|
CreatesBillplzBill $createsBillplzBill,
|
|
CreatesTransaction $createsTransaction
|
|
)
|
|
{
|
|
$this->fetchesCompany = $fetchesCompany;
|
|
$this->generatesWalletCode = $generatesWalletCode;
|
|
$this->createsWallet = $createsWallet;
|
|
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
|
$this->createsBillplzBill = $createsBillplzBill;
|
|
$this->createsTransaction = $createsTransaction;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
|
|
if (!$company->wallets()->first()) {
|
|
$object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute());
|
|
$wallet = $this->createsWallet->execute($object, $company);
|
|
}
|
|
|
|
$user = $company->employees()->first();
|
|
$billNumber = $this->generatesTransactionBillNumber->execute('TOPUP-');
|
|
|
|
$billPlzBill = $this->createsBillplzBill->execute(
|
|
$user->name,
|
|
$user->email,
|
|
'This payment is made for wallet topup. ' . $company->reference,
|
|
$request->input('amount'),
|
|
$billNumber,
|
|
$request->input('bank_code')
|
|
);
|
|
|
|
$transaction_object = new TransactionObject(
|
|
$billNumber,
|
|
TransactionType::TOP_UP,
|
|
1,
|
|
$company->id,
|
|
1,
|
|
PaymentMethodType::PAYMENT_GATEWAY,
|
|
$request->input('amount'),
|
|
$request->input('amount'),
|
|
1,
|
|
1,
|
|
1,
|
|
0,
|
|
0,
|
|
null,
|
|
ApprovalStatus::PENDING_SUBMISSION,
|
|
[],
|
|
$billPlzBill->id
|
|
);
|
|
|
|
$transaction = $this->createsTransaction->execute($company->wallets()->first(), $transaction_object);
|
|
|
|
return $this->resourceResponse(new WalletResource($wallet));
|
|
}
|
|
}
|