'Retrieved Shipping Order', 'message' => 'You have successfully retrieved shipping order' ]; } /** @var CanFetchBooking */ private $canFetchBooking; /** @var FetchesBooking */ private $fetchesBooking; /** @var GeneratesAuthenticationToken */ private $generatesAuthenticationToken; /** @var GeneratesAuthenticationTokenWithBookingId */ private $generatesAuthenticationTokenWithBookingId; /** * TrackBookingShipmentLogic constructor. * @param CanFetchBooking $canFetchBooking * @param FetchesBooking $fetchesBooking * @param GeneratesAuthenticationToken $generatesAuthenticationToken * @param GeneratesAuthenticationTokenWithBookingId $generatesAuthenticationTokenWithBookingId */ public function __construct(CanFetchBooking $canFetchBooking, FetchesBooking $fetchesBooking, GeneratesAuthenticationToken $generatesAuthenticationToken, GeneratesAuthenticationTokenWithBookingId $generatesAuthenticationTokenWithBookingId) { $this->canFetchBooking = $canFetchBooking; $this->fetchesBooking = $fetchesBooking; $this->generatesAuthenticationToken = $generatesAuthenticationToken; $this->generatesAuthenticationTokenWithBookingId = $generatesAuthenticationTokenWithBookingId; } /** * @param Request $request * @return void * @throws \App\Classes\Exceptions\AccessForbiddenException * @throws \App\Classes\Exceptions\RequestValidationException */ public function execute(Request $request) { $this->canFetchBooking->passes(); $booking = Booking::where('marking', $request->route('marking'))->first(); $shippingOrder = ShippingOrderBooking::where('booking_id', $booking->id)->first(); $user = Auth::user(); // if booking is connected with shipping order, we want to show the order, therefore exchange booking id is not needed if ($shippingOrder) { $token = $this->generatesAuthenticationToken->execute($user); if (App::environment(['production'])) { dd("Delete this line before push to production"); return redirect("https://izyim.cief-malaysia.com/?exchangeToken={$token}&orderId={$shippingOrder->shipping_order_id}"); } else if (App::environment(['local'])) { return redirect("http://127.0.0.1:8001/?exchangeToken={$token}&orderId={$shippingOrder->shipping_order_id}"); } else { return redirect("https://dev.portal.cief-malaysia.com/?exchangeToken={$token}&orderId={$shippingOrder->shipping_order_id}"); } } else { // else create the order for current booking by putting in booking id into token $token = $this->generatesAuthenticationTokenWithBookingId->execute($user, $booking->id); if (App::environment(['production'])) { dd("Delete this line before push to production"); return redirect("https://izyim.cief-malaysia.com/?exchangeToken={$token}"); } else if (App::environment(['local'])) { return redirect("http://127.0.0.1:8001/?exchangeToken={$token}"); } else { return redirect("https://dev.portal.cief-malaysia.com/?exchangeToken={$token}"); } } } }