From 50f2127d4261f275986c1c867c795c0bf4d32d53 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sat, 21 Aug 2021 21:38:02 +0800 Subject: [PATCH 01/11] Refund request - api endpoint for refund request --- .../CreateBookingRefundLogic.php | 100 ++++++++++++++++++ .../CalculatesBookingRefundAmount.php | 18 ++++ .../CreateBookingRefundController.php | 20 ++++ app/Models/Transaction.php | 9 ++ routes/booking.php | 8 ++ 5 files changed, 155 insertions(+) create mode 100644 app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php create mode 100644 app/Classes/Modules/Bookings/Services/CalculatesBookingRefundAmount.php create mode 100644 app/Http/Controllers/Bookings/CreateBookingRefundController.php diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php new file mode 100644 index 00000000..8999832d --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -0,0 +1,100 @@ + 'Create Refund Booking', + 'message' => 'You have successfully created a refund booking' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var FetchesCompanyPaymentAttemptLimit */ + private $fetchesCompanyPaymentAttemptLimit; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var CreatesTransactionDetail */ + private $createsTransactionDetail; + + /** + * CreateBookingPaymentLogic constructor. + * @param FetchesTransaction $fetchesTransaction + * + * @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatesTransaction $createsTransaction + */ + public function __construct(FetchesTransaction $fetchesTransaction, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CreatesTransactionDetail $createsTransactionDetail) + { + $this->fetchesTransaction = $fetchesTransaction; + $this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->createsTransactionDetail = $createsTransactionDetail; + } + + /** + * @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->input('payment_id')]); + + $paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company); + + $billNumber = $this->generatesTransactionBillNumber->execute('RFD-'); + + $object = new TransactionObject($billNumber, TransactionType::REFUND, 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); + + $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)); + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/CalculatesBookingRefundAmount.php b/app/Classes/Modules/Bookings/Services/CalculatesBookingRefundAmount.php new file mode 100644 index 00000000..2dec77fa --- /dev/null +++ b/app/Classes/Modules/Bookings/Services/CalculatesBookingRefundAmount.php @@ -0,0 +1,18 @@ +transactions()->refunds()->complete()->sum('original_amount'); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/CreateBookingRefundController.php b/app/Http/Controllers/Bookings/CreateBookingRefundController.php new file mode 100644 index 00000000..e15b8ff8 --- /dev/null +++ b/app/Http/Controllers/Bookings/CreateBookingRefundController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 002d7611..9d1ed5b9 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -84,6 +84,15 @@ class Transaction extends AbstractModel implements Documentable return $query->where('type', TransactionType::BILL); } + /** + * @param Builder $query + * @return Builder + */ + public function scopeRefunds(Builder $query) + { + return $query->where('type', TransactionType::REFUND); + } + /** * @param Builder $query diff --git a/routes/booking.php b/routes/booking.php index 03f9bb3f..5bf7ddba 100644 --- a/routes/booking.php +++ b/routes/booking.php @@ -16,6 +16,14 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking Route::put('/{payment_id}/approval/{status}', 'ApprovePaymentVerificationController@approve')->where('status', 'approve|reject')->name('approval'); }); + 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('{id}/purchase_order/verification', 'ApprovePurchaseOrderController@approve')->name('po.approval'); Route::post('/merge', 'MergeBookingController@merge')->name('merge'); From 5ca508507aedc5bf5c95b7d0d8a6241e96e6397d Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sat, 21 Aug 2021 22:12:29 +0800 Subject: [PATCH 02/11] 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 03/11] 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 080843f2fdbeaadf23014a22970dbb82f4e2b3a9 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Tue, 24 Aug 2021 13:06:47 +0800 Subject: [PATCH 04/11] hide announcement from user profile --- resources/views/pages/settings.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/settings.blade.php b/resources/views/pages/settings.blade.php index 8fb76ae2..b3a8d384 100644 --- a/resources/views/pages/settings.blade.php +++ b/resources/views/pages/settings.blade.php @@ -570,7 +570,7 @@
-
+
From 1f35b6c456657c690fa0106026d00175cda5070f Mon Sep 17 00:00:00 2001 From: omair saleh Date: Tue, 24 Aug 2021 13:09:03 +0800 Subject: [PATCH 05/11] hide announcement from user profile --- resources/views/pages/settings.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/settings.blade.php b/resources/views/pages/settings.blade.php index b3a8d384..299e32de 100644 --- a/resources/views/pages/settings.blade.php +++ b/resources/views/pages/settings.blade.php @@ -515,7 +515,7 @@
-
+
From 42d064d07f06da87786ef0ba4a80cffc9d8566c9 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Thu, 26 Aug 2021 15:09:32 +0800 Subject: [PATCH 06/11] add cancel order and restore order function --- .../ControllersLogic/CancelBookingLogic.php | 68 +++++++++++++++++++ .../ControllersLogic/RestoreBookingLogic.php | 68 +++++++++++++++++++ .../Bookings/Services/CancelsBooking.php | 24 +++++++ .../Bookings/Services/RestoresBooking.php | 24 +++++++ .../Standards/Rules/CanDeleteBooking.php | 2 +- .../Bookings/CancelBookingController.php | 19 ++++++ .../Bookings/RestoreBookingController.php | 19 ++++++ .../bookings/elements/BookingComponent.vue | 22 ++++-- .../forms/CancelBookingFormComponent.vue | 40 +++++++++++ .../forms/RestoreBookingFormComponent.vue | 40 +++++++++++ routes/booking.php | 2 + 11 files changed, 323 insertions(+), 5 deletions(-) create mode 100644 app/Classes/Modules/Bookings/ControllersLogic/CancelBookingLogic.php create mode 100644 app/Classes/Modules/Bookings/ControllersLogic/RestoreBookingLogic.php create mode 100644 app/Classes/Modules/Bookings/Services/CancelsBooking.php create mode 100644 app/Classes/Modules/Bookings/Services/RestoresBooking.php create mode 100644 app/Http/Controllers/Bookings/CancelBookingController.php create mode 100644 app/Http/Controllers/Bookings/RestoreBookingController.php create mode 100644 resources/assets/vue/components/bookings/forms/CancelBookingFormComponent.vue create mode 100644 resources/assets/vue/components/bookings/forms/RestoreBookingFormComponent.vue diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CancelBookingLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CancelBookingLogic.php new file mode 100644 index 00000000..29692a89 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/CancelBookingLogic.php @@ -0,0 +1,68 @@ + 'Cancel Booking', + 'message' => 'You have successfully canceled the Booking' + ]; + } + + + /** @var FetchesBooking */ + private $fetchesBooking; + + /** @var CancelsBooking */ + private $cancelsBooking; + + /** + * CancelBookingLogic constructor. + * @param FetchesBooking $fetchesBooking + * @param CancelsBooking $cancelsBooking + */ + public function __construct(FetchesBooking $fetchesBooking, CancelsBooking $cancelsBooking) + { + $this->fetchesBooking = $fetchesBooking; + $this->cancelsBooking = $cancelsBooking; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]); + + $bookingActivePayments = $booking->transactions()->where('type', '=', TransactionType::PAYMENT)->where('status', '!=', ApprovalStatus::PENDING_SUBMISSION)->get(); + + if(count($bookingActivePayments)){ + throw new MalformedRequestException('You can\'t cancel an order with active payments'); + } + + $this->cancelsBooking->execute($booking); + + return $this->resourceResponse(new BookingResource($booking)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/ControllersLogic/RestoreBookingLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/RestoreBookingLogic.php new file mode 100644 index 00000000..2ad8fa26 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/RestoreBookingLogic.php @@ -0,0 +1,68 @@ + 'Restore Booking', + 'message' => 'You have successfully restored the Booking' + ]; + } + + /** @var CanDeleteBooking */ + private $canDeleteBooking; + + /** @var FetchesBooking */ + private $fetchesBooking; + + /** @var RestoresBooking */ + private $restoresBooking; + + /** + * RestoreBookingLogic constructor. + * @param CanDeleteBooking $canDeleteBooking + * @param FetchesBooking $fetchesBooking + * @param RestoresBooking $restoresBooking + */ + public function __construct(CanDeleteBooking $canDeleteBooking, FetchesBooking $fetchesBooking, RestoresBooking $restoresBooking) + { + $this->canDeleteBooking = $canDeleteBooking; + $this->fetchesBooking = $fetchesBooking; + $this->restoresBooking = $restoresBooking; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]); + + $this->restoresBooking->execute($booking); + + return $this->resourceResponse(new BookingResource($booking)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/CancelsBooking.php b/app/Classes/Modules/Bookings/Services/CancelsBooking.php new file mode 100644 index 00000000..dd9b12f3 --- /dev/null +++ b/app/Classes/Modules/Bookings/Services/CancelsBooking.php @@ -0,0 +1,24 @@ +status = ApprovalStatus::SUSPENDED; + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/RestoresBooking.php b/app/Classes/Modules/Bookings/Services/RestoresBooking.php new file mode 100644 index 00000000..9efef208 --- /dev/null +++ b/app/Classes/Modules/Bookings/Services/RestoresBooking.php @@ -0,0 +1,24 @@ +status = ApprovalStatus::APPROVED; + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Standards/Rules/CanDeleteBooking.php b/app/Classes/Modules/Bookings/Standards/Rules/CanDeleteBooking.php index 1b5acee4..dfd307bc 100644 --- a/app/Classes/Modules/Bookings/Standards/Rules/CanDeleteBooking.php +++ b/app/Classes/Modules/Bookings/Standards/Rules/CanDeleteBooking.php @@ -34,7 +34,7 @@ class CanDeleteBooking extends AbstractRule /** - * @param BookingObject $object + * @param $object * @return bool */ protected function criteria($object): bool diff --git a/app/Http/Controllers/Bookings/CancelBookingController.php b/app/Http/Controllers/Bookings/CancelBookingController.php new file mode 100644 index 00000000..f31a80a1 --- /dev/null +++ b/app/Http/Controllers/Bookings/CancelBookingController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/RestoreBookingController.php b/app/Http/Controllers/Bookings/RestoreBookingController.php new file mode 100644 index 00000000..5b4aa809 --- /dev/null +++ b/app/Http/Controllers/Bookings/RestoreBookingController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/elements/BookingComponent.vue b/resources/assets/vue/components/bookings/elements/BookingComponent.vue index febce6ba..509e9840 100644 --- a/resources/assets/vue/components/bookings/elements/BookingComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BookingComponent.vue @@ -52,17 +52,26 @@ Pending...
-
+
- +
+ +
+
+ +
+ + + + + +
@@ -70,6 +79,11 @@ \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/forms/CancelBookingFormComponent.vue b/resources/assets/vue/components/bookings/forms/CancelBookingFormComponent.vue new file mode 100644 index 00000000..b32275f1 --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/CancelBookingFormComponent.vue @@ -0,0 +1,40 @@ + + \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/forms/RestoreBookingFormComponent.vue b/resources/assets/vue/components/bookings/forms/RestoreBookingFormComponent.vue new file mode 100644 index 00000000..3cd2227d --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/RestoreBookingFormComponent.vue @@ -0,0 +1,40 @@ + + \ No newline at end of file diff --git a/routes/booking.php b/routes/booking.php index 03f9bb3f..5fc970c4 100644 --- a/routes/booking.php +++ b/routes/booking.php @@ -7,6 +7,8 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking Route::get('/list', 'ListBookingsController@list')->name('list'); Route::post('/create', 'CreateBookingController@create')->name('create'); Route::put('/update/{id}', 'UpdateBookingController@update')->name('update'); + Route::put('/cancel/{id}', 'CancelBookingController@cancel')->name('cancel'); + Route::put('/restore/{id}', 'RestoreBookingController@restore')->name('restore'); Route::delete('/delete/{id}', 'DeleteBookingController@delete')->name('delete'); Route::group(['prefix' => '{id}/payment', 'as' => 'payment.'], function () { From 509a681bcc99b2a8adeac8d5f0272a3e511f1e42 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Fri, 27 Aug 2021 15:19:58 +0800 Subject: [PATCH 07/11] add cancel order and restore order function --- .../Modules/Bookings/ControllersLogic/CancelBookingLogic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CancelBookingLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CancelBookingLogic.php index 29692a89..6a6fedef 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CancelBookingLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CancelBookingLogic.php @@ -54,7 +54,7 @@ class CancelBookingLogic extends AbstractControllerLogic { $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]); - $bookingActivePayments = $booking->transactions()->where('type', '=', TransactionType::PAYMENT)->where('status', '!=', ApprovalStatus::PENDING_SUBMISSION)->get(); + $bookingActivePayments = $booking->transactions()->where('type', '=', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->get(); if(count($bookingActivePayments)){ throw new MalformedRequestException('You can\'t cancel an order with active payments'); From 338b8dd648be1bfd46f5e16964f8e6936a5d6f87 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sat, 28 Aug 2021 10:28:38 +0800 Subject: [PATCH 08/11] 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 09/11] 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 10/11] 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 11/11] 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