diff --git a/composer.json b/composer.json index 7a4244c..3f12377 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fleetbase/storefront-api", - "version": "0.2.11", + "version": "0.3.0", "description": "Headless Commerce & Marketplace Extension for Fleetbase", "keywords": [ "fleetbase-extension", @@ -22,8 +22,8 @@ ], "require": { "php": "^8.0", - "fleetbase/core-api": "^1.4.0", - "fleetbase/fleetops-api": "^0.4.6", + "fleetbase/core-api": "^1.4.3", + "fleetbase/fleetops-api": "^0.4.9", "geocoder-php/google-maps-places-provider": "^1.4", "laravel-notification-channels/apn": "^5.0", "laravel-notification-channels/fcm": "^4.1", diff --git a/extension.json b/extension.json index 20460c8..3d643c1 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "Storefront", - "version": "0.2.11", + "version": "0.3.0", "description": "Headless Commerce & Marketplace Extension for Fleetbase", "repository": "https://github.com/fleetbase/storefront", "license": "MIT", diff --git a/package.json b/package.json index 865bcab..2b178cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fleetbase/storefront-engine", - "version": "0.2.11", + "version": "0.3.0", "description": "Headless Commerce & Marketplace Extension for Fleetbase", "fleetbase": { "route": "storefront", diff --git a/server/src/Http/Controllers/MetricsController.php b/server/src/Http/Controllers/MetricsController.php index 54bc500..6b807fd 100644 --- a/server/src/Http/Controllers/MetricsController.php +++ b/server/src/Http/Controllers/MetricsController.php @@ -9,9 +9,8 @@ class MetricsController extends Controller { /** - * Get all key metrics for a companies storefront + * Get all key metrics for a companies storefront. * - * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function all(Request $request) diff --git a/server/src/Http/Controllers/v1/CartController.php b/server/src/Http/Controllers/v1/CartController.php index 304e2fa..e197116 100644 --- a/server/src/Http/Controllers/v1/CartController.php +++ b/server/src/Http/Controllers/v1/CartController.php @@ -15,7 +15,7 @@ class CartController extends Controller * * @return \Illuminate\Http\Response */ - public function retrieve(string $uniqueId = null, Request $request) + public function retrieve(?string $uniqueId = null, Request $request) { $cart = Cart::retrieve($uniqueId, true); diff --git a/server/src/Http/Controllers/v1/CustomerController.php b/server/src/Http/Controllers/v1/CustomerController.php index b7af784..fa99d38 100644 --- a/server/src/Http/Controllers/v1/CustomerController.php +++ b/server/src/Http/Controllers/v1/CustomerController.php @@ -9,7 +9,6 @@ use Fleetbase\FleetOps\Models\Contact; use Fleetbase\FleetOps\Models\Order; use Fleetbase\FleetOps\Models\Place; -use Fleetbase\FleetOps\Support\Utils; use Fleetbase\Http\Controllers\Controller; use Fleetbase\Models\User; use Fleetbase\Models\UserDevice; @@ -18,6 +17,7 @@ use Fleetbase\Storefront\Http\Requests\VerifyCreateCustomerRequest; use Fleetbase\Storefront\Http\Resources\Customer; use Fleetbase\Storefront\Support\Storefront; +use Fleetbase\Support\Utils; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; @@ -136,13 +136,19 @@ public function requestCustomerCreationCode(VerifyCreateCustomerRequest $request $meta = ['identity' => $identity]; if ($isEmail) { - VerificationCode::generateEmailVerificationFor($customer, 'storefront_create_customer', function ($verification) use ($about) { - return "Your {$about->name} verification code is {$verification->code}"; - }, $meta); + VerificationCode::generateEmailVerificationFor($customer, 'storefront_create_customer', [ + 'messageCallback' => function ($verification) use ($about) { + return "Your {$about->name} verification code is {$verification->code}"; + }, + 'meta' => $meta, + ]); } else { - VerificationCode::generateSmsVerificationFor($customer, 'storefront_create_customer', function ($verification) use ($about) { - return "Your {$about->name} verification code is {$verification->code}"; - }, $meta); + VerificationCode::generateSmsVerificationFor($customer, 'storefront_create_customer', [ + 'messageCallback' => function ($verification) use ($about) { + return "Your {$about->name} verification code is {$verification->code}"; + }, + 'meta' => $meta, + ]); } return response()->json(['status' => 'ok']); @@ -382,9 +388,11 @@ public function loginWithPhone() $about = Storefront::about(); // generate verification token - VerificationCode::generateSmsVerificationFor($user, 'storefront_login', function ($verification) use ($about) { - return "Your {$about->name} verification code is {$verification->code}"; - }); + VerificationCode::generateSmsVerificationFor($user, 'storefront_login', [ + 'messageCallback' => function ($verification) use ($about) { + return "Your {$about->name} verification code is {$verification->code}"; + }, + ]); return response()->json(['status' => 'OK']); } @@ -454,7 +462,7 @@ public function verifyCode(Request $request) /** * Patches phone number with international code. */ - public static function phone(string $phone = null): string + public static function phone(?string $phone = null): string { if ($phone === null) { $phone = request()->input('phone'); diff --git a/server/src/Http/Controllers/v1/NetworkController.php b/server/src/Http/Controllers/v1/NetworkController.php index 9e6f05d..a153367 100644 --- a/server/src/Http/Controllers/v1/NetworkController.php +++ b/server/src/Http/Controllers/v1/NetworkController.php @@ -4,12 +4,12 @@ use Fleetbase\FleetOps\Support\Utils; use Fleetbase\Http\Controllers\Controller; +use Fleetbase\LaravelMysqlSpatial\Types\Point; use Fleetbase\Models\Category; use Fleetbase\Storefront\Http\Resources\Store as StorefrontStore; use Fleetbase\Storefront\Http\Resources\StoreLocation as StorefrontStoreLocation; use Fleetbase\Storefront\Models\Store; use Fleetbase\Storefront\Models\StoreLocation; -use Fleetbase\LaravelMysqlSpatial\Types\Point; use Illuminate\Http\Request; class NetworkController extends Controller diff --git a/server/src/Http/Controllers/v1/ProductController.php b/server/src/Http/Controllers/v1/ProductController.php index c9a8af6..e6b75b1 100644 --- a/server/src/Http/Controllers/v1/ProductController.php +++ b/server/src/Http/Controllers/v1/ProductController.php @@ -71,7 +71,7 @@ public function find($id) /** * Deletes a Storefront Product resources. * - * @return \Fleetbase\Http\Resources\v1\DeletedResource + * @return DeletedResource */ public function delete($id) { diff --git a/server/src/Http/Controllers/v1/ServiceQuoteController.php b/server/src/Http/Controllers/v1/ServiceQuoteController.php index 2b384f5..6fe6549 100644 --- a/server/src/Http/Controllers/v1/ServiceQuoteController.php +++ b/server/src/Http/Controllers/v1/ServiceQuoteController.php @@ -17,6 +17,7 @@ use Fleetbase\Storefront\Models\Product; use Fleetbase\Storefront\Models\Store; use Fleetbase\Storefront\Models\StoreLocation; +use Fleetbase\Support\Utils as CoreUtils; use Illuminate\Support\Str; class ServiceQuoteController extends Controller @@ -30,7 +31,7 @@ class ServiceQuoteController extends Controller */ public function fromCart(GetServiceQuoteFromCart $request) { - $requestId = ServiceQuote::generatePublicId('request'); + $requestId = CoreUtils::generatePublicId('request'); $origin = $this->getPlaceFromId($request->input('origin')); $destination = $this->getPlaceFromId($request->input('destination')); $facilitator = $request->input('facilitator'); @@ -302,7 +303,7 @@ public function fromCartForNetwork(GetServiceQuoteFromCart $request) if ($integratedVendor) { try { - /** @var \Fleetbase\FleetOps\Models\ServiceQuote $serviceQuote */ + /** @var ServiceQuote $serviceQuote */ $serviceQuote = $integratedVendor->api()->setRequestId($requestId)->getQuoteFromPreliminaryPayload([...$origins, $destination], [], $serviceType, $scheduledAt, $isRouteOptimized); } catch (\Exception $e) { return response()->error($e->getMessage()); diff --git a/server/src/Http/Requests/GetServiceQuoteFromCart.php b/server/src/Http/Requests/GetServiceQuoteFromCart.php index 8f33fcc..67791e3 100644 --- a/server/src/Http/Requests/GetServiceQuoteFromCart.php +++ b/server/src/Http/Requests/GetServiceQuoteFromCart.php @@ -3,7 +3,7 @@ namespace Fleetbase\Storefront\Http\Requests; use Fleetbase\Http\Requests\FleetbaseRequest; -use Fleetbase\Rules\IsValidLocation; +use Fleetbase\Storefront\Rules\IsValidLocation; use Illuminate\Support\Str; class GetServiceQuoteFromCart extends FleetbaseRequest diff --git a/server/src/Http/Requests/InitializeCheckoutRequest.php b/server/src/Http/Requests/InitializeCheckoutRequest.php index b4103f3..09a7a26 100644 --- a/server/src/Http/Requests/InitializeCheckoutRequest.php +++ b/server/src/Http/Requests/InitializeCheckoutRequest.php @@ -3,9 +3,8 @@ namespace Fleetbase\Storefront\Http\Requests; use Fleetbase\Http\Requests\FleetbaseRequest; -// use Fleetbase\Rules\Storefront\CartExists; -use Fleetbase\Rules\Storefront\CustomerExists; -use Fleetbase\Rules\Storefront\GatewayExists; +use Fleetbase\Storefront\Rules\CustomerExists; +use Fleetbase\Storefront\Rules\GatewayExists; class InitializeCheckoutRequest extends FleetbaseRequest { diff --git a/server/src/Http/Resources/Product.php b/server/src/Http/Resources/Product.php index 6b1cf9b..92f719a 100644 --- a/server/src/Http/Resources/Product.php +++ b/server/src/Http/Resources/Product.php @@ -55,7 +55,7 @@ public function toArray($request) ]; } - public function mapHours(\Illuminate\Database\Eloquent\Collection $hours = null): array + public function mapHours(?\Illuminate\Database\Eloquent\Collection $hours = null): array { if (empty($hours)) { return []; @@ -79,7 +79,7 @@ function ($hour) { ); } - public function mapFiles(\Illuminate\Database\Eloquent\Collection $files = null, $contentType = 'image') + public function mapFiles(?\Illuminate\Database\Eloquent\Collection $files = null, $contentType = 'image') { return collect($files)->map(function ($file) use ($contentType) { if (!Str::contains($file->content_type, $contentType)) { @@ -90,7 +90,7 @@ public function mapFiles(\Illuminate\Database\Eloquent\Collection $files = null, })->filter()->values(); } - public function mapAddonCategories(\Illuminate\Database\Eloquent\Collection $addonCategories = null) + public function mapAddonCategories(?\Illuminate\Database\Eloquent\Collection $addonCategories = null) { return collect($addonCategories)->map(function ($addonCategory) { $addons = data_get($addonCategory, 'category.addons', []); @@ -120,7 +120,7 @@ public function mapAddonCategories(\Illuminate\Database\Eloquent\Collection $add }); } - public function mapProductAddons(\Illuminate\Database\Eloquent\Collection $addons = null, $excluded = []) + public function mapProductAddons(?\Illuminate\Database\Eloquent\Collection $addons = null, $excluded = []) { return collect($addons)->map(function ($addon) use ($excluded) { if (is_array($excluded) && in_array($addon->uuid, $excluded)) { @@ -157,7 +157,7 @@ public function mapProductAddons(\Illuminate\Database\Eloquent\Collection $addon })->filter()->values(); } - public function mapVariants(\Illuminate\Database\Eloquent\Collection $variants = null) + public function mapVariants(?\Illuminate\Database\Eloquent\Collection $variants = null) { return collect($variants)->map(function ($variant) { $productVariantArr = [ diff --git a/server/src/Imports/ProductsImport.php b/server/src/Imports/ProductsImport.php index 570cf6b..d649834 100644 --- a/server/src/Imports/ProductsImport.php +++ b/server/src/Imports/ProductsImport.php @@ -9,7 +9,7 @@ class ProductsImport implements ToCollection, WithHeadingRow { /** - * @return \Illuminate\Support\Collection + * @return Collection */ public function collection(Collection $rows) { diff --git a/server/src/Listeners/HandleOrderDriverAssigned.php b/server/src/Listeners/HandleOrderDriverAssigned.php index 8040dde..225f697 100644 --- a/server/src/Listeners/HandleOrderDriverAssigned.php +++ b/server/src/Listeners/HandleOrderDriverAssigned.php @@ -21,7 +21,7 @@ class HandleOrderDriverAssigned implements ShouldQueue */ public function handle(OrderDriverAssigned $event) { - /** @var \Fleetbase\FleetOps\Models\Order $order */ + /** @var Order $order */ $order = $event->getModelRecord(); // halt if unable to resolve order record from event diff --git a/server/src/Models/Cart.php b/server/src/Models/Cart.php index 2044c55..3a2e7b5 100644 --- a/server/src/Models/Cart.php +++ b/server/src/Models/Cart.php @@ -587,7 +587,7 @@ public function createEvent(string $eventName, $cartItemId = null, $save = true) * * @return \Fleetbase\Models\Storefront\Cart */ - public function updateCurrency(string $currencyCode = null, $save = false) + public function updateCurrency(?string $currencyCode = null, $save = false) { $this->attributes['currency'] = $currencyCode ?? session('storefront_currency'); diff --git a/server/src/Models/Gateway.php b/server/src/Models/Gateway.php index 4a3c793..11cb818 100644 --- a/server/src/Models/Gateway.php +++ b/server/src/Models/Gateway.php @@ -149,7 +149,7 @@ public function getIsQpayGatewayAttribute() /** * Generates a new cash/cash on delivery gateway. */ - public static function cash($attributes = ['sandbox' => 0]): Gateway + public static function cash($attributes = ['sandbox' => false]): Gateway { return new static([ 'public_id' => 'gateway_cash', diff --git a/server/src/Models/Network.php b/server/src/Models/Network.php index ca74d05..dbb1b29 100644 --- a/server/src/Models/Network.php +++ b/server/src/Models/Network.php @@ -21,7 +21,7 @@ class Network extends StorefrontModel { use HasUuid; - use HasPublicId; + use HasPublicid; use HasApiModelBehavior; use HasOptionsAttributes; use HasSlug; @@ -83,7 +83,7 @@ class Network extends StorefrontModel protected $hidden = ['logo', 'backdrop', 'files', 'media']; /** - * @var \Spatie\Sluggable\SlugOptions + * @var SlugOptions */ public function getSlugOptions(): SlugOptions { @@ -220,7 +220,7 @@ public function getStoresCountAttribute() /** * Adds a new store to the network. */ - public function addStore(Store $store, Category $category = null): NetworkStore + public function addStore(Store $store, ?Category $category = null): NetworkStore { return NetworkStore::updateOrCreate( [ @@ -241,7 +241,7 @@ public function addStore(Store $store, Category $category = null): NetworkStore * @param File|string|null $icon * @param string $iconColor */ - public function createCategory(string $name, string $description = '', ?array $meta = [], ?array $translations = [], Category $parent = null, $icon = null, $iconColor = '#000000'): Category + public function createCategory(string $name, string $description = '', ?array $meta = [], ?array $translations = [], ?Category $parent = null, $icon = null, $iconColor = '#000000'): Category { $iconFile = null; $iconName = null; @@ -276,7 +276,7 @@ public function createCategory(string $name, string $description = '', ?array $m * @param File|string|null $icon * @param string $iconColor */ - public function createCategoryStrict(string $name, string $description = '', ?array $meta = [], ?array $translations = [], Category $parent = null, $icon = null, $iconColor = '#000000'): Category + public function createCategoryStrict(string $name, string $description = '', ?array $meta = [], ?array $translations = [], ?Category $parent = null, $icon = null, $iconColor = '#000000'): Category { $existingCategory = Category::where(['company_uuid' => $this->company_uuid, 'owner_uuid' => $this->uuid, 'name' => $name])->first(); diff --git a/server/src/Models/Product.php b/server/src/Models/Product.php index 97d3b8c..9421cc8 100644 --- a/server/src/Models/Product.php +++ b/server/src/Models/Product.php @@ -134,7 +134,7 @@ public static function boot() } /** - * @var \Spatie\Sluggable\SlugOptions + * @var SlugOptions */ public function getSlugOptions(): SlugOptions { diff --git a/server/src/Models/ProductAddon.php b/server/src/Models/ProductAddon.php index 403e0e9..20a07a7 100644 --- a/server/src/Models/ProductAddon.php +++ b/server/src/Models/ProductAddon.php @@ -76,7 +76,7 @@ class ProductAddon extends StorefrontModel protected $appends = []; /** - * @var \Spatie\Sluggable\SlugOptions + * @var SlugOptions */ public function getSlugOptions(): SlugOptions { diff --git a/server/src/Models/ProductStoreLocation.php b/server/src/Models/ProductStoreLocation.php index 5ac8be2..31e4a5f 100644 --- a/server/src/Models/ProductStoreLocation.php +++ b/server/src/Models/ProductStoreLocation.php @@ -52,7 +52,7 @@ class ProductStoreLocation extends StorefrontModel protected $appends = []; /** - * @var \Spatie\Sluggable\SlugOptions + * @var SlugOptions */ public function getSlugOptions(): SlugOptions { diff --git a/server/src/Models/ProductVariant.php b/server/src/Models/ProductVariant.php index ec4ede9..b867b2a 100644 --- a/server/src/Models/ProductVariant.php +++ b/server/src/Models/ProductVariant.php @@ -86,7 +86,7 @@ class ProductVariant extends StorefrontModel protected $with = []; /** - * @var \Spatie\Sluggable\SlugOptions + * @var SlugOptions */ public function getSlugOptions(): SlugOptions { diff --git a/server/src/Models/Store.php b/server/src/Models/Store.php index f9da8e5..0cacac1 100644 --- a/server/src/Models/Store.php +++ b/server/src/Models/Store.php @@ -95,7 +95,7 @@ class Store extends StorefrontModel protected $filterParams = ['network', 'without_category', 'category', 'category_uuid']; /** - * @var \Spatie\Sluggable\SlugOptions + * @var SlugOptions */ public function getSlugOptions(): SlugOptions { @@ -332,7 +332,7 @@ public function getNetworkCategoryUsingId(?string $id) /** * Retrieves the category of the store belonging to the specified network. * - * @param \Fleetbase\Storefront\Models\Network $network the network for which the category is to be retrieved + * @param Network $network the network for which the category is to be retrieved * * @return \Fleetbase\Models\Category|null the category of the store in the given network, or null if the store does not belong to the network */ @@ -360,7 +360,7 @@ public function getNetworkCategory(Network $network) * @param File|string|null $icon * @param string $iconColor */ - public function createCategory(string $name, string $description = '', ?array $meta = [], ?array $translations = [], Category $parent = null, $icon = null, $iconColor = '#000000'): Category + public function createCategory(string $name, string $description = '', ?array $meta = [], ?array $translations = [], ?Category $parent = null, $icon = null, $iconColor = '#000000'): Category { $iconFile = null; $iconName = null; @@ -397,7 +397,7 @@ public function createCategory(string $name, string $description = '', ?array $m * @param File|string|null $icon * @param string $iconColor */ - public function createCategoryStrict(string $name, string $description = '', ?array $meta = [], ?array $translations = [], Category $parent = null, $icon = null, $iconColor = '#000000'): Category + public function createCategoryStrict(string $name, string $description = '', ?array $meta = [], ?array $translations = [], ?Category $parent = null, $icon = null, $iconColor = '#000000'): Category { $existingCategory = Category::where(['company_uuid' => $this->company_uuid, 'owner_uuid' => $this->uuid, 'name' => $name])->first(); @@ -411,7 +411,7 @@ public function createCategoryStrict(string $name, string $description = '', ?ar /** * Creates a new product in the store. */ - public function createProduct(string $name, string $description, array $tags = [], Category $category = null, File $image = null, User $createdBy = null, string $sku = '', int $price = 0, string $status = 'available', array $options = []): Product + public function createProduct(string $name, string $description, array $tags = [], ?Category $category = null, ?File $image = null, ?User $createdBy = null, string $sku = '', int $price = 0, string $status = 'available', array $options = []): Product { return Product::create( [ @@ -438,7 +438,7 @@ public function createProduct(string $name, string $description, array $tags = [ ); } - public function createLocation($location, string $name = null, ?User $createdBy): ?StoreLocation + public function createLocation($location, ?string $name = null, ?User $createdBy): ?StoreLocation { $place = Place::createFromMixed($location); diff --git a/server/src/Models/StoreLocation.php b/server/src/Models/StoreLocation.php index d064bae..9f8bcfd 100644 --- a/server/src/Models/StoreLocation.php +++ b/server/src/Models/StoreLocation.php @@ -7,14 +7,12 @@ use Fleetbase\Traits\HasApiModelBehavior; use Fleetbase\Traits\HasPublicid; use Fleetbase\Traits\HasUuid; -use Fleetbase\LaravelMysqlSpatial\Eloquent\SpatialTrait; class StoreLocation extends StorefrontModel { use HasUuid; use HasPublicid; use HasApiModelBehavior; - use SpatialTrait; /** * The type of public Id to generate. diff --git a/server/src/Notifications/StorefrontOrderCanceled.php b/server/src/Notifications/StorefrontOrderCanceled.php index bb66b14..c8a7921 100644 --- a/server/src/Notifications/StorefrontOrderCanceled.php +++ b/server/src/Notifications/StorefrontOrderCanceled.php @@ -28,7 +28,7 @@ class StorefrontOrderCanceled extends Notification /** * The order instance this notification is for. * - * @var \Fleetbase\FleetOps\Models\Order + * @var Order */ public $order; @@ -63,7 +63,7 @@ public function via($notifiable) /** * Get the mail representation of the notification. * - * @return \Illuminate\Notifications\Messages\MailMessage + * @return MailMessage */ public function toMail($notifiable) { diff --git a/server/src/Notifications/StorefrontOrderCompleted.php b/server/src/Notifications/StorefrontOrderCompleted.php index a20649f..352f001 100644 --- a/server/src/Notifications/StorefrontOrderCompleted.php +++ b/server/src/Notifications/StorefrontOrderCompleted.php @@ -70,7 +70,7 @@ public function via($notifiable) /** * Get the mail representation of the notification. * - * @return \Illuminate\Notifications\Messages\MailMessage + * @return MailMessage */ public function toMail($notifiable) { diff --git a/server/src/Notifications/StorefrontOrderCreated.php b/server/src/Notifications/StorefrontOrderCreated.php index 6528f2b..a7e8d2f 100644 --- a/server/src/Notifications/StorefrontOrderCreated.php +++ b/server/src/Notifications/StorefrontOrderCreated.php @@ -92,7 +92,7 @@ public function toTwilio($notifiable) /** * Get the mail representation of the notification. * - * @return \Illuminate\Notifications\Messages\MailMessage + * @return MailMessage */ public function toMail($notifiable) { diff --git a/server/src/Notifications/StorefrontOrderDriverAssigned.php b/server/src/Notifications/StorefrontOrderDriverAssigned.php index a245180..4a8a98b 100644 --- a/server/src/Notifications/StorefrontOrderDriverAssigned.php +++ b/server/src/Notifications/StorefrontOrderDriverAssigned.php @@ -69,7 +69,7 @@ public function via($notifiable) /** * Get the mail representation of the notification. * - * @return \Illuminate\Notifications\Messages\MailMessage + * @return MailMessage */ public function toMail($notifiable) { diff --git a/server/src/Notifications/StorefrontOrderEnroute.php b/server/src/Notifications/StorefrontOrderEnroute.php index 436bccc..a7f0d53 100644 --- a/server/src/Notifications/StorefrontOrderEnroute.php +++ b/server/src/Notifications/StorefrontOrderEnroute.php @@ -68,7 +68,7 @@ public function via($notifiable) /** * Get the mail representation of the notification. * - * @return \Illuminate\Notifications\Messages\MailMessage + * @return MailMessage */ public function toMail($notifiable) { diff --git a/server/src/Notifications/StorefrontOrderNearby.php b/server/src/Notifications/StorefrontOrderNearby.php index 49cd703..9247045 100644 --- a/server/src/Notifications/StorefrontOrderNearby.php +++ b/server/src/Notifications/StorefrontOrderNearby.php @@ -70,7 +70,7 @@ public function via($notifiable) /** * Get the mail representation of the notification. * - * @return \Illuminate\Notifications\Messages\MailMessage + * @return MailMessage */ public function toMail($notifiable) { diff --git a/server/src/Notifications/StorefrontOrderPreparing.php b/server/src/Notifications/StorefrontOrderPreparing.php index 0f019c1..6f76702 100644 --- a/server/src/Notifications/StorefrontOrderPreparing.php +++ b/server/src/Notifications/StorefrontOrderPreparing.php @@ -69,7 +69,7 @@ public function via($notifiable) /** * Get the mail representation of the notification. * - * @return \Illuminate\Notifications\Messages\MailMessage + * @return MailMessage */ public function toMail($notifiable) { diff --git a/server/src/Notifications/StorefrontOrderReadyForPickup.php b/server/src/Notifications/StorefrontOrderReadyForPickup.php index a825464..31c52ea 100644 --- a/server/src/Notifications/StorefrontOrderReadyForPickup.php +++ b/server/src/Notifications/StorefrontOrderReadyForPickup.php @@ -69,7 +69,7 @@ public function via($notifiable) /** * Get the mail representation of the notification. * - * @return \Illuminate\Notifications\Messages\MailMessage + * @return MailMessage */ public function toMail($notifiable) { diff --git a/server/src/Observers/NetworkObserver.php b/server/src/Observers/NetworkObserver.php index 61a5a17..11c1d0b 100644 --- a/server/src/Observers/NetworkObserver.php +++ b/server/src/Observers/NetworkObserver.php @@ -10,7 +10,7 @@ class NetworkObserver /** * Handle the Network "updated" event. * - * @param \Fleetbase\Storefront\Models\Network $network the Network that is updating + * @param Network $network the Network that is updating */ public function updating(Network $network): void { diff --git a/server/src/Observers/ProductObserver.php b/server/src/Observers/ProductObserver.php index f6f45aa..640dcef 100644 --- a/server/src/Observers/ProductObserver.php +++ b/server/src/Observers/ProductObserver.php @@ -17,7 +17,7 @@ class ProductObserver /** * Handle the Product "created" event. * - * @param \Fleetbase\Storefront\Models\Product $product the Product that was created + * @param Product $product the Product that was created */ public function created(Product $product): void { @@ -41,7 +41,7 @@ public function created(Product $product): void /** * Handle the Product "updated" event. * - * @param \Fleetbase\Storefront\Models\Product $product the Product that was created + * @param Product $product the Product that was created */ public function updated(Product $product): void { diff --git a/server/src/Rules/CartExists.php b/server/src/Rules/CartExists.php new file mode 100644 index 0000000..7199208 --- /dev/null +++ b/server/src/Rules/CartExists.php @@ -0,0 +1,31 @@ + $attribute, 'unique_identifier' => $attribute])->exists(); + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'Cart session does not exists.'; + } +} diff --git a/server/src/Rules/CustomerExists.php b/server/src/Rules/CustomerExists.php new file mode 100644 index 0000000..0a85e29 --- /dev/null +++ b/server/src/Rules/CustomerExists.php @@ -0,0 +1,34 @@ +exists(); + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'No customer found.'; + } +} diff --git a/server/src/Rules/GatewayExists.php b/server/src/Rules/GatewayExists.php new file mode 100644 index 0000000..01bf71b --- /dev/null +++ b/server/src/Rules/GatewayExists.php @@ -0,0 +1,35 @@ + $value])->exists(); + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'No gateway by code provided exists.'; + } +} diff --git a/server/src/Rules/IsValidLocation.php b/server/src/Rules/IsValidLocation.php new file mode 100644 index 0000000..49aee9f --- /dev/null +++ b/server/src/Rules/IsValidLocation.php @@ -0,0 +1,54 @@ +exists(); + } + + // Validate StoreLocation id + if (Str::startsWith($value, 'store_location_')) { + return StoreLocation::where('public_id', $value)->exists(); + } + + // Validate object with coordinates + if (isset($value->coordinates)) { + return Utils::isCoordinates($value->coordinates); + } + + // Validate coordinates + if (Utils::isCoordinates($value)) { + return true; + } + + return false; + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return 'Invalid :attribute.'; + } +} diff --git a/server/src/Support/Metrics.php b/server/src/Support/Metrics.php index c55715e..ae970ac 100644 --- a/server/src/Support/Metrics.php +++ b/server/src/Support/Metrics.php @@ -23,7 +23,7 @@ class Metrics protected Company $company; protected array $metrics = []; - public static function new(Company $company, \DateTime $start = null, \DateTime $end = null): Metrics + public static function new(Company $company, ?\DateTime $start = null, ?\DateTime $end = null): Metrics { $start = $start === null ? Carbon::create(1900)->toDateTime() : $start; $end = $end === null ? Carbon::tomorrow()->toDateTime() : $end; @@ -31,7 +31,7 @@ public static function new(Company $company, \DateTime $start = null, \DateTime return (new static())->setCompany($company)->between($start, $end); } - public static function forCompany(Company $company, \DateTime $start = null, \DateTime $end = null): Metrics + public static function forCompany(Company $company, ?\DateTime $start = null, ?\DateTime $end = null): Metrics { return static::new($company, $start, $end); } @@ -104,7 +104,7 @@ function ($metric) { return $this; } - public function totalProducts(callable $callback = null): Metrics + public function totalProducts(?callable $callback = null): Metrics { $query = Product::where('company_uuid', $this->company->uuid); @@ -117,7 +117,7 @@ public function totalProducts(callable $callback = null): Metrics return $this->set('total_products', $data); } - public function totalStores(callable $callback = null): Metrics + public function totalStores(?callable $callback = null): Metrics { $query = Store::where('company_uuid', $this->company->uuid); @@ -130,7 +130,7 @@ public function totalStores(callable $callback = null): Metrics return $this->set('total_stores', $data); } - public function totalNetworks(callable $callback = null): Metrics + public function totalNetworks(?callable $callback = null): Metrics { $query = Network::where('company_uuid', $this->company->uuid); @@ -143,7 +143,7 @@ public function totalNetworks(callable $callback = null): Metrics return $this->set('total_networks', $data); } - public function ordersInProgress(callable $callback = null): Metrics + public function ordersInProgress(?callable $callback = null): Metrics { $query = Order::where('company_uuid', $this->company->uuid) ->whereBetween('created_at', [$this->start, $this->end]) @@ -159,7 +159,7 @@ public function ordersInProgress(callable $callback = null): Metrics return $this->set('orders_in_progress', $data); } - public function ordersCompleted(callable $callback = null): Metrics + public function ordersCompleted(?callable $callback = null): Metrics { $query = Order::where('company_uuid', $this->company->uuid) ->whereBetween('created_at', [$this->start, $this->end]) @@ -175,7 +175,7 @@ public function ordersCompleted(callable $callback = null): Metrics return $this->set('orders_completed', $data); } - public function ordersCanceled(callable $callback = null): Metrics + public function ordersCanceled(?callable $callback = null): Metrics { $query = Order::where('company_uuid', $this->company->uuid) ->whereBetween('created_at', [$this->start, $this->end]) diff --git a/server/src/Support/QPay.php b/server/src/Support/QPay.php index 57c49e7..e6e5db5 100644 --- a/server/src/Support/QPay.php +++ b/server/src/Support/QPay.php @@ -12,7 +12,7 @@ class QPay private array $requestOptions = []; private Client $client; - public function __construct(string $username = null, string $password = null, string $callbackUrl = null) + public function __construct(?string $username = null, ?string $password = null, ?string $callbackUrl = null) { $this->callbackUrl = $callbackUrl; $this->requestOptions = [ @@ -60,7 +60,7 @@ public function useSandbox() return $this; } - public static function instance(string $username = null, string $password = null, string $callbackUrl = null): QPay + public static function instance(?string $username = null, ?string $password = null, ?string $callbackUrl = null): QPay { return new static($username, $password, $callbackUrl); } @@ -120,7 +120,7 @@ private function useBearerToken(string $token): QPay return $this; } - public function setAuthToken(string $accessToken = null): QPay + public function setAuthToken(?string $accessToken = null): QPay { if ($accessToken) { $this->useBearerToken($accessToken); @@ -136,7 +136,7 @@ public function setAuthToken(string $accessToken = null): QPay return $this; } - public function createSimpleInvoice(int $amount, ?string $invoiceCode = '', ?string $invoiceDescription = '', ?string $invoiceReceiverCode = '', ?string $senderInvoiceNo = '', string $callbackUrl = null) + public function createSimpleInvoice(int $amount, ?string $invoiceCode = '', ?string $invoiceDescription = '', ?string $invoiceReceiverCode = '', ?string $senderInvoiceNo = '', ?string $callbackUrl = null) { if (!$callbackUrl && $this->hasCallbackUrl()) { $callbackUrl = $this->callbackUrl; diff --git a/server/src/Support/Storefront.php b/server/src/Support/Storefront.php index b709d51..406b1e3 100644 --- a/server/src/Support/Storefront.php +++ b/server/src/Support/Storefront.php @@ -10,6 +10,7 @@ use Fleetbase\Storefront\Models\Product; use Fleetbase\Storefront\Models\Store; use Fleetbase\Storefront\Notifications\StorefrontOrderCreated; +use Fleetbase\Support\Utils; use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Redis; use Illuminate\Support\Str; @@ -92,7 +93,7 @@ public static function getCustomerFromToken() if ($token) { $accessToken = PersonalAccessToken::findToken($token); - if ($accessToken && Utils::isUuid($accessToken->name)) { + if ($accessToken && Str::isUuid($accessToken->name)) { $customer = Contact::where('uuid', $accessToken->name)->first(); if ($customer) {