From 5ca508507aedc5bf5c95b7d0d8a6241e96e6397d Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sat, 21 Aug 2021 22:12:29 +0800 Subject: [PATCH 1/6] added full payment refund request api endpoint --- routes/booking.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/routes/booking.php b/routes/booking.php index 5bf7ddba..eae751e8 100644 --- a/routes/booking.php +++ b/routes/booking.php @@ -20,10 +20,6 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking 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('{id}/purchase_order/verification', 'ApprovePurchaseOrderController@approve')->name('po.approval'); Route::post('/merge', 'MergeBookingController@merge')->name('merge'); From f6425f82bc4b197980663623c8ea9c554a25db1c Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Mon, 23 Aug 2021 09:55:55 +0800 Subject: [PATCH 2/6] edit full payment refund request api endpoint --- .../Bookings/ControllersLogic/CreateBookingRefundLogic.php | 2 +- routes/booking.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 8999832d..21cc5406 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -75,7 +75,7 @@ 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')]); $paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company); diff --git a/routes/booking.php b/routes/booking.php index eae751e8..ed188127 100644 --- a/routes/booking.php +++ b/routes/booking.php @@ -17,7 +17,7 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking }); Route::group(['prefix' => '{id}/refund', 'as' => 'refund.'], function () { - Route::post('create', 'CreateBookingRefundController@create')->name('create'); + Route::post('{payment_id}/create', 'CreateBookingRefundController@create')->name('create'); }); Route::post('{id}/purchase_order/verification', 'ApprovePurchaseOrderController@approve')->name('po.approval'); From 338b8dd648be1bfd46f5e16964f8e6936a5d6f87 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sat, 28 Aug 2021 10:28:38 +0800 Subject: [PATCH 3/6] Add update transaction status to refunded transaction --- .../CreateBookingRefundLogic.php | 21 ++++++++----------- .../ValueObjects/Constants/ApprovalStatus.php | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 21cc5406..0ec53d9b 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -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; } /** @@ -88,10 +87,8 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $transaction->tax, $transaction->service_charge, Carbon::now()->addMinutes($paymentAttemptLimit), ApprovalStatus::PENDING_VERIFICATION); $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); + + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::REFUNDED); return $this->resourceResponse(new TransactionResource($transaction)); } diff --git a/app/Classes/ValueObjects/Constants/ApprovalStatus.php b/app/Classes/ValueObjects/Constants/ApprovalStatus.php index 6f9932ff..154db2ca 100644 --- a/app/Classes/ValueObjects/Constants/ApprovalStatus.php +++ b/app/Classes/ValueObjects/Constants/ApprovalStatus.php @@ -18,5 +18,5 @@ final class ApprovalStatus { public const EXPIRED = 6; - public const REFUNDED = 6; + public const REFUNDED = 7; } From f63f57ad57cf9eb127eda0095293c955e9bf0ec3 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sat, 28 Aug 2021 10:39:00 +0800 Subject: [PATCH 4/6] Add update transaction status to refunded transaction --- .../Bookings/ControllersLogic/CreateBookingRefundLogic.php | 4 ++-- .../Controllers/Bookings/CreateBookingRefundController.php | 2 +- routes/booking.php | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 0ec53d9b..843ecb88 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -75,6 +75,8 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $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); @@ -87,8 +89,6 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $transaction->tax, $transaction->service_charge, Carbon::now()->addMinutes($paymentAttemptLimit), ApprovalStatus::PENDING_VERIFICATION); $transaction = $this->createsTransaction->execute($booking, $object); - - $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::REFUNDED); return $this->resourceResponse(new TransactionResource($transaction)); } diff --git a/app/Http/Controllers/Bookings/CreateBookingRefundController.php b/app/Http/Controllers/Bookings/CreateBookingRefundController.php index e15b8ff8..40d4ddda 100644 --- a/app/Http/Controllers/Bookings/CreateBookingRefundController.php +++ b/app/Http/Controllers/Bookings/CreateBookingRefundController.php @@ -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 { diff --git a/routes/booking.php b/routes/booking.php index e7f3d7d4..c2805443 100644 --- a/routes/booking.php +++ b/routes/booking.php @@ -20,6 +20,7 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking Route::group(['prefix' => '{id}/refund', 'as' => 'refund.'], function () { 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'); From 43530352ee848799ca548f2ab15d4c00c4b33a0c Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sat, 28 Aug 2021 11:40:04 +0800 Subject: [PATCH 5/6] Add credit note controller and logic --- .../Bookings/ControllersLogic/CreateBookingRefundLogic.php | 4 ++-- routes/booking.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 0ec53d9b..843ecb88 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -75,6 +75,8 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $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); @@ -87,8 +89,6 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $transaction->tax, $transaction->service_charge, Carbon::now()->addMinutes($paymentAttemptLimit), ApprovalStatus::PENDING_VERIFICATION); $transaction = $this->createsTransaction->execute($booking, $object); - - $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::REFUNDED); return $this->resourceResponse(new TransactionResource($transaction)); } diff --git a/routes/booking.php b/routes/booking.php index e7f3d7d4..c2805443 100644 --- a/routes/booking.php +++ b/routes/booking.php @@ -20,6 +20,7 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking Route::group(['prefix' => '{id}/refund', 'as' => 'refund.'], function () { 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'); From 410c55e2bf010f21db2eea37763fe3188b6ac8f1 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sun, 29 Aug 2021 20:52:43 +0800 Subject: [PATCH 6/6] Add credit note controller and logic --- .../CreateBookingRefundCreditNoteLogic.php | 97 +++++++++++++++++++ ...reateBookingRefundCreditNoteController.php | 20 ++++ 2 files changed, 117 insertions(+) create mode 100644 app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundCreditNoteLogic.php create mode 100644 app/Http/Controllers/Bookings/CreateBookingRefundCreditNoteController.php diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundCreditNoteLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundCreditNoteLogic.php new file mode 100644 index 00000000..9c66abc5 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundCreditNoteLogic.php @@ -0,0 +1,97 @@ + '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)); + } + + +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/CreateBookingRefundCreditNoteController.php b/app/Http/Controllers/Bookings/CreateBookingRefundCreditNoteController.php new file mode 100644 index 00000000..4e54678a --- /dev/null +++ b/app/Http/Controllers/Bookings/CreateBookingRefundCreditNoteController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file