@fleetbase/storefront-engine 0.2.4 → 0.2.6

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 (140) hide show
  1. package/README.md +4 -4
  2. package/addon/components/modals/import-products.hbs +1 -1
  3. package/addon/components/schedule-manager.hbs +2 -2
  4. package/addon/components/widget/customers.hbs +1 -1
  5. package/addon/components/widget/customers.js +7 -4
  6. package/addon/components/widget/orders.js +4 -0
  7. package/addon/controllers/base-controller.js +31 -0
  8. package/addon/controllers/networks/index/network.js +2 -2
  9. package/addon/controllers/networks/index.js +3 -2
  10. package/addon/controllers/products/index/category/new.js +14 -11
  11. package/addon/controllers/products/index/category.js +2 -2
  12. package/addon/controllers/products/index/index.js +2 -2
  13. package/addon/controllers/products/index.js +2 -3
  14. package/addon/models/network.js +0 -1
  15. package/addon/models/product-addon-category.js +10 -1
  16. package/addon/models/product-variant.js +0 -2
  17. package/addon/models/product.js +35 -2
  18. package/addon/routes/customers/index.js +11 -1
  19. package/addon/routes/networks/index.js +9 -0
  20. package/addon/routes/orders/index.js +11 -1
  21. package/addon/routes/products/index.js +8 -2
  22. package/addon/serializers/product.js +16 -0
  23. package/addon/services/storefront.js +81 -0
  24. package/addon/templates/networks/index/network/stores.hbs +2 -2
  25. package/addon/templates/networks/index/network.hbs +1 -1
  26. package/addon/templates/products/index/category/new.hbs +3 -3
  27. package/addon/templates/products/index/category.hbs +20 -3
  28. package/app/controllers/base-controller.js +1 -0
  29. package/assets/sounds/storefront_order_alert.mp3 +0 -0
  30. package/composer.json +3 -3
  31. package/config/environment.js +11 -1
  32. package/extension.json +1 -1
  33. package/index.js +15 -0
  34. package/package.json +132 -125
  35. package/server/src/Auth/Schemas/Storefront.php +31 -39
  36. package/server/src/Console/Commands/NotifyStorefrontOrderNearby.php +9 -11
  37. package/server/src/Expansions/ContactFilterExpansion.php +36 -0
  38. package/server/src/Expansions/EntityExpansion.php +12 -12
  39. package/server/src/Expansions/OrderFilterExpansion.php +31 -0
  40. package/server/src/Expansions/VendorFilterExpansion.php +36 -0
  41. package/server/src/Http/Controllers/ActionController.php +9 -11
  42. package/server/src/Http/Controllers/AddonCategoryController.php +1 -1
  43. package/server/src/Http/Controllers/CustomerController.php +1 -1
  44. package/server/src/Http/Controllers/GatewayController.php +1 -1
  45. package/server/src/Http/Controllers/MetricsController.php +17 -17
  46. package/server/src/Http/Controllers/NetworkController.php +16 -26
  47. package/server/src/Http/Controllers/NotificationChannelController.php +1 -1
  48. package/server/src/Http/Controllers/OrderController.php +18 -22
  49. package/server/src/Http/Controllers/ProductAddonCategoryController.php +1 -2
  50. package/server/src/Http/Controllers/ProductAddonController.php +1 -2
  51. package/server/src/Http/Controllers/ProductController.php +89 -44
  52. package/server/src/Http/Controllers/ProductHourController.php +1 -1
  53. package/server/src/Http/Controllers/ProductVariantController.php +1 -1
  54. package/server/src/Http/Controllers/ProductVariantOptionController.php +1 -1
  55. package/server/src/Http/Controllers/ReviewController.php +1 -1
  56. package/server/src/Http/Controllers/StoreController.php +1 -2
  57. package/server/src/Http/Controllers/StoreHourController.php +1 -1
  58. package/server/src/Http/Controllers/StoreLocationController.php +1 -1
  59. package/server/src/Http/Controllers/StorefrontController.php +0 -2
  60. package/server/src/Http/Controllers/VoteController.php +1 -1
  61. package/server/src/Http/Controllers/v1/CartController.php +16 -26
  62. package/server/src/Http/Controllers/v1/CategoryController.php +3 -4
  63. package/server/src/Http/Controllers/v1/CheckoutController.php +283 -286
  64. package/server/src/Http/Controllers/v1/CustomerController.php +54 -67
  65. package/server/src/Http/Controllers/v1/GatewayControllerController.php +0 -2
  66. package/server/src/Http/Controllers/v1/NetworkController.php +26 -23
  67. package/server/src/Http/Controllers/v1/PaymentMethodController.php +0 -2
  68. package/server/src/Http/Controllers/v1/ProductController.php +1 -4
  69. package/server/src/Http/Controllers/v1/ReviewController.php +31 -35
  70. package/server/src/Http/Controllers/v1/ServiceQuoteController.php +57 -53
  71. package/server/src/Http/Controllers/v1/StoreController.php +8 -16
  72. package/server/src/Http/Filter/AddonCategoryFilter.php +1 -1
  73. package/server/src/Http/Filter/OrderFilter.php +2 -2
  74. package/server/src/Http/Middleware/SetStorefrontSession.php +9 -20
  75. package/server/src/Http/Requests/AddStoreToNetworkCategory.php +3 -3
  76. package/server/src/Http/Requests/CreateCustomerRequest.php +5 -7
  77. package/server/src/Http/Requests/CreateReviewRequest.php +4 -5
  78. package/server/src/Http/Requests/GetServiceQuoteFromCart.php +2 -2
  79. package/server/src/Http/Requests/InitializeCheckoutRequest.php +5 -5
  80. package/server/src/Http/Requests/NetworkActionRequest.php +2 -2
  81. package/server/src/Http/Requests/VerifyCreateCustomerRequest.php +2 -2
  82. package/server/src/Http/Resources/Cart.php +20 -11
  83. package/server/src/Http/Resources/Category.php +12 -11
  84. package/server/src/Http/Resources/Customer.php +15 -14
  85. package/server/src/Http/Resources/Gateway.php +12 -11
  86. package/server/src/Http/Resources/Media.php +9 -8
  87. package/server/src/Http/Resources/Network.php +33 -28
  88. package/server/src/Http/Resources/Product.php +89 -81
  89. package/server/src/Http/Resources/Review.php +14 -13
  90. package/server/src/Http/Resources/ReviewCustomer.php +12 -11
  91. package/server/src/Http/Resources/Store.php +39 -33
  92. package/server/src/Http/Resources/StoreHour.php +9 -8
  93. package/server/src/Http/Resources/StoreLocation.php +9 -9
  94. package/server/src/Imports/ProductsImport.php +0 -2
  95. package/server/src/Jobs/DownloadProductImageUrl.php +7 -4
  96. package/server/src/Listeners/HandleOrderCompleted.php +2 -1
  97. package/server/src/Listeners/HandleOrderDispatched.php +2 -1
  98. package/server/src/Listeners/HandleOrderDriverAssigned.php +2 -1
  99. package/server/src/Listeners/HandleOrderStarted.php +4 -3
  100. package/server/src/Mail/StorefrontNetworkInvite.php +7 -6
  101. package/server/src/Models/AddonCategory.php +2 -4
  102. package/server/src/Models/Cart.php +117 -124
  103. package/server/src/Models/Checkout.php +14 -12
  104. package/server/src/Models/Customer.php +9 -9
  105. package/server/src/Models/Gateway.php +22 -22
  106. package/server/src/Models/Network.php +41 -52
  107. package/server/src/Models/NetworkStore.php +6 -5
  108. package/server/src/Models/NotificationChannel.php +11 -9
  109. package/server/src/Models/PaymentMethod.php +9 -7
  110. package/server/src/Models/Product.php +152 -30
  111. package/server/src/Models/ProductAddon.php +14 -11
  112. package/server/src/Models/ProductAddonCategory.php +9 -8
  113. package/server/src/Models/ProductHour.php +6 -5
  114. package/server/src/Models/ProductStoreLocation.php +7 -5
  115. package/server/src/Models/ProductVariant.php +15 -11
  116. package/server/src/Models/ProductVariantOption.php +12 -9
  117. package/server/src/Models/Review.php +9 -7
  118. package/server/src/Models/Store.php +68 -84
  119. package/server/src/Models/StoreHour.php +6 -5
  120. package/server/src/Models/StoreLocation.php +12 -8
  121. package/server/src/Models/StorefrontModel.php +1 -1
  122. package/server/src/Models/Vote.php +8 -6
  123. package/server/src/Notifications/StorefrontOrderCanceled.php +15 -19
  124. package/server/src/Notifications/StorefrontOrderCompleted.php +15 -19
  125. package/server/src/Notifications/StorefrontOrderCreated.php +31 -36
  126. package/server/src/Notifications/StorefrontOrderDriverAssigned.php +15 -20
  127. package/server/src/Notifications/StorefrontOrderEnroute.php +14 -19
  128. package/server/src/Notifications/StorefrontOrderNearby.php +16 -21
  129. package/server/src/Notifications/StorefrontOrderPreparing.php +15 -18
  130. package/server/src/Notifications/StorefrontOrderReadyForPickup.php +15 -18
  131. package/server/src/Observers/NetworkObserver.php +2 -3
  132. package/server/src/Observers/ProductObserver.php +17 -33
  133. package/server/src/Providers/EventServiceProvider.php +15 -4
  134. package/server/src/Providers/StorefrontServiceProvider.php +8 -10
  135. package/server/src/Support/Metrics.php +12 -12
  136. package/server/src/Support/OrderConfig.php +3 -2
  137. package/server/src/Support/QPay.php +22 -20
  138. package/server/src/Support/Storefront.php +18 -17
  139. package/server/src/routes.php +1 -1
  140. package/tsconfig.declarations.json +10 -0
