From 51188fedef9ab34c9f9391a6e066a52454ee131e Mon Sep 17 00:00:00 2001 From: Rias Date: Wed, 14 Aug 2024 11:14:49 +0200 Subject: [PATCH] Allow client requests to price api --- app/Http/Api/Controllers/PriceController.php | 5 ++++- routes/api.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Api/Controllers/PriceController.php b/app/Http/Api/Controllers/PriceController.php index ab466b42..1ae20a4b 100644 --- a/app/Http/Api/Controllers/PriceController.php +++ b/app/Http/Api/Controllers/PriceController.php @@ -3,11 +3,14 @@ namespace App\Http\Api\Controllers; use App\Domain\Shop\Models\Purchasable; +use Illuminate\Http\Request; class PriceController { - public function __invoke(Purchasable $purchasable, string $ipOrCountryCode) + public function __invoke(Request $request, Purchasable $purchasable, ?string $ipOrCountryCode = null) { + $ipOrCountryCode ??= $request->ip() ?? ''; + $countryCode = strlen($ipOrCountryCode) === 2 ? $ipOrCountryCode : geoip($ipOrCountryCode)->iso_code; diff --git a/routes/api.php b/routes/api.php index 17534cba..47b77c24 100644 --- a/routes/api.php +++ b/routes/api.php @@ -29,7 +29,7 @@ Route::post('activations/{activation:uuid}/version', UpdateCurrentVersionController::class); Route::delete('activations/{activation:uuid}', DeleteActivationController::class); -Route::get('price/{purchasable}/{ipOrCountryCode}', PriceController::class); +Route::get('price/{purchasable}/{ipOrCountryCode?}', PriceController::class); Route::get('bundle-price/{bundle}/{ipOrCountryCode}', BundlePriceController::class);