@fleetbase/storefront-engine 0.2.11 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/composer.json +3 -3
  2. package/extension.json +1 -1
  3. package/package.json +1 -1
  4. package/server/src/Http/Controllers/MetricsController.php +1 -2
  5. package/server/src/Http/Controllers/v1/CartController.php +1 -1
  6. package/server/src/Http/Controllers/v1/CustomerController.php +19 -11
  7. package/server/src/Http/Controllers/v1/NetworkController.php +1 -1
  8. package/server/src/Http/Controllers/v1/ProductController.php +1 -1
  9. package/server/src/Http/Controllers/v1/ServiceQuoteController.php +3 -2
  10. package/server/src/Http/Requests/GetServiceQuoteFromCart.php +1 -1
  11. package/server/src/Http/Requests/InitializeCheckoutRequest.php +2 -3
  12. package/server/src/Http/Resources/Product.php +5 -5
  13. package/server/src/Imports/ProductsImport.php +1 -1
  14. package/server/src/Listeners/HandleOrderDriverAssigned.php +1 -1
  15. package/server/src/Models/Cart.php +1 -1
  16. package/server/src/Models/Gateway.php +1 -1
  17. package/server/src/Models/Network.php +5 -5
  18. package/server/src/Models/Product.php +1 -1
  19. package/server/src/Models/ProductAddon.php +1 -1
  20. package/server/src/Models/ProductStoreLocation.php +1 -1
  21. package/server/src/Models/ProductVariant.php +1 -1
  22. package/server/src/Models/Store.php +6 -6
  23. package/server/src/Models/StoreLocation.php +0 -2
  24. package/server/src/Notifications/StorefrontOrderCanceled.php +2 -2
  25. package/server/src/Notifications/StorefrontOrderCompleted.php +1 -1
  26. package/server/src/Notifications/StorefrontOrderCreated.php +1 -1
  27. package/server/src/Notifications/StorefrontOrderDriverAssigned.php +1 -1
  28. package/server/src/Notifications/StorefrontOrderEnroute.php +1 -1
  29. package/server/src/Notifications/StorefrontOrderNearby.php +1 -1
  30. package/server/src/Notifications/StorefrontOrderPreparing.php +1 -1
  31. package/server/src/Notifications/StorefrontOrderReadyForPickup.php +1 -1
  32. package/server/src/Observers/NetworkObserver.php +1 -1
  33. package/server/src/Observers/ProductObserver.php +2 -2
  34. package/server/src/Rules/CartExists.php +31 -0
  35. package/server/src/Rules/CustomerExists.php +34 -0
  36. package/server/src/Rules/GatewayExists.php +35 -0
  37. package/server/src/Rules/IsValidLocation.php +54 -0
  38. package/server/src/Support/Metrics.php +8 -8
  39. package/server/src/Support/QPay.php +4 -4
  40. package/server/src/Support/Storefront.php +2 -1
package/composer.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetbase/storefront-api",
3
- "version": "0.2.11",
3
+ "version": "0.3.0",
4
4
  "description": "Headless Commerce & Marketplace Extension for Fleetbase",
5
5
  "keywords": [
6
6
  "fleetbase-extension",
@@ -22,8 +22,8 @@
22
22
  ],
