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