From a0ca37ec16f4fe8c7c27b35616ca02e8d48bce35 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Mon, 27 Mar 2023 23:47:59 +0800 Subject: [PATCH] multi payment final --- .../DataTransferObjects/GroupObject.php | 173 ++++++++++++++++++ .../Modules/Groups/Services/CreatesGroup.php | 32 ++++ .../ControllersLogic/CreateGroupsLogic.php | 39 ++-- 3 files changed, 229 insertions(+), 15 deletions(-) create mode 100644 app/Classes/Modules/Groups/DataTransferObjects/GroupObject.php create mode 100644 app/Classes/Modules/Groups/Services/CreatesGroup.php diff --git a/app/Classes/Modules/Groups/DataTransferObjects/GroupObject.php b/app/Classes/Modules/Groups/DataTransferObjects/GroupObject.php new file mode 100644 index 00000000..ef8e0121 --- /dev/null +++ b/app/Classes/Modules/Groups/DataTransferObjects/GroupObject.php @@ -0,0 +1,173 @@ +issuer = $issuer; + $this->receiver = $receiver; + $this->amount = $amount; + $this->originalAmount = $originalAmount; + $this->currencyId = $currencyId; + $this->originalCurrencyId = $originalCurrencyId; + $this->currencyRate = $currencyRate; + $this->tax = $tax; + $this->serviceCharge = $serviceCharge; + $this->reference = $reference; + $this->status = $status; + } + + /** + * @return int + */ + public function getIssuer(): int + { + return $this->issuer; + } + + /** + * @return int + */ + public function getReceiver(): int + { + return $this->receiver; + } + + /** + * @return float + */ + public function getAmount(): float + { + return $this->amount; + } + + /** + * @return float + */ + public function getOriginalAmount(): float + { + return $this->originalAmount; + } + + /** + * @return int + */ + public function getCurrencyId(): int + { + return $this->currencyId; + } + + /** + * @return int + */ + public function getOriginalCurrencyId(): int + { + return $this->originalCurrencyId; + } + + /** + * @return float + */ + public function getCurrencyRate(): float + { + return $this->currencyRate; + } + + /** + * @return float + */ + public function getTax(): float + { + return $this->tax; + } + + /** + * @return float + */ + public function getServiceCharge(): float + { + return $this->serviceCharge; + } + + /** + * @return int + */ + public function getStatus(): ?int + { + return $this->status; + } + + /** + * @return string|null + */ + public function getReference(): ?string + { + return $this->reference; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Groups/Services/CreatesGroup.php b/app/Classes/Modules/Groups/Services/CreatesGroup.php new file mode 100644 index 00000000..1aa2a298 --- /dev/null +++ b/app/Classes/Modules/Groups/Services/CreatesGroup.php @@ -0,0 +1,32 @@ +issuer = $object->getIssuer(); + $model->receiver = $object->getReceiver(); + $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->status = $object->getStatus(); + $model->reference = $object->getReference(); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php index dcc7f1c1..26fc48b7 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php @@ -8,9 +8,11 @@ use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Transactions\Services\FetchesTransaction; use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; use App\Classes\Modules\Companies\Services\FetchesCompanyModule; +use App\Classes\Modules\Groups\DataTransferObjects\GroupObject; use App\Classes\ValueObjects\Constants\PaymentMethodType; use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor; use App\Models\Group; +use App\Classes\Modules\Groups\Services\CreatesGroup; use App\Models\Transaction; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -47,16 +49,19 @@ class CreateGroupsLogic extends AbstractControllerLogic /** @var CreateWalletTopUpTransactionProcessor */ private $createWalletTopUpTransactionProcessor; - /** @var CreatePaymentTransactionProcessor */ private $createPaymentTransactionProcessor; + /** @var CreatesGroup */ + private $createsGroup; + public function __construct( FetchesTransaction $fetchesTransaction, GeneratesTransactionBillNumber $generatesTransactionBillNumber, FetchesCompanyModule $fetchesCompanyModule, CreateWalletTopUpTransactionProcessor $createWalletTopUpTransactionProcessor, - CreatePaymentTransactionProcessor $createPaymentTransactionProcessor + CreatePaymentTransactionProcessor $createPaymentTransactionProcessor, + CreatesGroup $createsGroup ) { $this->fetchesTransaction = $fetchesTransaction; @@ -64,6 +69,7 @@ class CreateGroupsLogic extends AbstractControllerLogic $this->fetchesCompanyModule = $fetchesCompanyModule; $this->createWalletTopUpTransactionProcessor = $createWalletTopUpTransactionProcessor; $this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor; + $this->createsGroup = $createsGroup; } public function logic(Request $request) : JsonResponse @@ -92,7 +98,6 @@ class CreateGroupsLogic extends AbstractControllerLogic $groupPyamentStatus = ApprovalStatus::APPROVED; } - $group = new Group(); $issuer = 0; $receiver = 0; $amount = 0; @@ -102,18 +107,22 @@ class CreateGroupsLogic extends AbstractControllerLogic $currency_rate = 0; $tax = 0; $service_charge = 0; - $group->issuer = $issuer; - $group->receiver = $receiver; - $group->reference = 0; - $group->amount = $amount; - $group->original_amount = $original_amount; - $group->currency_id = $currency_id; - $group->original_currency_id = $original_currency_id; - $group->currency_rate = $currency_rate; - $group->tax = $tax; - $group->service_charge = $service_charge; - $group->payment_method = $payment_method; - $group->save(); + + $group = new GroupObject( + $issuer, + $receiver, + $amount, + $original_amount, + $currency_id, + $original_currency_id, + $currency_rate, + $tax, + $service_charge, + '-', + $groupPyamentStatus, + ); + + $group = $this->createsGroup->execute($group); foreach ($invoices as $invoice) { if ($payment_method == PaymentMethodType::WALLET) {