23
23
  "require": {
24
24
  "php": "^8.0",
25
- "fleetbase/core-api": "^1.4.0",
26
- "fleetbase/fleetops-api": "^0.4.6",
25
+ "fleetbase/core-api": "^1.4.3",
26
+ "fleetbase/fleetops-api": "^0.4.9",
27
27
  "geocoder-php/google-maps-places-provider": "^1.4",
28
28
  "laravel-notification-channels/apn": "^5.0",
29
29
  "laravel-notification-channels/fcm": "^4.1",
package/extension.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "Storefront",
3
- "version": "0.2.11",
3
+ "version": "0.3.0",
4
4
  "description": "Headless Commerce & Marketplace Extension for Fleetbase",
5
5
  "repository": "https://github.com/fleetbase/storefront",
6
6
  "license": "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fleetbase/storefront-engine",
3
- "version": "0.2.11",
3
+ "version": "0.3.0",
4
4
  "description": "Headless Commerce & Marketplace Extension for Fleetbase",
5
5
  "fleetbase": {
6
6
  "route": "storefront",
@@ -9,9 +9,8 @@ use Illuminate\Http\Request;
9
9
  class MetricsController extends Controller
10
10
  {
11
11
  /**
12
- * Get all key metrics for a companies storefront
12
+ * Get all key metrics for a companies storefront.
13
13
  *
14
- * @param \Illuminate\Http\Request $request
15
14
  * @return \Illuminate\Http\Response
16
15
  */
17
16
  public function all(Request $request)
@@ -15,7 +15,7 @@ class CartController extends Controller
15
15
  *
16
16
  * @return \Illuminate\Http\Response
17
17
  */
18
- public function retrieve(string $uniqueId = null, Request $request)
18
+ public function retrieve(?string $uniqueId = null, Request $request)
19
19
  {
20
20
  $cart = Cart::retrieve($uniqueId, true);
21
21
 
@@ -9,7 +9,6 @@ use Fleetbase\FleetOps\Http\Resources\v1\Place as PlaceResource;
9
9
  use Fleetbase\FleetOps\Models\Contact;
10
10
  use Fleetbase\FleetOps\Models\Order;
11
11
  use Fleetbase\FleetOps\Models\Place;
12
- use Fleetbase\FleetOps\Support\Utils;
13
12
  use Fleetbase\Http\Controllers\Controller;
14
13
  use Fleetbase\Models\User;
15
14
  use Fleetbase\Models\UserDevice;
@@ -18,6 +17,7 @@ use Fleetbase\Storefront\Http\Requests\CreateCustomerRequest;
18
17
  use Fleetbase\Storefront\Http\Requests\VerifyCreateCustomerRequest;
19
18
  use Fleetbase\Storefront\Http\Resources\Customer;
20
19
  use Fleetbase\Storefront\Support\Storefront;
20
+ use Fleetbase\Support\Utils;
21
21
  use Illuminate\Database\Eloquent\ModelNotFoundException;
22
22
  use Illuminate\Http\Request;
23
23
  use Illuminate\Support\Facades\Hash;
@@ -136,13 +136,19 @@ class CustomerController extends Controller
136
136
  $meta = ['identity' => $identity];
137
137
 
138
138
  if ($isEmail) {
139
- VerificationCode::generateEmailVerificationFor($customer, 'storefront_create_customer', function ($verification) use ($about) {
140
- return "Your {$about->name} verification code is {$verification->code}";
141
- }, $meta);
139
+ VerificationCode::generateEmailVerificationFor($customer, 'storefront_create_customer', [
140
+ 'messageCallback' => function ($verification) use ($about) {
141
+ return "Your {$about->name} verification code is {$verification->code}";
142
+ },
143
+ 'meta' => $meta,
144
+ ]);
142
145
  } else {
143
- VerificationCode::generateSmsVerificationFor($customer, 'storefront_create_customer', function ($verification) use ($about) {
144
- return "Your {$about->name} verification code is {$verification->code}";
145
- }, $meta);
146
+ VerificationCode::generateSmsVerificationFor($customer, 'storefront_create_customer', [
147
+ 'messageCallback' => function ($verification) use ($about) {
148
+ return "Your {$about->name} verification code is {$verification->code}";
149
+ },
150
+ 'meta' => $meta,
151
+ ]);
146
152
  }
147
153
 
148
154
  return response()->json(['status' => 'ok']);
@@ -382,9 +388,11 @@ class CustomerController extends Controller
382
388
  $about = Storefront::about();
383
389
 
384
390
  // generate verification token
385
- VerificationCode::generateSmsVerificationFor($user, 'storefront_login', function ($verification) use ($about) {
386
- return "Your {$about->name} verification code is {$verification->code}";
387
- });
391
+ VerificationCode::generateSmsVerificationFor($user, 'storefront_login', [
392
+ 'messageCallback' => function ($verification) use ($about) {
393
+ return "Your {$about->name} verification code is {$verification->code}";
394
+ },
395
+ ]);
388
396
 
389
397
  return response()->json(['status' => 'OK']);
390
398
  }
@@ -454,7 +462,7 @@ class CustomerController extends Controller
454
462
  /**
455
463
  * Patches phone number with international code.
456
464
  */
457
- public static function phone(string $phone = null): string
465
+ public static function phone(?string $phone = null): string
458
466
  {
459
467
  if ($phone === null) {
460
468
  $phone = request()->input('phone');
@@ -4,12 +4,12 @@ namespace Fleetbase\Storefront\Http\Controllers\v1;
4
4
 
5
5
  use Fleetbase\FleetOps\Support\Utils;
6
6
  use Fleetbase\Http\Controllers\Controller;
7
+ use Fleetbase\LaravelMysqlSpatial\Types\Point;
7
8
  use Fleetbase\Models\Category;
8
9
  use Fleetbase\Storefront\Http\Resources\Store as StorefrontStore;
9
10
  use Fleetbase\Storefront\Http\Resources\StoreLocation as StorefrontStoreLocation;
10
11
  use Fleetbase\Storefront\Models\Store;
11
12
  use Fleetbase\Storefront\Models\StoreLocation;
12
- use Fleetbase\LaravelMysqlSpatial\Types\Point;
13
13
  use Illuminate\Http\Request;
14
14
 
15
15
  class NetworkController extends Controller
@@ -71,7 +71,7 @@ class ProductController extends Controller
71
71
  /**
72
72
  * Deletes a Storefront Product resources.
73
73
  *
74
- * @return \Fleetbase\Http\Resources\v1\DeletedResource
74
+ * @return DeletedResource
75
75
  */
76
76
  public function delete($id)
77
77
  {
@@ -17,6 +17,7 @@ use Fleetbase\Storefront\Models\Cart;
17
17
  use Fleetbase\Storefront\Models\Product;
18
18
  use Fleetbase\Storefront\Models\Store;
19
19
  use Fleetbase\Storefront\Models\StoreLocation;
20
+ use Fleetbase\Support\Utils as CoreUtils;
20
21
  use Illuminate\Support\Str;
21
22
 
22
23
  class ServiceQuoteController extends Controller
@@ -30,7 +31,7 @@ class ServiceQuoteController extends Controller
30
31
  */
31
32
  public function fromCart(GetServiceQuoteFromCart $request)
32
33
  {
33
- $requestId = ServiceQuote::generatePublicId('request');
34
+ $requestId = CoreUtils::generatePublicId('request');
34
35
  $origin = $this->getPlaceFromId($request->input('origin'));
35
36
  $destination = $this->getPlaceFromId($request->input('destination'));
36
37
  $facilitator = $request->input('facilitator');
@@ -302,7 +303,7 @@ class ServiceQuoteController extends Controller
302
303
 
303
304
  if ($integratedVendor) {
304
305
  try {
305
- /** @var \Fleetbase\FleetOps\Models\ServiceQuote $serviceQuote */
306
+ /** @var ServiceQuote $serviceQuote */
306
307
  $serviceQuote = $integratedVendor->api()->setRequestId($requestId)->getQuoteFromPreliminaryPayload([...$origins, $destination], [], $serviceType, $scheduledAt, $isRouteOptimized);
307
308
  } catch (\Exception $e) {
308
309
  return response()->error($e->getMessage());
@@ -3,7 +3,7 @@
3
3
  namespace Fleetbase\Storefront\Http\Requests;
4
4
 
5
5
  use Fleetbase\Http\Requests\FleetbaseRequest;
6
- use Fleetbase\Rules\IsValidLocation;
6
+ use Fleetbase\Storefront\Rules\IsValidLocation;
7
7
  use Illuminate\Support\Str;
8
8
 
9
9
  class GetServiceQuoteFromCart extends FleetbaseRequest
@@ -3,9 +3,8 @@
3
3
  namespace Fleetbase\Storefront\Http\Requests;
4
4
 
5
5
  use Fleetbase\Http\Requests\FleetbaseRequest;
6
- // use Fleetbase\Rules\Storefront\CartExists;
7
- use Fleetbase\Rules\Storefront\CustomerExists;
8
- use Fleetbase\Rules\Storefront\GatewayExists;
6
+ use Fleetbase\Storefront\Rules\CustomerExists;
7
+ use Fleetbase\Storefront\Rules\GatewayExists;
9
8
 
10
9
  class InitializeCheckoutRequest extends FleetbaseRequest
11
10
  {
@@ -55,7 +55,7 @@ class Product extends FleetbaseResource
55
55
  ];
56
56
  }
57
57
 
58
- public function mapHours(\Illuminate\Database\Eloquent\Collection $hours = null): array
58
+ public function mapHours(?\Illuminate\Database\Eloquent\Collection $hours = null): array
59
59
  {
60
60
  if (empty($hours)) {
61
61
  return [];
@@ -79,7 +79,7 @@ class Product extends FleetbaseResource
79
79
  );
80
80
  }
81
81
 
82
- public function mapFiles(\Illuminate\Database\Eloquent\Collection $files = null, $contentType = 'image')
82
+ public function mapFiles(?\Illuminate\Database\Eloquent\Collection $files = null, $contentType = 'image')
83
83
  {
84
84
  return collect($files)->map(function ($file) use ($contentType) {
85
85
  if (!Str::contains($file->content_type, $contentType)) {
@@ -90,7 +90,7 @@ class Product extends FleetbaseResource
90
90
  })->filter()->values();
91
91
  }
92
92
 
93
- public function mapAddonCategories(\Illuminate\Database\Eloquent\Collection $addonCategories = null)
93
+ public function mapAddonCategories(?\Illuminate\Database\Eloquent\Collection $addonCategories = null)
94
94
  {
95
95
  return collect($addonCategories)->map(function ($addonCategory) {
96
96
  $addons = data_get($addonCategory, 'category.addons', []);
@@ -120,7 +120,7 @@ class Product extends FleetbaseResource
120
120
  });
121
121
  }
122
122
 
123
- public function mapProductAddons(\Illuminate\Database\Eloquent\Collection $addons = null, $excluded = [])
123
+ public function mapProductAddons(?\Illuminate\Database\Eloquent\Collection $addons = null, $excluded = [])
124
124
  {
125
125
  return collect($addons)->map(function ($addon) use ($excluded) {
126
126
  if (is_array($excluded) && in_array($addon->uuid, $excluded)) {
@@ -157,7 +157,7 @@ class Product extends FleetbaseResource
157
157
  })->filter()->values();
158
158
  }
159
159
 
160
- public function mapVariants(\Illuminate\Database\Eloquent\Collection $variants = null)
160
+ public function mapVariants(?\Illuminate\Database\Eloquent\Collection $variants = null)
161
161
  {
162
162
  return collect($variants)->map(function ($variant) {
163
163
  $productVariantArr = [
@@ -9,7 +9,7 @@ use Maatwebsite\Excel\Concerns\WithHeadingRow;
9
9
  class ProductsImport implements ToCollection, WithHeadingRow
10
10
  {
11
11
  /**
12
- * @return \Illuminate\Support\Collection
12
+ * @return Collection
13
13
  */
14
14
  public function collection(Collection $rows)
15
15
  {
@@ -21,7 +21,7 @@ class HandleOrderDriverAssigned implements ShouldQueue
21
21
  */
22
22
  public function handle(OrderDriverAssigned $event)
23
23
  {
24
- /** @var \Fleetbase\FleetOps\Models\Order $order */
24
+ /** @var Order $order */
25
25
  $order = $event->getModelRecord();
26
26
 
27
27
  // halt if unable to resolve order record from event
@@ -587,7 +587,7 @@ class Cart extends StorefrontModel
587
587
  *
588
588
  * @return \Fleetbase\Models\Storefront\Cart
589
589
  */
590
- public function updateCurrency(string $currencyCode = null, $save = false)
590
+ public function updateCurrency(?string $currencyCode = null, $save = false)
591
591
  {
592
592
  $this->attributes['currency'] = $currencyCode ?? session('storefront_currency');
593
593
 
@@ -149,7 +149,7 @@ class Gateway extends StorefrontModel
149
149
  /**
150
150
  * Generates a new cash/cash on delivery gateway.
151
151
  */
152
- public static function cash($attributes = ['sandbox' => 0]): Gateway
152
+ public static function cash($attributes = ['sandbox' => false]): Gateway
153
153
  {
154
154
  return new static([
155
155
  'public_id' => 'gateway_cash',
@@ -21,7 +21,7 @@ use Spatie\Sluggable\SlugOptions;
21
21
  class Network extends StorefrontModel
22
22
  {
23
23
  use HasUuid;
24
- use HasPublicId;
24
+ use HasPublicid;
25
25
  use HasApiModelBehavior;
26
26
  use HasOptionsAttributes;
27
27
  use HasSlug;
@@ -83,7 +83,7 @@ class Network extends StorefrontModel
83
83
  protected $hidden = ['logo', 'backdrop', 'files', 'media'];
84
84
 
85
85
  /**
86
- * @var \Spatie\Sluggable\SlugOptions
86
+ * @var SlugOptions
87
87
  */
88
88
  public function getSlugOptions(): SlugOptions
89
89
  {
@@ -220,7 +220,7 @@ class Network extends StorefrontModel
220
220
  /**
221
221
  * Adds a new store to the network.
222
222
  */
223
- public function addStore(Store $store, Category $category = null): NetworkStore
223
+ public function addStore(Store $store, ?Category $category = null): NetworkStore
224
224
  {
225
225
  return NetworkStore::updateOrCreate(
226
226
  [
@@ -241,7 +241,7 @@ class Network extends StorefrontModel
241
241
  * @param File|string|null $icon
242
242
  * @param string $iconColor
243
243
  */
244
- public function createCategory(string $name, string $description = '', ?array $meta = [], ?array $translations = [], Category $parent = null, $icon = null, $iconColor = '#000000'): Category
244
+ public function createCategory(string $name, string $description = '', ?array $meta = [], ?array $translations = [], ?Category $parent = null, $icon = null, $iconColor = '#000000'): Category
245
245
  {
246
246
  $iconFile = null;
247
247
  $iconName = null;
@@ -276,7 +276,7 @@ class Network extends StorefrontModel
276
276
  * @param File|string|null $icon
277
277
  * @param string $iconColor
278
278
  */
279
- public function createCategoryStrict(string $name, string $description = '', ?array $meta = [], ?array $translations = [], Category $parent = null, $icon = null, $iconColor = '#000000'): Category
279
+ public function createCategoryStrict(string $name, string $description = '', ?array $meta = [], ?array $translations = [], ?Category $parent = null, $icon = null, $iconColor = '#000000'): Category
280
280
  {
281
281
  $existingCategory = Category::where(['company_uuid' => $this->company_uuid, 'owner_uuid' => $this->uuid, 'name' => $name])->first();
282
282
 
@@ -134,7 +134,7 @@ class Product extends StorefrontModel
134
134
  }
135
135
 
136
136
  /**
137
- * @var \Spatie\Sluggable\SlugOptions
137
+ * @var SlugOptions
138
138
  */
139
139
  public function getSlugOptions(): SlugOptions
140
140
  {
@@ -76,7 +76,7 @@ class ProductAddon extends StorefrontModel
76
76
  protected $appends = [];
77
77
 
78
78
  /**
79
- * @var \Spatie\Sluggable\SlugOptions
79
+ * @var SlugOptions
80
80
  */
81
81
  public function getSlugOptions(): SlugOptions
82
82
  {
@@ -52,7 +52,7 @@ class ProductStoreLocation extends StorefrontModel
52
52
  protected $appends = [];
53
53
 
54
54
  /**
55
- * @var \Spatie\Sluggable\SlugOptions
55
+ * @var SlugOptions
56
56
  */
57
57
  public function getSlugOptions(): SlugOptions
58
58
  {
@@ -86,7 +86,7 @@ class ProductVariant extends StorefrontModel
86
86
  protected $with = [];
87
87
 
88
88
  /**
89
- * @var \Spatie\Sluggable\SlugOptions
89
+ * @var SlugOptions
90
90
  */
91
91
  public function getSlugOptions(): SlugOptions
92
92
  {
@@ -95,7 +95,7 @@ class Store extends StorefrontModel
95
95
  protected $filterParams = ['network', 'without_category', 'category', 'category_uuid'];
96
96
 
97
97
  /**
98
- * @var \Spatie\Sluggable\SlugOptions
98
+ * @var SlugOptions
99
99
  */
100
100
  public function getSlugOptions(): SlugOptions
101
101
  {
@@ -332,7 +332,7 @@ class Store extends StorefrontModel
332
332
  /**
333
333
  * Retrieves the category of the store belonging to the specified network.
334
334
  *
335
- * @param \Fleetbase\Storefront\Models\Network $network the network for which the category is to be retrieved
335
+ * @param Network $network the network for which the category is to be retrieved
336
336
  *
337
337
  * @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
338
338
  */
@@ -360,7 +360,7 @@ class Store extends StorefrontModel
360
360
  * @param File|string|null $icon
361
361
  * @param string $iconColor
362
362
  */
363
- public function createCategory(string $name, string $description = '', ?array $meta = [], ?array $translations = [], Category $parent = null, $icon = null, $iconColor = '#000000'): Category
363
+ public function createCategory(string $name, string $description = '', ?array $meta = [], ?array $translations = [], ?Category $parent = null, $icon = null, $iconColor = '#000000'): Category
364
364
  {
365
365
  $iconFile = null;
366
366
  $iconName = null;
@@ -397,7 +397,7 @@ class Store extends StorefrontModel
397
397
  * @param File|string|null $icon
398
398
  * @param string $iconColor
399
399
  */
400
- public function createCategoryStrict(string $name, string $description = '', ?array $meta = [], ?array $translations = [], Category $parent = null, $icon = null, $iconColor = '#000000'): Category
400
+ public function createCategoryStrict(string $name, string $description = '', ?array $meta = [], ?array $translations = [], ?Category $parent = null, $icon = null, $iconColor = '#000000'): Category
401
401
  {
402
402
  $existingCategory = Category::where(['company_uuid' => $this->company_uuid, 'owner_uuid' => $this->uuid, 'name' => $name])->first();
403
403
 
@@ -411,7 +411,7 @@ class Store extends StorefrontModel
411
411
  /**
412
412
  * Creates a new product in the store.
413
413
  */
414
- 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
414
+ 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
415
415
  {
416
416
  return Product::create(
417
417
  [
@@ -438,7 +438,7 @@ class Store extends StorefrontModel
438
438
  );
439
439
  }
440
440
 
441
- public function createLocation($location, string $name = null, ?User $createdBy): ?StoreLocation
441
+ public function createLocation($location, ?string $name = null, ?User $createdBy): ?StoreLocation
442
442
  {
443
443
  $place = Place::createFromMixed($location);
444
444
 
@@ -7,14 +7,12 @@ use Fleetbase\Models\User;
7
7
  use Fleetbase\Traits\HasApiModelBehavior;
8
8
  use Fleetbase\Traits\HasPublicid;
9
9
  use Fleetbase\Traits\HasUuid;
10
- use Fleetbase\LaravelMysqlSpatial\Eloquent\SpatialTrait;
11
10
 
12
11
  class StoreLocation extends StorefrontModel
13
12
  {
14
13
  use HasUuid;
15
14
  use HasPublicid;
16
15
  use HasApiModelBehavior;
17
- use SpatialTrait;
18
16
 
19
17
  /**
20
18
  * The type of public Id to generate.
@@ -28,7 +28,7 @@ class StorefrontOrderCanceled extends Notification
28
28
  /**
29
29
  * The order instance this notification is for.
30
30
  *
31
- * @var \Fleetbase\FleetOps\Models\Order
31
+ * @var Order
32
32
  */
33
33
  public $order;
34
34
 
@@ -63,7 +63,7 @@ class StorefrontOrderCanceled extends Notification
63
63
  /**
64
64
  * Get the mail representation of the notification.
65
65
  *
66
- * @return \Illuminate\Notifications\Messages\MailMessage
66
+ * @return MailMessage
67
67
  */
68
68
  public function toMail($notifiable)
69
69
  {
@@ -70,7 +70,7 @@ class StorefrontOrderCompleted extends Notification
70
70
  /**
71
71
  * Get the mail representation of the notification.
72
72
  *
73
- * @return \Illuminate\Notifications\Messages\MailMessage
73
+ * @return MailMessage
74
74
  */
75
75
  public function toMail($notifiable)
76
76
  {
@@ -92,7 +92,7 @@ class StorefrontOrderCreated extends Notification
92
92
  /**
93
93
  * Get the mail representation of the notification.
94
94
  *
95
- * @return \Illuminate\Notifications\Messages\MailMessage
95
+ * @return MailMessage
96
96
  */
97
97
  public function toMail($notifiable)
98
98
  {
@@ -69,7 +69,7 @@ class StorefrontOrderDriverAssigned extends Notification
69
69
  /**
70
70
  * Get the mail representation of the notification.
71
71
  *
72
- * @return \Illuminate\Notifications\Messages\MailMessage
72
+ * @return MailMessage
73
73
  */
74
74
  public function toMail($notifiable)
75
75
  {
@@ -68,7 +68,7 @@ class StorefrontOrderEnroute extends Notification
68
68
  /**
69
69
  * Get the mail representation of the notification.
70
70
  *
71
- * @return \Illuminate\Notifications\Messages\MailMessage
71
+ * @return MailMessage
72
72
  */
73
73
  public function toMail($notifiable)
74
74
  {
@@ -70,7 +70,7 @@ class StorefrontOrderNearby extends Notification
70
70
  /**
71
71
  * Get the mail representation of the notification.
72
72
  *
73
- * @return \Illuminate\Notifications\Messages\MailMessage
73
+ * @return MailMessage
74
74
  */
75
75
  public function toMail($notifiable)
76
76
  {
@@ -69,7 +69,7 @@ class StorefrontOrderPreparing extends Notification
69
69
  /**
70
70
  * Get the mail representation of the notification.
71
71
  *
72
- * @return \Illuminate\Notifications\Messages\MailMessage
72
+ * @return MailMessage
73
73
  */
74
74
  public function toMail($notifiable)
75
75
  {
@@ -69,7 +69,7 @@ class StorefrontOrderReadyForPickup extends Notification
69
69
  /**
70
70
  * Get the mail representation of the notification.
71
71
  *
72
- * @return \Illuminate\Notifications\Messages\MailMessage
72
+ * @return MailMessage
73
73
  */
74
74
  public function toMail($notifiable)
75
75
  {
@@ -10,7 +10,7 @@ class NetworkObserver
10
10
  /**
11
11
  * Handle the Network "updated" event.
12
12
  *
13
- * @param \Fleetbase\Storefront\Models\Network $network the Network that is updating
13
+ * @param Network $network the Network that is updating
14
14
  */
15
15
  public function updating(Network $network): void
16
16
  {
@@ -17,7 +17,7 @@ class ProductObserver
17
17
  /**
18
18
  * Handle the Product "created" event.
19
19
  *
20
- * @param \Fleetbase\Storefront\Models\Product $product the Product that was created
20
+ * @param Product $product the Product that was created
21
21
  */
22
22
  public function created(Product $product): void
23
23
  {
@@ -41,7 +41,7 @@ class ProductObserver
41
41
  /**
42
42
  * Handle the Product "updated" event.
43
43
  *
44
- * @param \Fleetbase\Storefront\Models\Product $product the Product that was created
44
+ * @param Product $product the Product that was created
45
45
  */
46
46
  public function updated(Product $product): void
47
47
  {
@@ -0,0 +1,31 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\Storefront\Rules;
4
+
5
+ use Fleetbase\Storefront\Models\Cart;
6
+ use Illuminate\Contracts\Validation\Rule;
7
+
8
+ class CartExists implements Rule
9
+ {
10
+ /**
11
+ * Determine if the validation rule passes.
12
+ *
13
+ * @param string $attribute
14
+ *
15
+ * @return bool
16
+ */
17
+ public function passes($attribute, $value)
18
+ {
19
+ return Cart::where(['public_id' => $attribute, 'unique_identifier' => $attribute])->exists();
20
+ }
21
+
22
+ /**
23
+ * Get the validation error message.
24
+ *
25
+ * @return string
26
+ */
27
+ public function message()
28
+ {
29
+ return 'Cart session does not exists.';
30
+ }
31
+ }
@@ -0,0 +1,34 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\Storefront\Rules;
4
+
5
+ use Fleetbase\FleetOps\Models\Contact;
6
+ use Illuminate\Contracts\Validation\Rule;
7
+ use Illuminate\Support\Str;
8
+
9
+ class CustomerExists implements Rule
10
+ {
11
+ /**
12
+ * Determine if the validation rule passes.
13
+ *
14
+ * @param string $attribute
15
+ *
16
+ * @return bool
17
+ */
18
+ public function passes($attribute, $value)
19
+ {
20
+ $value = Str::replaceFirst('customer', 'contact', $value);
21
+
22
+ return Contact::where('public_id', $value)->exists();
23
+ }
24
+
25
+ /**
26
+ * Get the validation error message.
27
+ *
28
+ * @return string
29
+ */
30
+ public function message()
31
+ {
32
+ return 'No customer found.';
33
+ }
34
+ }
@@ -0,0 +1,35 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\Storefront\Rules;
4
+
5
+ use Fleetbase\Storefront\Models\Gateway;
6
+ use Illuminate\Contracts\Validation\Rule;
7
+
8
+ class GatewayExists implements Rule
9
+ {
10
+ /**
11
+ * Determine if the validation rule passes.
12
+ *
13
+ * @param string $attribute
14
+ *
15
+ * @return bool
16
+ */
17
+ public function passes($attribute, $value)
18
+ {
19
+ if ($value === 'cash') {
20
+ return true;
21
+ }
22
+
23
+ return Gateway::where(['code' => $value])->exists();
24
+ }
25
+
26
+ /**
27
+ * Get the validation error message.
28
+ *
29
+ * @return string
30
+ */
31
+ public function message()
32
+ {
33
+ return 'No gateway by code provided exists.';
34
+ }
35
+ }
@@ -0,0 +1,54 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\Storefront\Rules;
4
+
5
+ use Fleetbase\FleetOps\Models\Place;
6
+ use Fleetbase\FleetOps\Support\Utils;
7
+ use Fleetbase\Storefront\Models\StoreLocation;
8
+ use Illuminate\Contracts\Validation\Rule;
9
+ use Illuminate\Support\Str;
10
+
11
+ class IsValidLocation implements Rule
12
+ {
13
+ /**
14
+ * Determine if the validation rule passes.
15
+ *
16
+ * @param string $attribute
17
+ *
18
+ * @return bool
19
+ */
20
+ public function passes($attribute, $value)
21
+ {
22
+ // Validate Place id
23
+ if (Str::startsWith($value, 'place_')) {
24
+ return Place::where('public_id', $value)->exists();
25
+ }
26
+
27
+ // Validate StoreLocation id
28
+ if (Str::startsWith($value, 'store_location_')) {
29
+ return StoreLocation::where('public_id', $value)->exists();
30
+ }
31
+
32
+ // Validate object with coordinates
33
+ if (isset($value->coordinates)) {
34
+ return Utils::isCoordinates($value->coordinates);
35
+ }
36
+
37
+ // Validate coordinates
38
+ if (Utils::isCoordinates($value)) {
39
+ return true;
40
+ }
41
+
42
+ return false;
43
+ }
44
+
45
+ /**
46
+ * Get the validation error message.
47
+ *
48
+ * @return string
49
+ */
50
+ public function message()
51
+ {
52
+ return 'Invalid :attribute.';
53
+ }
54
+ }
@@ -23,7 +23,7 @@ class Metrics
23
23
  protected Company $company;
24
24
  protected array $metrics = [];
25
25
 
26
- public static function new(Company $company, \DateTime $start = null, \DateTime $end = null): Metrics
26
+ public static function new(Company $company, ?\DateTime $start = null, ?\DateTime $end = null): Metrics
27
27
  {
28
28
  $start = $start === null ? Carbon::create(1900)->toDateTime() : $start;
29
29
  $end = $end === null ? Carbon::tomorrow()->toDateTime() : $end;
@@ -31,7 +31,7 @@ class Metrics
31
31
  return (new static())->setCompany($company)->between($start, $end);
32
32
  }
33
33
 
34
- public static function forCompany(Company $company, \DateTime $start = null, \DateTime $end = null): Metrics
34
+ public static function forCompany(Company $company, ?\DateTime $start = null, ?\DateTime $end = null): Metrics
35
35
  {
36
36
  return static::new($company, $start, $end);
37
37
  }
@@ -104,7 +104,7 @@ class Metrics
104
104
  return $this;
105
105
  }
106
106
 
107
- public function totalProducts(callable $callback = null): Metrics
107
+ public function totalProducts(?callable $callback = null): Metrics
108
108
  {
109
109
  $query = Product::where('company_uuid', $this->company->uuid);
110
110
 
@@ -117,7 +117,7 @@ class Metrics
117
117
  return $this->set('total_products', $data);
118
118
  }
119
119
 
120
- public function totalStores(callable $callback = null): Metrics
120
+ public function totalStores(?callable $callback = null): Metrics
121
121
  {
122
122
  $query = Store::where('company_uuid', $this->company->uuid);
123
123
 
@@ -130,7 +130,7 @@ class Metrics
130
130
  return $this->set('total_stores', $data);
131
131
  }
132
132
 
133
- public function totalNetworks(callable $callback = null): Metrics
133
+ public function totalNetworks(?callable $callback = null): Metrics
134
134
  {
135
135
  $query = Network::where('company_uuid', $this->company->uuid);
136
136
 
@@ -143,7 +143,7 @@ class Metrics
143
143
  return $this->set('total_networks', $data);
144
144
  }
145
145
 
146
- public function ordersInProgress(callable $callback = null): Metrics
146
+ public function ordersInProgress(?callable $callback = null): Metrics
147
147
  {
148
148
  $query = Order::where('company_uuid', $this->company->uuid)
149
149
  ->whereBetween('created_at', [$this->start, $this->end])
@@ -159,7 +159,7 @@ class Metrics
159
159
  return $this->set('orders_in_progress', $data);
160
160
  }
161
161
 
162
- public function ordersCompleted(callable $callback = null): Metrics
162
+ public function ordersCompleted(?callable $callback = null): Metrics
163
163
  {
164
164
  $query = Order::where('company_uuid', $this->company->uuid)
165
165
  ->whereBetween('created_at', [$this->start, $this->end])
@@ -175,7 +175,7 @@ class Metrics
175
175
  return $this->set('orders_completed', $data);
176
176
  }
177
177
 
178
- public function ordersCanceled(callable $callback = null): Metrics
178
+ public function ordersCanceled(?callable $callback = null): Metrics
179
179
  {
180
180
  $query = Order::where('company_uuid', $this->company->uuid)
181
181
  ->whereBetween('created_at', [$this->start, $this->end])
@@ -12,7 +12,7 @@ class QPay
12
12
  private array $requestOptions = [];
13
13
  private Client $client;
14
14
 
15
- public function __construct(string $username = null, string $password = null, string $callbackUrl = null)
15
+ public function __construct(?string $username = null, ?string $password = null, ?string $callbackUrl = null)
16
16
  {
17
17
  $this->callbackUrl = $callbackUrl;
18
18
  $this->requestOptions = [
@@ -60,7 +60,7 @@ class QPay
60
60
  return $this;
61
61
  }
62
62
 
63
- public static function instance(string $username = null, string $password = null, string $callbackUrl = null): QPay
63
+ public static function instance(?string $username = null, ?string $password = null, ?string $callbackUrl = null): QPay
64
64
  {
65
65
  return new static($username, $password, $callbackUrl);
66
66
  }
@@ -120,7 +120,7 @@ class QPay
120
120
  return $this;
121
121
  }
122
122
 
123
- public function setAuthToken(string $accessToken = null): QPay
123
+ public function setAuthToken(?string $accessToken = null): QPay
124
124
  {
125
125
  if ($accessToken) {
126
126
  $this->useBearerToken($accessToken);
@@ -136,7 +136,7 @@ class QPay
136
136
  return $this;
137
137
  }
138
138
 
139
- public function createSimpleInvoice(int $amount, ?string $invoiceCode = '', ?string $invoiceDescription = '', ?string $invoiceReceiverCode = '', ?string $senderInvoiceNo = '', string $callbackUrl = null)
139
+ public function createSimpleInvoice(int $amount, ?string $invoiceCode = '', ?string $invoiceDescription = '', ?string $invoiceReceiverCode = '', ?string $senderInvoiceNo = '', ?string $callbackUrl = null)
140
140
  {
141
141
  if (!$callbackUrl && $this->hasCallbackUrl()) {
142
142
  $callbackUrl = $this->callbackUrl;
@@ -10,6 +10,7 @@ use Fleetbase\Storefront\Models\Network;
10
10
  use Fleetbase\Storefront\Models\Product;
11
11
  use Fleetbase\Storefront\Models\Store;
12
12
  use Fleetbase\Storefront\Notifications\StorefrontOrderCreated;
13
+ use Fleetbase\Support\Utils;
13
14
  use Illuminate\Support\Facades\Notification;
14
15
  use Illuminate\Support\Facades\Redis;
15
16
  use Illuminate\Support\Str;
@@ -92,7 +93,7 @@ class Storefront
92
93
  if ($token) {
93
94
  $accessToken = PersonalAccessToken::findToken($token);
94
95
 
95
- if ($accessToken && Utils::isUuid($accessToken->name)) {
96
+ if ($accessToken && Str::isUuid($accessToken->name)) {
96
97
  $customer = Contact::where('uuid', $accessToken->name)->first();
97
98
 
98
99
  if ($customer) {