@@ -6,22 +6,22 @@ use GuzzleHttp\Client;
6
6
 
7
7
  class QPay
8
8
  {
9
- private string $host = 'https://merchant.qpay.mn/';
9
+ private string $host = 'https://merchant.qpay.mn/';
10
10
  private string $namespace = 'v2';
11
11
  private ?string $callbackUrl;
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
- $this->callbackUrl = $callbackUrl;
17
+ $this->callbackUrl = $callbackUrl;
18
18
  $this->requestOptions = [
19
19
  'base_uri' => $this->buildRequestUrl(),
20
- 'auth' => [$username, $password],
21
- 'headers' => [
20
+ 'auth' => [$username, $password],
21
+ 'headers' => [
22
22
  'Content-Type' => 'application/json',
23
- 'Accept' => 'application/json'
24
- ]
23
+ 'Accept' => 'application/json',
24
+ ],
25
25
  ];
26
26
  $this->client = new Client($this->requestOptions);
27
27
  }
@@ -29,7 +29,7 @@ class QPay
29
29
  public function updateRequestOption($key, $value)
30
30
  {
31
31
  $this->requestOptions[$key] = $value;
32
- $this->client = new Client($this->requestOptions);
32
+ $this->client = new Client($this->requestOptions);
33
33
  }
