This commit is contained in:
ahmedsophyudden
2021-09-05 09:58:15 +08:00
7 changed files with 132 additions and 19 deletions
@@ -0,0 +1,97 @@
<?php
namespace App\Classes\Modules\Bookings\ControllersLogic;
use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Companies\Services\FetchesCompanyPaymentAttemptLimit;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Http\Resources\TransactionResource;
use App\Models\Booking;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateBookingRefundCreditNoteLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Create Refund Booking',
'message' => 'You have successfully created a refund booking'
];
}
/** @var FetchesTransaction */
private $fetchesTransaction;
/** @var UpdatesTransactionStatus */
private $updatesTransactionStatus;
/** @var FetchesCompanyPaymentAttemptLimit */
private $fetchesCompanyPaymentAttemptLimit;
/** @var GeneratesTransactionBillNumber */
private $generatesTransactionBillNumber;
/** @var CreatesTransaction */
private $createsTransaction;
/**
* CreateBookingPaymentLogic constructor.
* @param FetchesTransaction $fetchesTransaction
* @param UpdatesTransactionStatus $updatesTransactionStatus
* @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
* @param CreatesTransaction $createsTransaction
*/
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction)
{
$this->fetchesTransaction = $fetchesTransaction;
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit;
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
$this->createsTransaction = $createsTransaction;
}
/**
* @param Request $request
* @return JsonResponse
* @throws MalformedRequestException
*/
public function logic(Request $request) : JsonResponse
{
$booking = Booking::find($request->route('id'));
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('payment_id')]);
$this->updatesTransactionStatus->execute($transaction, ApprovalStatus::REFUNDED);
$paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company);
$billNumber = $this->generatesTransactionBillNumber->execute('CDTN-');
$object = new TransactionObject($billNumber, TransactionType::CREDIT_NOTE, 1, $booking->company->id,
$booking->bank_id, $transaction->payment_method,
$transaction->amount, $transaction->original_amount, 1,
$transaction->original_currency_id, $transaction->currency_rate,
$transaction->tax, $transaction->service_charge, Carbon::now()->addMinutes($paymentAttemptLimit), ApprovalStatus::PENDING_VERIFICATION);
$transaction = $this->createsTransaction->execute($booking, $object);
return $this->resourceResponse(new TransactionResource($transaction));
}
}
@@ -6,11 +6,10 @@ namespace App\Classes\Modules\Bookings\ControllersLogic;
use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Companies\Services\FetchesCompanyPaymentAttemptLimit;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject;
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail;
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
@@ -36,6 +35,9 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
/** @var FetchesTransaction */
private $fetchesTransaction;
/** @var UpdatesTransactionStatus */
private $updatesTransactionStatus;
/** @var FetchesCompanyPaymentAttemptLimit */
private $fetchesCompanyPaymentAttemptLimit;
@@ -45,24 +47,21 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
/** @var CreatesTransaction */
private $createsTransaction;
/** @var CreatesTransactionDetail */
private $createsTransactionDetail;
/**
* CreateBookingPaymentLogic constructor.
* @param FetchesTransaction $fetchesTransaction
*
* @param UpdatesTransactionStatus $updatesTransactionStatus
* @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
* @param CreatesTransaction $createsTransaction
*/
public function __construct(FetchesTransaction $fetchesTransaction, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CreatesTransactionDetail $createsTransactionDetail)
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction)
{
$this->fetchesTransaction = $fetchesTransaction;
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit;
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
$this->createsTransaction = $createsTransaction;
$this->createsTransactionDetail = $createsTransactionDetail;
}
/**
@@ -75,7 +74,9 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
$booking = Booking::find($request->route('id'));
$transaction = $this->fetchesTransaction->execute(['id' => $request->input('payment_id')]);
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('payment_id')]);
$this->updatesTransactionStatus->execute($transaction, ApprovalStatus::REFUNDED);
$paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company);
@@ -89,10 +90,6 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
$transaction = $this->createsTransaction->execute($booking, $object);
$detailObject = new TransactionDetailObject($transaction->bill_no, 'Payment refund for '.$transaction->bill_no, 1, $transaction->original_amount);
$this->createsTransactionDetail->execute($transaction, $detailObject);
return $this->resourceResponse(new TransactionResource($transaction));
}
@@ -18,4 +18,5 @@ final class ApprovalStatus {
public const EXPIRED = 6;
public const REFUNDED = 7;
}
@@ -22,4 +22,5 @@ final class TransactionType {
public const SUPPLIER_DELIVER = 8;
public const CREDIT_NOTE = 9;
}
@@ -10,7 +10,7 @@ class CreateBookingRefundController
{
/**
* @param Request $request
* @param CreateBookingPaymentLogic $logic
* @param CreateBookingRefundLogic $logic
* @return JsonResponse
*/
public function create(Request $request, CreateBookingRefundLogic $logic): JsonResponse {
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Bookings;
use App\Classes\Modules\Bookings\ControllersLogic\CreateBookingRefundCreditNoteLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateBookingRefundCreditNoteController
{
/**
* @param Request $request
* @param CreateBookingRefundCreditNoteLogic $logic
* @return JsonResponse
*/
public function create(Request $request, CreateBookingRefundCreditNoteLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
+2 -5
View File
@@ -19,11 +19,8 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking
});
Route::group(['prefix' => '{id}/refund', 'as' => 'refund.'], function () {
Route::post('create', 'CreateBookingRefundController@create')->name('create');
});
Route::group(['prefix' => '{id}/refund', 'as' => 'refund.'], function () {
Route::post('{payment_id}create', 'CreateBookingRefundController@create')->name('create');
Route::post('{payment_id}/create', 'CreateBookingRefundController@create')->name('create');
Route::post('{payment_id}/credit_note/create', 'CreateBookingRefundCreditNoteController@create')->name('credit_note.create');
});
Route::post('{id}/purchase_order/verification', 'ApprovePurchaseOrderController@approve')->name('po.approval');