diff --git a/src/Cart/Driver.php b/src/Cart/Driver.php index 4686dc79..d44977b6 100644 --- a/src/Cart/Driver.php +++ b/src/Cart/Driver.php @@ -250,8 +250,8 @@ public function isEmpty(): bool */ public function checkout(string $driver): Response { - return App::call(static function (Request $request) use ($driver): Response { - return Gateway::driver($driver)->handleCheckout($request); + return App::call(function (Request $request) use ($driver): Response { + return Gateway::driver($driver)->handleCheckout($request, $this->getModel()->toOrder()); }); } diff --git a/src/Gateway/Driver.php b/src/Gateway/Driver.php index d4091d56..af702a1b 100644 --- a/src/Gateway/Driver.php +++ b/src/Gateway/Driver.php @@ -9,7 +9,6 @@ use Cone\Bazar\Models\Order; use Cone\Bazar\Models\Transaction; use Cone\Bazar\Support\Driver as BaseDriver; -use Cone\Bazar\Support\Facades\Cart; use Illuminate\Http\Request; use Illuminate\Http\Response as HttpResponse; use Illuminate\Support\Facades\Config; @@ -65,7 +64,9 @@ public function getSuccessUrl(Order $order): string { $url = $this->config['success_url'] ?? Config::get('bazar.gateway.urls.success'); - return URL::to(str_replace(['{order}'], [$order->uuid], $url ?? '/')); + return URL::to(str_replace(['{order}'], [$order->uuid], $url ?? '/'), [ + 'driver' => $this->name, + ]); } /** @@ -75,24 +76,16 @@ public function getFailureUrl(Order $order): string { $url = $this->config['failure_url'] ?? Config::get('bazar.gateway.urls.failure'); - return URL::to(str_replace(['{order}'], [$order->uuid], $url ?? '/')); - } - - /** - * Resolve the order model for checkout. - */ - public function resolveOrderForCheckout(Request $request): Order - { - return Cart::getModel()->toOrder(); + return URL::to(str_replace(['{order}'], [$order->uuid], $url ?? '/'), [ + 'driver' => $this->name, + ]); } /** * Handle the checkout request. */ - public function handleCheckout(Request $request): Response + public function handleCheckout(Request $request, Order $order): Response { - $order = $this->resolveOrderForCheckout($request); - try { $this->checkout($request, $order); @@ -129,10 +122,8 @@ public function resolveOrderForCapture(Request $request): Order /** * Handle the capture request. */ - public function handleCapture(Request $request): Response + public function handleCapture(Request $request, Order $order): Response { - $order = $this->resolveOrderForCapture($request); - try { $this->capture($request, $order); diff --git a/src/Http/Controllers/GatewayController.php b/src/Http/Controllers/GatewayController.php index b9fd846b..b407622b 100644 --- a/src/Http/Controllers/GatewayController.php +++ b/src/Http/Controllers/GatewayController.php @@ -13,7 +13,9 @@ class GatewayController extends Controller */ public function capture(Request $request, string $driver): Response { - return Gateway::driver($driver)->handleCapture($request)->toResponse($request); + $gateway = Gateway::driver($driver); + + return $gateway->handleCapture($request, $gateway->resolveOrderForCapture($request))->toResponse($request); } /**