34
34
 
35
35
  public function getClient()
@@ -48,6 +48,7 @@ class QPay
48
48
  private function buildRequestUrl(string $path = ''): string
49
49
  {
50
50
  $url = trim($this->host . $this->namespace . '/' . $path);
51
+
51
52
  return $url;
52
53
  }
53
54
 
@@ -59,7 +60,7 @@ class QPay
59
60
  return $this;
60
61
  }
61
62
 
62
- 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
63
64
  {
64
65
  return new static($username, $password, $callbackUrl);
65
66
  }
@@ -74,9 +75,9 @@ class QPay
74
75
  $options['http_errors'] = false;
75
76
 
76
77
  $response = $this->client->request($method, $path, $options);
77
- $body = $response->getBody();
78
+ $body = $response->getBody();
78
79
  $contents = $body->getContents();
79
- $json = json_decode($contents);
80
+ $json = json_decode($contents);
80
81
 
81
82
  return $json;
82
83
  }
@@ -119,13 +120,13 @@ class QPay
119
120
  return $this;
120
121
  }
121
122
 
122
- public function setAuthToken(?string $accessToken = null): QPay
123
+ public function setAuthToken(string $accessToken = null): QPay
123
124
  {
124
125
  if ($accessToken) {
125
126
  $this->useBearerToken($accessToken);
126
127
  } else {
127
128
  $response = $this->getAuthToken();
128
- $token = $response->access_token;
129
+ $token = $response->access_token;
129
130
 
130
131
  if (isset($token)) {
131
132
  $this->useBearerToken($token);
@@ -135,19 +136,19 @@ class QPay
135
136
  return $this;
136
137
  }
137
138
 
138
- 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)
139
140
  {
140
141
  if (!$callbackUrl && $this->hasCallbackUrl()) {
141
142
  $callbackUrl = $this->callbackUrl;
142
143
  }
143
144
 
144
145
  $params = array_filter([
145
- 'invoice_code' => $invoiceCode,
146
- 'amount' => $amount,
147
- 'callback_url' => $callbackUrl,
148
- 'invoice_description' => $invoiceDescription,
146
+ 'invoice_code' => $invoiceCode,
147
+ 'amount' => $amount,
148
+ 'callback_url' => $callbackUrl,
149
+ 'invoice_description' => $invoiceDescription,
149
150
  'invoice_receiver_code' => $invoiceReceiverCode,
150
- 'sender_invoice_no' => $senderInvoiceNo,
151
+ 'sender_invoice_no' => $senderInvoiceNo,
151
152
  ]);
152
153
 
153
154
  return $this->createQPayInvoice($params);
@@ -166,7 +167,7 @@ class QPay
166
167
  {
167
168
  $params = [
168
169
  'object_type' => 'INVOICE',
169
- 'object_id' => $invoiceId
170
+ 'object_id' => $invoiceId,
170
171
  ];
171
172
 
172
173
  return $this->post('payment/check', $params, $options);
@@ -203,6 +204,7 @@ class QPay
203
204
  public static function cleanCode(string $code)
204
205
  {
205
206
  $code = str_replace(' ', '-', $code);
207
+
206
208
  return preg_replace('/[^A-Za-z0-9\-]/', '', $code);
207
209
  }
208
210
  }
@@ -2,13 +2,13 @@
2
2
 
3
3
  namespace Fleetbase\Storefront\Support;
4
4
 
5
+ use Fleetbase\FleetOps\Models\Contact;
6
+ use Fleetbase\FleetOps\Models\Order;
7
+ use Fleetbase\Models\User;
5
8
  use Fleetbase\Storefront\Models\Gateway;
6
9
  use Fleetbase\Storefront\Models\Network;
7
10
  use Fleetbase\Storefront\Models\Product;
8
11
  use Fleetbase\Storefront\Models\Store;
9
- use Fleetbase\FleetOps\Models\Contact;
10
- use Fleetbase\FleetOps\Models\Order;
11
- use Fleetbase\Models\User;
12
12
  use Fleetbase\Storefront\Notifications\StorefrontOrderCreated;
13
13
  use Illuminate\Support\Facades\Notification;
14
14
  use Illuminate\Support\Facades\Redis;
@@ -22,6 +22,7 @@ class Storefront
22
22
  * with bare minimum columns, but can optionally pass in more columns to receive.
23
23
  *
24
24
  * @param array $columns
25
+ *
25
26
  * @return \Fleetbase\Models\Storefront\Network|\Fleetbase\Models\Storefront\Store
26
27
  */
27
28
  public static function about($columns = [], $with = [])
@@ -42,7 +43,7 @@ class Storefront
42
43
  $about = Network::select($columns)->where('key', $key)->with($with)->first();
43
44
  }
44
45
 
45
- $about->is_store = Str::startsWith($key, 'store');
46
+ $about->is_store = Str::startsWith($key, 'store');
46
47
  $about->is_network = Str::startsWith($key, 'network');
47
48
 
48
49
  return $about;
@@ -64,7 +65,7 @@ class Storefront
64
65
  return $about;
65
66
  }
