Skip to content

Commit

Permalink
update drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Feb 1, 2024
1 parent c189c9c commit a4466bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/Cart/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
}

Expand Down
25 changes: 8 additions & 17 deletions src/Gateway/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
]);
}

/**
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion src/Http/Controllers/GatewayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit a4466bd

Please sign in to comment.