Merge branch 'task/EXC-353' into development

This commit is contained in:
ahmedsophyudden
2021-11-08 16:15:05 +08:00
40 changed files with 1044 additions and 54 deletions
@@ -0,0 +1,13 @@
<?php
namespace App\Classes\General\Interfaces;
use Illuminate\Database\Eloquent\Relations\MorphMany;
interface Transactionable
{
public function transactions(): morphMany;
}
@@ -84,7 +84,6 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
*/
public function logic(Request $request) : JsonResponse
{
$booking = Booking::find($request->route('id'));
$conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $request->input('amount'))), $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')]);
@@ -110,7 +109,7 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
$configurations->getTax(), $configurations->getServiceCharge(), Carbon::now()->addMinutes($paymentAttemptLimit), ApprovalStatus::PENDING_SUBMISSION, [], isset($billPlzBill) ? $billPlzBill->id : NULL);
$transaction = $this->createsTransaction->execute($booking, $object);
return $this->resourceResponse(new TransactionResource($transaction));
}
@@ -83,7 +83,7 @@ class CreatePaymentProofDocumentLogic extends AbstractControllerLogic
$this->createsFile->execute($document, $object);
$this->updatesTransactionStatus->execute($transaction, ApprovalStatus::COMPLETED);
$this->updatesTransactionStatus->execute($transaction, ApprovalStatus::APPROVED);
$this->createInvoiceTransactionProcessor->execute($transaction->booking);
@@ -101,7 +101,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic
/** @var Transaction $payment */
$payment = $this->fetchesTransaction->execute(['id' => $payment['id']]);
if($payment->status !== ApprovalStatus::APPROVED) continue;
$this->updatesTransactionStatus->execute($payment, ApprovalStatus::COMPLETED);
@@ -109,7 +109,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic
$object = new TransactionObject($billNumber, TransactionType::BILL, $supplier->id, 1,
$supplier->banks()->where('default', true)->first()->id, PaymentMethodType::CASH,
$payment->original_amount * (1 / $rate), $payment->original_amount, 1, $payment->original_currency_id,
$rate, 0, 0, null, ApprovalStatus::APPROVED);
$rate, 0, 0, null, ApprovalStatus::PENDING_VERIFICATION);
$transactions[] = $this->createsTransaction->execute($payment->booking, $object);
}
@@ -0,0 +1,61 @@
<?php
namespace App\Classes\Modules\Transactions\Processors;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Transactions\Services\CreatesWalletTransaction;
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Models\Wallet;
class CreateWalletTransactionProcessor
{
/** @var CreatesWalletTransaction */
private $createsWalletTransaction;
/** @var GeneratesTransactionBillNumber */
private $generatesTransactionBillNumber;
public function __construct(CreatesWalletTransaction $createsWalletTransaction, GeneratesTransactionBillNumber $generatesTransactionBillNumber)
{
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
$this->createsWalletTransaction = $createsWalletTransaction;
}
/**
* @param Booking $booking
* @return void
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Wallet $wallet, WalletObject $walletOject, int $transactionType)
{
$billNumber = $this->generatesTransactionBillNumber->execute('WAL-');
$transaction_object = new TransactionObject(
$billNumber,
$transactionType,
$wallet->company->id,
1,
1,
PaymentMethodType::BA,
$walletOject->getAmount(),
$walletOject->getAmount(),
$wallet->currency_id,
$wallet->currency_id,
0,
0,
0,
null,
ApprovalStatus::PENDING_SUBMISSION
);
$walletTransaction = $this->createsWalletTransaction->execute($wallet, $transaction_object);
return $walletTransaction;
}
}
@@ -0,0 +1,68 @@
<?php
namespace App\Classes\Modules\Transactions\Processors;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
use App\Classes\Modules\Wallets\Services\FetchesWallet;
use App\Classes\Modules\Wallets\Services\UpdatesWallet;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Models\Wallet;
class UpdateWalletTransactionProcessor
{
/** @var CreatesWalletTransaction */
private $createsWalletTransaction;
/** @var FetchesTransaction */
private $fetchesTransaction;
/** @var ListWallet */
private $fetchesWallet;
/** @var UpdatesTransactionStatus */
private $updatesTransactionStatus;
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, UpdatesWallet $updatesWallet, FetchesTransaction $fetchesTransaction)
{
$this->fetchesTransaction = $fetchesTransaction;
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->updatesWallet = $updatesWallet;
}
/**
* @param Booking $booking
* @return void
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(int $transactionId, int $transactionStatus)
{
$transaction = $this->fetchesTransaction->execute(['id' => $transactionId]);
$wallet = $transaction->wallet;
switch($transaction->type){
case TransactionType::TOP_UP:
$updateWalletAmount = $transaction->amount + $wallet->amount;
break;
case TransactionType::WITHDRAW:
$updateWalletAmount = $wallet->amount - $transaction->amount;
break;
default:
break;
}
$walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount);
$this->updatesTransactionStatus->execute($transaction, $transactionStatus);
$this->updatesWallet->execute($wallet, $walletOject);
return $wallet;
}
}
@@ -2,8 +2,8 @@
namespace App\Classes\Modules\Transactions\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\General\Interfaces\Transactionable;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Models\Booking;
use App\Models\Transaction;
@@ -15,7 +15,7 @@ class CreatesTransaction extends AbstractUpdateRelationshipRecord
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Booking $booking, TransactionObject $object) {
public function execute(Transactionable $transactionable, TransactionObject $object) {
$model = new Transaction();
$model->bill_no = $object->getBillNo();
$model->type = $object->getTransactionType();
@@ -34,8 +34,7 @@ class CreatesTransaction extends AbstractUpdateRelationshipRecord
$model->status = $object->getStatus();
$model->payment_reference = $object->getPaymentReference();
return $this->handler($booking->transactions(), $model);
return $this->handler($transactionable->transactions(), $model);
}
}
@@ -0,0 +1,39 @@
<?php
namespace App\Classes\Modules\Transactions\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Models\Wallet;
use App\Models\Transaction;
class CreatesWalletTransaction extends AbstractUpdateRelationshipRecord
{
/**
* @param TransactionObject $object
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Wallet $wallet, TransactionObject $object) {
$model = new Transaction();
$model->bill_no = $object->getBillNo();
$model->type = $object->getTransactionType();
$model->issuer = $object->getIssuer();
$model->receiver = $object->getReceiver();
$model->recipient_bank_account_id = $object->getRecipientBankAccountId();
$model->payment_method = $object->getPaymentMethod();
$model->amount = $object->getAmount();
$model->original_amount = $object->getOriginalAmount();
$model->currency_id = $object->getCurrencyId();
$model->original_currency_id = $object->getOriginalCurrencyId();
$model->currency_rate = $object->getCurrencyRate();
$model->tax = $object->getTax();
$model->service_charge = $object->getServiceCharge();
$model->expires_on = $object->getExpiresOn();
$model->status = $object->getStatus();
return $this->handler($wallet->transactions(), $model);
}
}
@@ -9,6 +9,7 @@ use App\Classes\Modules\Wallets\Services\CreatesWallet;
use App\Classes\Modules\Wallets\Services\GeneratesWalletCode;
use App\Classes\Modules\Wallets\Standards\Rules\CanCreateCompanyWallet;
use App\Http\Resources\WalletResource;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use ErrorException;
use Illuminate\Http\JsonResponse;
@@ -38,14 +39,18 @@ class CreateWalletLogic extends AbstractControllerLogic
/** @var CanCreateCompanyWallet */
private $canCreateCompanyWallet;
/** @var FetchesCompany */
private $fetchesCompany;
/**
* CreateWalletLogic constructor.
* @param CreatesWallet $createsWallet
* @param GeneratesWalletCode $generatesWalletCode
* @param CanCreateCompanyWallet $canCreateCompanyWallet
*/
public function __construct(CreatesWallet $createsWallet, GeneratesWalletCode $generatesWalletCode, CanCreateCompanyWallet $canCreateCompanyWallet)
public function __construct(CreatesWallet $createsWallet, GeneratesWalletCode $generatesWalletCode, CanCreateCompanyWallet $canCreateCompanyWallet, FetchesCompany $fetchesCompany)
{
$this->fetchesCompany = $fetchesCompany;
$this->createsWallet = $createsWallet;
$this->generatesWalletCode = $generatesWalletCode;
$this->canCreateCompanyWallet = $canCreateCompanyWallet;
@@ -58,24 +63,14 @@ class CreateWalletLogic extends AbstractControllerLogic
*/
public function logic(Request $request) : JsonResponse
{
try {
$object = new WalletObject($request->input('company_id'), $request->input('currency_id'), $this->generatesWalletCode->execute());
DB::beginTransaction();
$this->canCreateCompanyWallet->passes($object);
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
$object = new WalletObject($request->input('currency_id'), $request->input('company_id'), $this->generatesWalletCode->execute());
$this->canCreateCompanyWallet->passes($object);
$wallet = $this->createsWallet->execute($object);
DB::commit();
return $this->resourceResponse(new WalletResource($wallet));
} catch (\Exception $exception) {
throw new ErrorException($exception->getMessage(), $exception->getCode());
}
$wallet = $this->createsWallet->execute($object, $company);
return $this->resourceResponse(new WalletResource($wallet));
}
}
}
@@ -0,0 +1,60 @@
<?php
namespace App\Classes\Modules\Wallets\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Wallets\Services\ListsWallet;
use App\Classes\Modules\Wallets\Standards\Rules\CanListWallet;
use App\Http\Resources\WalletResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ListWalletLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'List Company Wallet',
'message' => 'You have successfully list company wallet'
];
}
/** @var ListWallet */
private $listsWallet;
/** @var CanCreateCompanyWallet */
private $canListWallet;
/**
* CreateWalletLogic constructor.
* @param CreatesWallet $createsWallet
* @param GeneratesWalletCode $generatesWalletCode
* @param CanCreateCompanyWallet $canCreateCompanyWallet
*/
public function __construct(CanListWallet $canListWallet, ListsWallet $listsWallet)
{
$this->canListWallet = $canListWallet;
$this->listsWallet = $listsWallet;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
//$this->canListWallet->passes();
$query = $this->listsWallet->execute($this->listsWallet->deserializeFilters($request->input('filters')));
return $this->collectionResponse(WalletResource::collection($query));
}
}
@@ -0,0 +1,72 @@
<?php
namespace App\Classes\Modules\Wallets\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Wallets\Services\ListsWallet;
use App\Classes\Modules\Wallets\Services\FetchesWallet;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\Modules\Wallets\Standards\Rules\CanTopUpWallet;
use App\Http\Resources\WalletResource;
use App\Classes\Modules\Transactions\Processors\CreateWalletTransactionProcessor;
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 FetchesWallet */
private $fetchesWallet;
/** @var CanTopUpWallet */
private $canTopUpWallet;
/** @var CreateWalletTransactionProcessor */
private $createWalletTransactionProcessor;
/**
* CreateWalletLogic constructor.
* @param CreatesWallet $createsWallet
* @param GeneratesWalletCode $generatesWalletCode
* @param CanCreateCompanyWallet $canCreateCompanyWallet
*/
public function __construct(CanTopUpWallet $canTopUpWallet, FetchesWallet $fetchesWallet, CreateWalletTransactionProcessor $createWalletTransactionProcessor)
{
$this->canTopUpWallet = $canTopUpWallet;
$this->fetchesWallet = $fetchesWallet;
$this->createWalletTransactionProcessor = $createWalletTransactionProcessor;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
$wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]);
$walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $request->input('amount'));
$this->canTopUpWallet->passes($walletOject);
$transaction = $this->createWalletTransactionProcessor->execute($wallet, $walletOject, TransactionType::TOP_UP);
return $this->resourceResponse(new WalletResource($wallet));
}
}
@@ -0,0 +1,69 @@
<?php
namespace App\Classes\Modules\Wallets\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Wallets\Services\ListsWallet;
use App\Classes\Modules\Wallets\Services\FetchesWallet;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\Modules\Wallets\Standards\Rules\CanListWallet;
use App\Http\Resources\WalletResource;
use App\Classes\Modules\Transactions\Processors\UpdateWalletTransactionProcessor;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class UpdateStatusWalletLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Update Status Transaction Company Wallet',
'message' => 'You have successfully status transaction company wallet'
];
}
/** @var ListWallet */
private $fetchesWallet;
/** @var CanCreateCompanyWallet */
private $canListWallet;
/** @var UpdateWalletTransactionProcessor */
private $updateWalletTransactionProcessor;
/**
* CreateWalletLogic constructor.
* @param CreatesWallet $createsWallet
* @param GeneratesWalletCode $generatesWalletCode
* @param CanCreateCompanyWallet $canCreateCompanyWallet
*/
public function __construct(FetchesWallet $fetchesWallet, UpdateWalletTransactionProcessor $updateWalletTransactionProcessor)
{
$this->fetchesWallet = $fetchesWallet;
$this->updateWalletTransactionProcessor = $updateWalletTransactionProcessor;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
$status = ($request->route('status')=='approve') ? 2 : 4;
$wallet = $this->updateWalletTransactionProcessor->execute($request->route('transaction_id'), $status);
return $this->resourceResponse(new WalletResource($wallet));
}
}
@@ -0,0 +1,72 @@
<?php
namespace App\Classes\Modules\Wallets\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Wallets\Services\ListsWallet;
use App\Classes\Modules\Wallets\Services\FetchesWallet;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\Modules\Wallets\Standards\Rules\CanWithdrawWallet;
use App\Http\Resources\WalletResource;
use App\Classes\Modules\Transactions\Processors\CreateWalletTransactionProcessor;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class WithdrawWalletLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Withdraw from Company Wallet',
'message' => 'You have successfully withdraw company wallet'
];
}
/** @var FetchesWallet */
private $fetchesWallet;
/** @var CanWithdrawWallet */
private $canWithdrawWallet;
/** @var CreateWalletTransactionProcessor */
private $createWalletTransactionProcessor;
/**
* CreateWalletLogic constructor.
* @param CreatesWallet $createsWallet
* @param GeneratesWalletCode $generatesWalletCode
* @param CanCreateCompanyWallet $canCreateCompanyWallet
*/
public function __construct(CanWithdrawWallet $canWithdrawWallet, FetchesWallet $fetchesWallet, CreateWalletTransactionProcessor $createWalletTransactionProcessor)
{
$this->canWithdrawWallet = $canWithdrawWallet;
$this->fetchesWallet = $fetchesWallet;
$this->createWalletTransactionProcessor = $createWalletTransactionProcessor;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
$wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]);
$walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $request->input('amount'));
$this->canWithdrawWallet->passes($walletOject);
$transaction = $this->createWalletTransactionProcessor->execute($wallet, $walletOject, TransactionType::WITHDRAW);
return $this->resourceResponse(new WalletResource($wallet));
}
}
@@ -16,17 +16,20 @@ class WalletObject implements DataTransferObject
/** @var int */
private $code;
private $amount;
/**
* WalletObject constructor.
* @param int $company_id
* @param int $currency
* @param int $code
*/
public function __construct(int $company_id, int $currency, int $code)
public function __construct(int $company_id, int $currency, int $code, float $amount=0)
{
$this->company_id = $company_id;
$this->currency_id = $currency;
$this->code = $code;
$this->amount = $amount;
}
/**
@@ -53,7 +56,10 @@ class WalletObject implements DataTransferObject
return $this->code;
}
public function getAmount(): float
{
return $this->amount;
}
}
}
@@ -3,24 +3,26 @@
namespace App\Classes\Modules\Wallets\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Models\Wallet;
use App\Models\Company;
class CreatesWallet extends AbstractUpdateRecord
class CreatesWallet extends AbstractUpdateRelationshipRecord
{
/**
* @param WalletObject $object
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(WalletObject $object) {
public function execute(WalletObject $object, Company $company) {
$model = new Wallet();
$model->company_id = $object->getCompanyId();
//$model->company_id = $object->getCompanyId();
$model->code = $object->getCode();
$model->currency_id = $object->getCurrency();
return $this->handler($model);
return $this->handler($company->wallets(), $model);
}
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Classes\Modules\Wallets\Services;
use Illuminate\Database\Eloquent\Builder;
use App\Classes\General\Eloquent\AbstractListRecord;
use App\Models\Wallet;
class ListsWallet extends AbstractListRecord
{
/** @var Booking */
private $repository;
/**
* ListsBookings constructor.
* @param Booking $repository
*/
public function __construct(Wallet $repository)
{
$this->repository = $repository;
}
/**
* @return Builder
*/
public function getRepository(): Builder
{
return $this->repository->newQuery();
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Classes\Modules\Wallets\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Models\Wallet;
use App\Models\Company;
class UpdatesWallet extends AbstractUpdateRecord
{
/**
* @param WalletObject $object
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Wallet $model, WalletObject $object) {
$model->amount = $object->getAmount();
$model->code = $object->getCode();
$model->currency_id = $object->getCurrency();
return $this->handler($model);
}
}
@@ -0,0 +1,51 @@
<?php
namespace App\Classes\Modules\Wallets\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Wallets\Standards\Validators\ListWalletValidation;
class CanListWallet extends AbstractRule
{
/** @var ListWalletValidation */
private $listWalletValidation;
public function __construct(ListWalletValidation $listWalletValidation)
{
$this->listWalletValidation = $listWalletValidation;
}
/**
* @return bool
*/
protected function authorized(): bool
{
// TODO Set Authorization rules
return true;
}
/**
* @param WalletObject $object
* @return bool
* @throws \App\Classes\Exceptions\RequestValidationException
*/
protected function validators($object): bool
{
return $this->listWalletValidation->validate($object);
}
/**
* @param WalletTransactionObject $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,51 @@
<?php
namespace App\Classes\Modules\Wallets\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Wallets\Standards\Validators\TopUpWalletValidation;
class CanTopUpWallet extends AbstractRule
{
/** @var TopUpWalletValidation */
private $topUpWalletValidation;
public function __construct(TopUpWalletValidation $topUpWalletValidation)
{
$this->topUpWalletValidation = $topUpWalletValidation;
}
/**
* @return bool
*/
protected function authorized(): bool
{
// TODO Set Authorization rules
return true;
}
/**
* @param WalletObject $object
* @return bool
* @throws \App\Classes\Exceptions\RequestValidationException
*/
protected function validators($object): bool
{
return $this->topUpWalletValidation->validate($object);
}
/**
* @param WalletTransactionObject $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,51 @@
<?php
namespace App\Classes\Modules\Wallets\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Wallets\Standards\Validators\WithdrawWalletValidation;
class CanWithdrawWallet extends AbstractRule
{
/** @var WithdrawWalletValidation */
private $witdrawWalletValidation;
public function __construct(WithdrawWalletValidation $witdrawWalletValidation)
{
$this->witdrawWalletValidation = $witdrawWalletValidation;
}
/**
* @return bool
*/
protected function authorized(): bool
{
// TODO Set Authorization rules
return true;
}
/**
* @param WalletObject $object
* @return bool
* @throws \App\Classes\Exceptions\RequestValidationException
*/
protected function validators($object): bool
{
return $this->witdrawWalletValidation->validate($object);
}
/**
* @param WalletTransactionObject $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Classes\Modules\Wallets\Standards\Validators;
use App\Classes\General\Abstracts\AbstractValidation;
class ListWalletValidation extends AbstractValidation
{
protected function data($object): array
{
return [];
}
/**
* @return array
*/
protected function rules(): array
{
return [];
}
/**
* @return array
*/
protected function messages(): array
{
return [];
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Classes\Modules\Wallets\Standards\Validators;
use App\Classes\General\Abstracts\AbstractValidation;
class TopUpWalletValidation extends AbstractValidation
{
protected function data($object): array
{
return [];
}
/**
* @return array
*/
protected function rules(): array
{
return [];
}
/**
* @return array
*/
protected function messages(): array
{
return [];
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Classes\Modules\Wallets\Standards\Validators;
use App\Classes\General\Abstracts\AbstractValidation;
class WithdrawWalletValidation extends AbstractValidation
{
protected function data($object): array
{
return [];
}
/**
* @return array
*/
protected function rules(): array
{
return [];
}
/**
* @return array
*/
protected function messages(): array
{
return [];
}
}
@@ -23,4 +23,6 @@ final class TransactionType {
public const SUPPLIER_DELIVER = 8;
public const CREDIT_NOTE = 9;
public const WITHDRAW = 10;
}
@@ -0,0 +1,14 @@
<?php
namespace App\Http\Controllers\Wallets;
use App\Classes\Modules\Wallets\ControllersLogic\ListWalletLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ListWalletController
{
public function list(Request $request, ListWalletLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Controllers\Wallets;
use App\Classes\Modules\Wallets\ControllersLogic\TopUpWalletLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class TopUpWalletController
{
public function topUp(Request $request, TopUpWalletLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,14 @@
<?php
namespace App\Http\Controllers\Wallets;
use App\Classes\Modules\Wallets\ControllersLogic\UpdateStatusWalletLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateStatusWalletController
{
public function updateStatus(Request $request, UpdateStatusWalletLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Controllers\Wallets;
use App\Classes\Modules\Wallets\ControllersLogic\WithdrawWalletLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class WithdrawWalletController
{
public function withdraw(Request $request, WithdrawWalletLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
+6 -1
View File
@@ -47,7 +47,12 @@ class BookingResource extends JsonResource
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'),
$this->mergeWhen($this->relationLoaded('transactions'), [
'purchase_order' => new TransactionResource($this->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first()),
'payment_attempts' => TransactionResource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->get()),
'payment_attempts' => TransactionResource::collection(
$this->transactions()
->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)
->whereDate('expires_on', '>=', Carbon::now())
->get()
),
'expired_payment_attempts' => TransactionResource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '<', Carbon::now())->get()),
'payment_history' => TransactionResource::collection($this->transactions()->where(function($query){
$query->where(function($query){
+5 -4
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use App\Classes\General\Interfaces\Documentable;
use App\Classes\General\Interfaces\Transactionable;
use App\Classes\ValueObjects\Constants\RoleTypes;
use App\Scopes\CustomerBookingsScope;
use Illuminate\Database\Eloquent\Builder;
@@ -24,7 +25,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property \App\Models\Currency convertible_currency_id
* @property \App\Models\Currency conversion_currency_id
*/
class Booking extends AbstractModel implements Documentable
class Booking extends AbstractModel implements Documentable, Transactionable
{
use SoftDeletes;
@@ -89,11 +90,11 @@ class Booking extends AbstractModel implements Documentable
}
/**
* @return HasMany
* @return MorphMany
*/
public function transactions(): HasMany
public function transactions(): MorphMany
{
return $this->HasMany(Transaction::class, 'booking_id');
return $this->MorphMany(Transaction::class, 'owner');
}
protected static function booted()
+9 -1
View File
@@ -99,7 +99,15 @@ class Company extends AbstractModel implements Documentable
*/
public function transactions(): hasManyDeep
{
return $this->hasManyDeep(Transaction::class, [Booking::class], ['company_id', 'booking_id'], ['id', 'id']);
return $this->hasManyDeep(Transaction::class, [Booking::class], ['company_id', 'owner_id'], ['id', 'id']);
}
/**
* @return MorphMany
*/
public function wallets(): morphMany
{
return $this->morphMany(Wallet::class, 'owner');
}
/**
+25 -3
View File
@@ -12,18 +12,40 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class Transaction extends AbstractModel implements Documentable
{
protected $table = 'transactions';
public function owner(): morphTo
{
return $this->morphTo();
}
/**
* @return BelongsTo
* @return MorphMany
*/
public function booking(): BelongsTo
{
return $this->BelongsTo( Booking::class, 'booking_id', 'id');
return $this->BelongsTo(Booking::class, 'owner_id', 'id');
}
/**
* @return MorphMany
*/
public function wallets(): morphMany
{
return $this->morphMany(Wallet::class, 'owner');
}
/**
* @return BelongsTo
*/
public function wallet(): BelongsTo
{
return $this->BelongsTo(Wallet::class, 'owner_id', 'id');
}
/**
@@ -135,6 +157,6 @@ class Transaction extends AbstractModel implements Documentable
*/
public function scopeTransferred(Builder $query)
{
return $query->whereIn('status', [ApprovalStatus::COMPLETED]);
return $query->whereIn('status', [ApprovalStatus::APPROVED]);
}
}
+23 -5
View File
@@ -2,16 +2,34 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
class Wallet extends AbstractModel
{
protected $table = 'wallets';
use SoftDeletes;
public function company(): HasOne
protected $table = 'wallets';
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function owner(): morphTo
{
return $this->hasOne(Company::class, 'company_id', 'id');
return $this->morphTo();
}
public function company(): BelongsTo
{
return $this->BelongsTo(Company::class, 'owner_id', 'id');
}
/**
* @return morphMany
*/
public function transactions(): morphMany
{
return $this->morphMany(Transaction::class, 'owner');
}
}
+1
View File
@@ -14,6 +14,7 @@
"ext-zip": "*",
"barryvdh/laravel-dompdf": "^0.9.0",
"carlos-meneses/laravel-mpdf": "^2.1",
"doctrine/dbal": "2.*",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
"guzzlehttp/guzzle": "^6.3",
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class DropWalletTransactionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::dropIfExists('wallet_transaction');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
@@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AlterWalletCompanyId extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasColumn('wallets', 'company_id')) {
Schema::table('wallets', function (Blueprint $table) {
$table->dropForeign('wallets_company_id_foreign');
$table->dropColumn('company_id');
});
}
if (!Schema::hasColumn('wallets', 'owner_id')) {
Schema::table('wallets', function (Blueprint $table) {
$table->morphs('owner');
});
//In-case the model name lengthy
Schema::table('wallets', function (Blueprint $table) {
$table->string('owner_type', 250)->change();
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
@@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class AlterTransactionBookingId extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasColumn('transactions', 'owner_id')) {
Schema::table('transactions', function (Blueprint $table) {
$table->morphs('owner');
});
//In-case the model name lengthy
Schema::table('transactions', function (Blueprint $table) {
$table->string('owner_type', 250)->change();
});
DB::statement("UPDATE transactions SET owner_type='App\\\\Models\\\\Booking', owner_id = booking_id");
Schema::table('transactions', function (Blueprint $table) {
$table->dropForeign('transactions_booking_id_foreign');
$table->dropColumn('booking_id');
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
@@ -328,7 +328,7 @@
<div class="col">
<div class="row">
<div class="col">
<list-component ref="paymentProofList" section="paymentProofSection" :endpoint="route('api.transaction.list')" :options="{status: 2, type: 3, issuer_in: [2]}">
<list-component ref="paymentProofList" section="paymentProofSection" :endpoint="route('api.transaction.list')" :options="{status: 1, type: 3, issuer_in: [2]}">
<template slot="list" slot-scope="{data}">
<payment-proof-component :data="data"></payment-proof-component>
</template>
+3 -2
View File
@@ -14,7 +14,7 @@ use Illuminate\Support\Facades\Route;
*/
Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function () {
require __DIR__ . '/account.php';
// Route::get('/rate/calculate', 'RateCalculateCurrencyController@convert')->name('calculate');
@@ -55,7 +55,8 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function
require __DIR__ . '/billplz.php';
// require __DIR__ . '/wallet.php';
require __DIR__ . '/wallet.php';
// require __DIR__ . '/rate.php';
// require __DIR__ . '/receipt.php';
+5 -3
View File
@@ -3,8 +3,10 @@
use Illuminate\Support\Facades\Route;
Route::group(['prefix' => 'wallets', 'namespace' => 'Wallets', 'as' => 'wallet.'], function () {
Route::get('/', 'ListWalletController@list')->name('list');
Route::post('/create', 'CreateWalletController@create')->name('create');
Route::post('/create-transaction/{id}', 'CreateWalletTransactionController@create')->name('create_transaction');
Route::post('/topup', 'TopUpWalletController@topUp')->name('topup');
Route::post('/withdraw', 'WithdrawWalletController@withdraw')->name('withdraw');
Route::put('/{transaction_id}/update-status/{status}', 'UpdateStatusWalletController@updateStatus')->where('status', 'approve|reject')->name('approval');
});
});