'Created Booking', 'message' => 'You have successfully created a new Booking' ]; } /** @var CanCreateBooking */ private $canCreateBooking; /** @var CreatesBooking */ private $createsBooking; /** @var GeneratesBookingMarking */ private $generatesBookingMarking; /** @var FetchesCompany */ private $fetchesCompany; /** @var FetchesCompanyBank */ private $fetchesCompanyBank; /** @var FetchesCurrency */ private $fetchesCurrency; /** * CreateSegmentLogic constructor. * @param CanCreateBooking $canCreateBooking * @param CreatesBooking $createsBooking * @param FetchesCompany $fetchesCompany * @param FetchesCompanyBank $fetchesCompanyBank * @param FetchesCurrency $fetchesCurrency */ public function __construct( CanCreateBooking $canCreateBooking, CreatesBooking $createsBooking, GeneratesBookingMarking $generatesBookingMarking, FetchesCompany $fetchesCompany, FetchesCompanyBank $fetchesCompanyBank, FetchesCurrency $fetchesCurrency ) { $this->canCreateBooking = $canCreateBooking; $this->createsBooking = $createsBooking; $this->generatesBookingMarking = $generatesBookingMarking; $this->fetchesCompany = $fetchesCompany; $this->fetchesCompanyBank = $fetchesCompanyBank; $this->fetchesCurrency = $fetchesCurrency; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { try { DB::beginTransaction(); $booking_object = new BookingObject( $request->input('company_id'), $request->input('transferable_bank_id'), $this->generatesBookingMarking->execute(), $request->input('reference'), number_format( (float) $request->input('fix_amount'), 5, '.', ''), $request->input('fix_currency_id'), $request->input('convertible_currency_id'), $request->input('conversion_currency_id') ); $this->canCreateBooking->passes($booking_object); $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); $transferable_bank = $this->fetchesCompanyBank->execute(['id' => $request->input('transferable_bank_id')]); $fix_currency = $this->fetchesCurrency->execute(['id' => $request->input('fix_currency_id')]); $convertible_currency = $this->fetchesCurrency->execute(['id' => $request->input('convertible_currency_id')]); $conversion_currency = $this->fetchesCurrency->execute(['id' => $request->input('conversion_currency_id')]); $booking = $this->createsBooking->execute($booking_object); DB::commit(); return $this->resourceResponse(new BookingResource($booking)); } catch (\Exception $exception) { throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }