mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 20:43:56 +00:00
101 lines
4.1 KiB
PHP
101 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Bookings\ControllersLogic;
|
|
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Accounts\Services\GeneratesAuthenticationToken;
|
|
use App\Classes\Modules\Accounts\Services\GeneratesAuthenticationTokenWithBookingId;
|
|
use App\Classes\Modules\Bookings\Services\FetchesBooking;
|
|
use App\Classes\Modules\Bookings\Standards\Rules\CanFetchBooking;
|
|
use App\Http\Resources\BookingResource;
|
|
use App\Models\Booking;
|
|
use App\Models\ShippingOrderBooking;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class TrackBookingShipmentLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => '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}");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} |