66
67
 
67
- $about->is_store = Str::startsWith($id, 'store');
68
+ $about->is_store = Str::startsWith($id, 'store');
68
69
  $about->is_network = Str::startsWith($id, 'network');
69
70
 
70
71
  return $about;
@@ -114,7 +115,7 @@ class Storefront
114
115
  }
115
116
 
116
117
  return Gateway::where([
117
- 'code' => $code,
118
+ 'code' => $code,
118
119
  'owner_uuid' => session('storefront_store') ?? session('storefront_network'),
119
120
  ])->first();
120
121
  }
@@ -150,21 +151,21 @@ class Storefront
150
151
 
151
152
  public static function alertNewOrder(Order $order, $sendNow = false)
152
153
  {
153
- $about = static::about(['alertable']);
154
+ $about = static::about(['alertable']);
154
155
  $alertables = [];
155
156
 
156
157
  if ($about->is_network) {
157
158
  $store = static::findAbout($order->getMeta('storefront_id'), ['alertable']);
158
159
 
159
160
  if ($store && $store->public_id !== $about->public_id) {
160
- $merge = Utils::get($store, 'alertable.for_new_order', []);
161
+ $merge = Utils::get($store, 'alertable.for_new_order', []);
161
162
  $alertables = array_merge($alertables, $merge);
162
163
  }
163
164
  }
164
165
 
165
- $merge = Utils::get($about, 'alertable.for_new_order', []);
166
+ $merge = Utils::get($about, 'alertable.for_new_order', []);
166
167
  $alertables = array_merge($alertables, $merge);
167
- $users = collect($alertables)->map(function ($id) {
168
+ $users = collect($alertables)->map(function ($id) {
168
169
  return User::where('public_id', $id)->first();
169
170
  });
170
171
 
@@ -183,14 +184,14 @@ class Storefront
183
184
  {
184
185
  $stripeCustomer = \Stripe\Customer::create([
185
186
  'description' => 'Customer created in Fleetbase Storefront',
186
- 'email' => $customer->email,
187
- 'name' => $customer->name,
188
- 'phone' => $customer->phone,
189
- 'metadata' => [
190
- 'contact_id' => $customer->public_id,
187
+ 'email' => $customer->email,
188
+ 'name' => $customer->name,
189
+ 'phone' => $customer->phone,
190
+ 'metadata' => [
191
+ 'contact_id' => $customer->public_id,
191
192
  'storefront_id' => session('storefront_store') ?? session('storefront_network'),
192
- 'company_id' => session('company')
193
- ]
193
+ 'company_id' => session('company'),
194
+ ],
194
195
  ]);
195
196
 
196
197
  // set the stripe customer to customer meta
@@ -161,7 +161,7 @@ Route::prefix(config('storefront.api.routing.prefix', 'storefront'))->namespace(
161
161
  $router->group(
162
162
  [],
163
163
  function ($router) {
164
- /** Dashboard Build */
164
+ /* Dashboard Build */
165
165
  $router->get('dashboard', 'MetricsController@dashboard');
166
166
 
167
167
  $router->group(
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "declarationDir": "declarations",
5
+ "emitDeclarationOnly": true,
6
+ "noEmit": false,
7
+ "rootDir": "."
8
+ },
9
+ "include": ["addon", "addon-test-support"]
10
+ }