@fleetbase/storefront-engine 0.1.6 → 0.1.8

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 (333) hide show
  1. package/.php-cs-fixer.php +29 -0
  2. package/LICENSE.md +16 -4
  3. package/README.md +106 -13
  4. package/addon/components/modals/add-store-to-category.hbs +5 -0
  5. package/addon/components/modals/create-network-category.hbs +28 -28
  6. package/addon/components/modals/share-network.hbs +3 -3
  7. package/addon/components/modals/store-details.hbs +22 -0
  8. package/addon/components/modals/store-form.hbs +22 -0
  9. package/addon/components/modals/store-form.js +21 -0
  10. package/addon/components/network-category-picker.hbs +40 -0
  11. package/addon/components/network-category-picker.js +83 -0
  12. package/addon/components/store-selector.hbs +4 -2
  13. package/addon/components/widget/orders.js +22 -17
  14. package/addon/controllers/networks/index/network/index.js +133 -9
  15. package/addon/controllers/networks/index/network/stores.js +422 -153
  16. package/addon/controllers/networks/index.js +66 -4
  17. package/addon/controllers/products/index/category.js +1 -1
  18. package/addon/controllers/settings/index.js +14 -7
  19. package/addon/controllers/settings/notifications.js +1 -1
  20. package/addon/models/store.js +44 -7
  21. package/addon/routes/networks/index/network/customers.js +4 -1
  22. package/addon/routes/networks/index/network/orders.js +4 -1
  23. package/addon/routes/networks/index/network/stores.js +19 -15
  24. package/addon/serializers/store.js +1 -0
  25. package/addon/templates/customers/index.hbs +0 -11
  26. package/addon/templates/networks/index/network/index.hbs +1 -1
  27. package/addon/templates/networks/index/network/stores.hbs +8 -163
  28. package/addon/templates/networks/index/network.hbs +2 -3
  29. package/addon/utils/create-shareable-link.js +21 -0
  30. package/app/adapters/addon-category.js +1 -1
  31. package/app/adapters/gateway.js +1 -1
  32. package/app/adapters/network.js +1 -1
  33. package/app/adapters/notification-channel.js +1 -1
  34. package/app/adapters/product-addon-category.js +1 -1
  35. package/app/adapters/product-addon.js +1 -1
  36. package/app/adapters/product-hour.js +1 -1
  37. package/app/adapters/product-store-location.js +1 -1
  38. package/app/adapters/product-variant-option.js +1 -1
  39. package/app/adapters/product-variant.js +1 -1
  40. package/app/adapters/product.js +1 -1
  41. package/app/adapters/store-hour.js +1 -1
  42. package/app/adapters/store-location.js +1 -1
  43. package/app/adapters/store.js +1 -1
  44. package/app/adapters/storefront.js +1 -1
  45. package/app/components/file-record.js +1 -1
  46. package/app/components/modals/add-store-hours.js +1 -1
  47. package/app/components/modals/add-store-to-category.js +1 -0
  48. package/app/components/modals/add-stores-to-network.js +1 -1
  49. package/app/components/modals/assign-driver.js +1 -1
  50. package/app/components/modals/create-first-store.js +1 -1
  51. package/app/components/modals/create-gateway.js +1 -1
  52. package/app/components/modals/create-network-category.js +1 -1
  53. package/app/components/modals/create-network.js +1 -1
  54. package/app/components/modals/create-new-variant.js +1 -1
  55. package/app/components/modals/create-notification-channel.js +1 -1
  56. package/app/components/modals/create-product-category.js +1 -1
  57. package/app/components/modals/create-store.js +1 -1
  58. package/app/components/modals/edit-network.js +1 -1
  59. package/app/components/modals/import-products.js +1 -1
  60. package/app/components/modals/incoming-order.js +1 -1
  61. package/app/components/modals/manage-addons.js +1 -1
  62. package/app/components/modals/order-ready-assign-driver.js +1 -1
  63. package/app/components/modals/select-addon-category.js +1 -1
  64. package/app/components/modals/share-network.js +1 -1
  65. package/app/components/modals/store-details.js +1 -0
  66. package/app/components/modals/store-form.js +1 -0
  67. package/app/components/modals/store-location-form.js +1 -1
  68. package/app/components/network-category-picker.js +1 -0
  69. package/app/components/order-card.js +1 -1
  70. package/app/components/schedule-manager.js +1 -1
  71. package/app/components/settings-container.js +1 -1
  72. package/app/components/store-selector.js +1 -1
  73. package/app/components/widget/customers.js +1 -1
  74. package/app/components/widget/orders.js +1 -1
  75. package/app/components/widget/storefront-metrics.js +1 -1
  76. package/app/controllers/application.js +1 -1
  77. package/app/controllers/customers/index.js +1 -1
  78. package/app/controllers/home.js +1 -1
  79. package/app/controllers/networks/index/network/customers.js +1 -1
  80. package/app/controllers/networks/index/network/index.js +1 -1
  81. package/app/controllers/networks/index/network/orders.js +1 -1
  82. package/app/controllers/networks/index/network/stores.js +1 -1
  83. package/app/controllers/networks/index/network.js +1 -1
  84. package/app/controllers/networks/index.js +1 -1
  85. package/app/controllers/orders/index.js +1 -1
  86. package/app/controllers/products/index/category/edit.js +1 -1
  87. package/app/controllers/products/index/category/new.js +1 -1
  88. package/app/controllers/products/index/category.js +1 -1
  89. package/app/controllers/products/index/index/edit.js +1 -1
  90. package/app/controllers/products/index/index.js +1 -1
  91. package/app/controllers/products/index.js +1 -1
  92. package/app/controllers/settings/api.js +1 -1
  93. package/app/controllers/settings/gateways.js +1 -1
  94. package/app/controllers/settings/index.js +1 -1
  95. package/app/controllers/settings/locations.js +1 -1
  96. package/app/controllers/settings/notifications.js +1 -1
  97. package/app/helpers/get-tip-amount.js +1 -1
  98. package/app/models/addon-category.js +1 -1
  99. package/app/models/gateway.js +1 -1
  100. package/app/models/network.js +1 -1
  101. package/app/models/notification-channel.js +1 -1
  102. package/app/models/product-addon-category.js +1 -1
  103. package/app/models/product-addon.js +1 -1
  104. package/app/models/product-hour.js +1 -1
  105. package/app/models/product-store-location.js +1 -1
  106. package/app/models/product-variant-option.js +1 -1
  107. package/app/models/product-variant.js +1 -1
  108. package/app/models/product.js +1 -1
  109. package/app/models/store-hour.js +1 -1
  110. package/app/models/store-location.js +1 -1
  111. package/app/models/store.js +1 -1
  112. package/app/routes/application.js +1 -1
  113. package/app/routes/customers/index/edit.js +1 -1
  114. package/app/routes/customers/index.js +1 -1
  115. package/app/routes/home.js +1 -1
  116. package/app/routes/networks/index/network/customers.js +1 -1
  117. package/app/routes/networks/index/network/index.js +1 -1
  118. package/app/routes/networks/index/network/orders.js +1 -1
  119. package/app/routes/networks/index/network/stores.js +1 -1
  120. package/app/routes/networks/index/network.js +1 -1
  121. package/app/routes/networks/index.js +1 -1
  122. package/app/routes/orders/index/edit.js +1 -1
  123. package/app/routes/orders/index/new.js +1 -1
  124. package/app/routes/orders/index/view.js +1 -1
  125. package/app/routes/orders/index.js +1 -1
  126. package/app/routes/products/index/category/edit.js +1 -1
  127. package/app/routes/products/index/category/new.js +1 -1
  128. package/app/routes/products/index/category.js +1 -1
  129. package/app/routes/products/index/index/edit.js +1 -1
  130. package/app/routes/products/index/index.js +1 -1
  131. package/app/routes/products/index.js +1 -1
  132. package/app/routes/settings/api.js +1 -1
  133. package/app/routes/settings/gateways.js +1 -1
  134. package/app/routes/settings/index.js +1 -1
  135. package/app/routes/settings/locations.js +1 -1
  136. package/app/routes/settings/notifications.js +1 -1
  137. package/app/serializers/addon-category.js +1 -1
  138. package/app/serializers/network.js +1 -1
  139. package/app/serializers/notification-channel.js +1 -1
  140. package/app/serializers/product-addon-category.js +1 -1
  141. package/app/serializers/product-variant.js +1 -1
  142. package/app/serializers/product.js +1 -1
  143. package/app/serializers/store-location.js +1 -1
  144. package/app/serializers/store.js +1 -1
  145. package/app/services/storefront.js +1 -1
  146. package/app/templates/customers/index/edit.js +1 -1
  147. package/app/templates/customers/index.js +1 -1
  148. package/app/templates/home.js +1 -1
  149. package/app/templates/networks/index/network/customers.js +1 -1
  150. package/app/templates/networks/index/network/index.js +1 -1
  151. package/app/templates/networks/index/network/orders.js +1 -1
  152. package/app/templates/networks/index/network/stores.js +1 -1
  153. package/app/templates/networks/index/network.js +1 -1
  154. package/app/templates/networks/index.js +1 -1
  155. package/app/templates/orders/index/edit.js +1 -1
  156. package/app/templates/orders/index/new.js +1 -1
  157. package/app/templates/orders/index/view.js +1 -1
  158. package/app/templates/orders/index.js +1 -1
  159. package/app/templates/products/index/category/edit.js +1 -1
  160. package/app/templates/products/index/category/new.js +1 -1
  161. package/app/templates/products/index/category.js +1 -1
  162. package/app/templates/products/index/index/edit.js +1 -1
  163. package/app/templates/products/index/index.js +1 -1
  164. package/app/templates/products/index.js +1 -1
  165. package/app/templates/settings/api.js +1 -1
  166. package/app/templates/settings/gateways.js +1 -1
  167. package/app/templates/settings/index.js +1 -1
  168. package/app/templates/settings/locations.js +1 -1
  169. package/app/templates/settings/notifications.js +1 -1
  170. package/app/templates/settings.js +1 -1
  171. package/app/utils/create-shareable-link.js +1 -0
  172. package/app/utils/get-gateway-schemas.js +1 -1
  173. package/app/utils/get-notification-schemas.js +1 -1
  174. package/composer.json +88 -0
  175. package/extension.json +10 -0
  176. package/package.json +6 -7
  177. package/phpstan.neon.dist +8 -0
  178. package/phpunit.xml.dist +16 -0
  179. package/server/.gitattributes +14 -0
  180. package/server/README.md +40 -0
  181. package/server/config/api.php +101 -0
  182. package/server/config/database.connections.php +57 -0
  183. package/server/config/storefront.php +19 -0
  184. package/server/config/twilio-notification-channel.php +36 -0
  185. package/server/migrations/2023_05_03_025307_create_carts_table.php +44 -0
  186. package/server/migrations/2023_05_03_025307_create_checkouts_table.php +51 -0
  187. package/server/migrations/2023_05_03_025307_create_gateways_table.php +48 -0
  188. package/server/migrations/2023_05_03_025307_create_network_stores_table.php +36 -0
  189. package/server/migrations/2023_05_03_025307_create_networks_table.php +56 -0
  190. package/server/migrations/2023_05_03_025307_create_notification_channels_table.php +43 -0
  191. package/server/migrations/2023_05_03_025307_create_payment_methods_table.php +44 -0
  192. package/server/migrations/2023_05_03_025307_create_product_addon_categories_table.php +38 -0
  193. package/server/migrations/2023_05_03_025307_create_product_addons_table.php +43 -0
  194. package/server/migrations/2023_05_03_025307_create_product_hours_table.php +37 -0
  195. package/server/migrations/2023_05_03_025307_create_product_store_locations_table.php +34 -0
  196. package/server/migrations/2023_05_03_025307_create_product_variant_options_table.php +40 -0
  197. package/server/migrations/2023_05_03_025307_create_product_variants_table.php +44 -0
  198. package/server/migrations/2023_05_03_025307_create_products_table.php +59 -0
  199. package/server/migrations/2023_05_03_025307_create_reviews_table.php +41 -0
  200. package/server/migrations/2023_05_03_025307_create_store_hours_table.php +37 -0
  201. package/server/migrations/2023_05_03_025307_create_store_locations_table.php +38 -0
  202. package/server/migrations/2023_05_03_025307_create_stores_table.php +57 -0
  203. package/server/migrations/2023_05_03_025307_create_votes_table.php +39 -0
  204. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_carts_table.php +40 -0
  205. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_checkouts_table.php +48 -0
  206. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_gateways_table.php +40 -0
  207. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_network_stores_table.php +40 -0
  208. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_networks_table.php +42 -0
  209. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_notification_channels_table.php +40 -0
  210. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_payment_methods_table.php +40 -0
  211. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_addon_categories_table.php +38 -0
  212. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_addons_table.php +38 -0
  213. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_hours_table.php +32 -0
  214. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_store_locations_table.php +34 -0
  215. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_variant_options_table.php +32 -0
  216. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_product_variants_table.php +32 -0
  217. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_products_table.php +44 -0
  218. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_reviews_table.php +38 -0
  219. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_store_hours_table.php +32 -0
  220. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_store_locations_table.php +40 -0
  221. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_stores_table.php +42 -0
  222. package/server/migrations/2023_05_03_025310_add_foreign_keys_to_votes_table.php +38 -0
  223. package/server/src/Auth/Schemas/Storefront.php +95 -0
  224. package/server/src/Console/Commands/NotifyStorefrontOrderNearby.php +86 -0
  225. package/server/src/Expansions/EntityExpansion.php +44 -0
  226. package/server/src/Http/Controllers/ActionController.php +119 -0
  227. package/server/src/Http/Controllers/AddonCategoryController.php +13 -0
  228. package/server/src/Http/Controllers/CustomerController.php +13 -0
  229. package/server/src/Http/Controllers/GatewayController.php +13 -0
  230. package/server/src/Http/Controllers/MetricsController.php +71 -0
  231. package/server/src/Http/Controllers/NetworkController.php +170 -0
  232. package/server/src/Http/Controllers/NotificationChannelController.php +13 -0
  233. package/server/src/Http/Controllers/OrderController.php +154 -0
  234. package/server/src/Http/Controllers/ProductAddonCategoryController.php +14 -0
  235. package/server/src/Http/Controllers/ProductAddonController.php +14 -0
  236. package/server/src/Http/Controllers/ProductController.php +123 -0
  237. package/server/src/Http/Controllers/ProductHourController.php +13 -0
  238. package/server/src/Http/Controllers/ProductVariantController.php +13 -0
  239. package/server/src/Http/Controllers/ProductVariantOptionController.php +13 -0
  240. package/server/src/Http/Controllers/ReviewController.php +13 -0
  241. package/server/src/Http/Controllers/StoreController.php +26 -0
  242. package/server/src/Http/Controllers/StoreHourController.php +13 -0
  243. package/server/src/Http/Controllers/StoreLocationController.php +13 -0
  244. package/server/src/Http/Controllers/StorefrontController.php +15 -0
  245. package/server/src/Http/Controllers/VoteController.php +13 -0
  246. package/server/src/Http/Controllers/v1/CartController.php +161 -0
  247. package/server/src/Http/Controllers/v1/CategoryController.php +138 -0
  248. package/server/src/Http/Controllers/v1/CheckoutController.php +957 -0
  249. package/server/src/Http/Controllers/v1/CustomerController.php +482 -0
  250. package/server/src/Http/Controllers/v1/GatewayControllerController.php +11 -0
  251. package/server/src/Http/Controllers/v1/NetworkController.php +281 -0
  252. package/server/src/Http/Controllers/v1/PaymentMethodController.php +11 -0
  253. package/server/src/Http/Controllers/v1/ProductController.php +94 -0
  254. package/server/src/Http/Controllers/v1/ReviewController.php +270 -0
  255. package/server/src/Http/Controllers/v1/ServiceQuoteController.php +402 -0
  256. package/server/src/Http/Controllers/v1/StoreController.php +176 -0
  257. package/server/src/Http/Filter/AddonCategoryFilter.php +19 -0
  258. package/server/src/Http/Filter/CustomerFilter.php +18 -0
  259. package/server/src/Http/Filter/GatewayFilter.php +13 -0
  260. package/server/src/Http/Filter/NetworkFilter.php +18 -0
  261. package/server/src/Http/Filter/NotificationChannelFilter.php +13 -0
  262. package/server/src/Http/Filter/OrderFilter.php +46 -0
  263. package/server/src/Http/Filter/ProductFilter.php +28 -0
  264. package/server/src/Http/Filter/StoreFilter.php +42 -0
  265. package/server/src/Http/Filter/StoreLocationFilter.php +23 -0
  266. package/server/src/Http/Middleware/SetStorefrontSession.php +130 -0
  267. package/server/src/Http/Requests/AddStoreToNetworkCategory.php +45 -0
  268. package/server/src/Http/Requests/CaptureOrderRequest.php +30 -0
  269. package/server/src/Http/Requests/CreateCustomerRequest.php +44 -0
  270. package/server/src/Http/Requests/CreateReviewRequest.php +34 -0
  271. package/server/src/Http/Requests/GetServiceQuoteFromCart.php +40 -0
  272. package/server/src/Http/Requests/InitializeCheckoutRequest.php +38 -0
  273. package/server/src/Http/Requests/NetworkActionRequest.php +43 -0
  274. package/server/src/Http/Requests/VerifyCreateCustomerRequest.php +31 -0
  275. package/server/src/Http/Resources/Cart.php +31 -0
  276. package/server/src/Http/Resources/Category.php +48 -0
  277. package/server/src/Http/Resources/Customer.php +36 -0
  278. package/server/src/Http/Resources/Gateway.php +32 -0
  279. package/server/src/Http/Resources/Media.php +29 -0
  280. package/server/src/Http/Resources/Network.php +48 -0
  281. package/server/src/Http/Resources/Product.php +209 -0
  282. package/server/src/Http/Resources/Review.php +45 -0
  283. package/server/src/Http/Resources/ReviewCustomer.php +60 -0
  284. package/server/src/Http/Resources/Store.php +76 -0
  285. package/server/src/Http/Resources/StoreHour.php +29 -0
  286. package/server/src/Http/Resources/StoreLocation.php +33 -0
  287. package/server/src/Imports/ProductsImport.php +20 -0
  288. package/server/src/Jobs/DownloadProductImageUrl.php +60 -0
  289. package/server/src/Listeners/HandleOrderCompleted.php +31 -0
  290. package/server/src/Listeners/HandleOrderDispatched.php +34 -0
  291. package/server/src/Listeners/HandleOrderDriverAssigned.php +37 -0
  292. package/server/src/Listeners/HandleOrderStarted.php +27 -0
  293. package/server/src/Mail/StorefrontNetworkInvite.php +48 -0
  294. package/server/src/Models/AddonCategory.php +30 -0
  295. package/server/src/Models/Cart.php +691 -0
  296. package/server/src/Models/Checkout.php +166 -0
  297. package/server/src/Models/Customer.php +88 -0
  298. package/server/src/Models/Gateway.php +165 -0
  299. package/server/src/Models/Network.php +300 -0
  300. package/server/src/Models/NetworkStore.php +86 -0
  301. package/server/src/Models/NotificationChannel.php +147 -0
  302. package/server/src/Models/PaymentMethod.php +99 -0
  303. package/server/src/Models/Product.php +315 -0
  304. package/server/src/Models/ProductAddon.php +128 -0
  305. package/server/src/Models/ProductAddonCategory.php +90 -0
  306. package/server/src/Models/ProductHour.php +59 -0
  307. package/server/src/Models/ProductStoreLocation.php +77 -0
  308. package/server/src/Models/ProductVariant.php +125 -0
  309. package/server/src/Models/ProductVariantOption.php +86 -0
  310. package/server/src/Models/Review.php +127 -0
  311. package/server/src/Models/Store.php +478 -0
  312. package/server/src/Models/StoreHour.php +59 -0
  313. package/server/src/Models/StoreLocation.php +126 -0
  314. package/server/src/Models/StorefrontModel.php +22 -0
  315. package/server/src/Models/Vote.php +84 -0
  316. package/server/src/Notifications/StorefrontOrderCanceled.php +196 -0
  317. package/server/src/Notifications/StorefrontOrderCompleted.php +201 -0
  318. package/server/src/Notifications/StorefrontOrderCreated.php +157 -0
  319. package/server/src/Notifications/StorefrontOrderDriverAssigned.php +200 -0
  320. package/server/src/Notifications/StorefrontOrderEnroute.php +199 -0
  321. package/server/src/Notifications/StorefrontOrderNearby.php +201 -0
  322. package/server/src/Notifications/StorefrontOrderPreparing.php +202 -0
  323. package/server/src/Notifications/StorefrontOrderReadyForPickup.php +202 -0
  324. package/server/src/Observers/NetworkObserver.php +40 -0
  325. package/server/src/Observers/ProductObserver.php +118 -0
  326. package/server/src/Providers/EventServiceProvider.php +23 -0
  327. package/server/src/Providers/StorefrontServiceProvider.php +103 -0
  328. package/server/src/Support/Metrics.php +193 -0
  329. package/server/src/Support/OrderConfig.php +13 -0
  330. package/server/src/Support/QPay.php +208 -0
  331. package/server/src/Support/Storefront.php +201 -0
  332. package/server/src/routes.php +180 -0
  333. package/server/tests/Feature.php +5 -0
@@ -0,0 +1,84 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\Storefront\Models;
4
+
5
+ use Fleetbase\Traits\HasUuid;
6
+ use Fleetbase\Traits\HasApiModelBehavior;
7
+ use Fleetbase\Traits\HasPublicid;
8
+
9
+ class Vote extends StorefrontModel
10
+ {
11
+ use HasUuid, HasPublicid, HasApiModelBehavior;
12
+
13
+ /**
14
+ * The type of public Id to generate
15
+ *
16
+ * @var string
17
+ */
18
+ protected $publicIdType = 'vote';
19
+
20
+ /**
21
+ * The database table used by the model.
22
+ *
23
+ * @var string
24
+ */
25
+ protected $table = 'votes';
26
+
27
+ /**
28
+ * These attributes that can be queried
29
+ *
30
+ * @var array
31
+ */
32
+ protected $searchableColumns = [];
33
+
34
+ /**
35
+ * The attributes that are mass assignable.
36
+ *
37
+ * @var array
38
+ */
39
+ protected $fillable = [
40
+ 'created_by_uuid',
41
+ 'customer_uuid',
42
+ 'subject_uuid',
43
+ 'subject_type',
44
+ 'type'
45
+ ];
46
+
47
+ /**
48
+ * The attributes that should be cast to native types.
49
+ *
50
+ * @var array
51
+ */
52
+ protected $casts = [];
53
+
54
+ /**
55
+ * Dynamic attributes that are appended to object
56
+ *
57
+ * @var array
58
+ */
59
+ protected $appends = [];
60
+
61
+ /**
62
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
63
+ */
64
+ public function createdBy()
65
+ {
66
+ return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(User::class);
67
+ }
68
+
69
+ /**
70
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
71
+ */
72
+ public function customer()
73
+ {
74
+ return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Contact::class);
75
+ }
76
+
77
+ /**
78
+ * @return \Illuminate\Database\Eloquent\Relations\MorphTo
79
+ */
80
+ public function subject()
81
+ {
82
+ return $this->morphTo(__FUNCTION__, 'subject_type', 'subject_uuid')->withoutGlobalScopes();
83
+ }
84
+ }
@@ -0,0 +1,196 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\Storefront\Notifications;
4
+
5
+ use Exception;
6
+ use Fleetbase\FleetOps\Models\Order;
7
+ use Fleetbase\Storefront\Models\NotificationChannel;
8
+ use Fleetbase\Storefront\Support\Storefront;
9
+ use Fleetbase\FleetOps\Support\Utils;
10
+ use Illuminate\Bus\Queueable;
11
+ use Illuminate\Notifications\Messages\MailMessage;
12
+ use Illuminate\Notifications\Notification;
13
+ use NotificationChannels\Fcm\FcmChannel;
14
+ use NotificationChannels\Fcm\FcmMessage;
15
+ use NotificationChannels\Apn\ApnChannel;
16
+ use NotificationChannels\Apn\ApnMessage;
17
+ use NotificationChannels\Fcm\Resources\AndroidConfig;
18
+ use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
19
+ use NotificationChannels\Fcm\Resources\AndroidNotification;
20
+ use NotificationChannels\Fcm\Resources\ApnsConfig;
21
+ use NotificationChannels\Fcm\Resources\ApnsFcmOptions;
22
+ use Pushok\Client as PushOkClient;
23
+ use Pushok\AuthProvider\Token as PuskOkToken;
24
+
25
+ class StorefrontOrderCanceled extends Notification
26
+ {
27
+ use Queueable;
28
+
29
+ /**
30
+ * The order instance this notification is for.
31
+ *
32
+ * @var \Fleetbase\FleetOps\Models\Order
33
+ */
34
+ public $order;
35
+
36
+ /**
37
+ * The order instance this notification is for.
38
+ *
39
+ * @var \Fleetbase\Storefront\Models\Store|\Fleetbase\Storefront\Models\Network
40
+ */
41
+ public $storefront;
42
+
43
+ /**
44
+ * Create a new notification instance.
45
+ *
46
+ * @return void
47
+ */
48
+ public function __construct(Order $order)
49
+ {
50
+ $this->order = $order->setRelations([]);
51
+ $this->storefront = Storefront::findAbout($this->order->getMeta('storefront_id'));
52
+ }
53
+
54
+ /**
55
+ * Get the notification's delivery channels.
56
+ *
57
+ * @param mixed $notifiable
58
+ * @return array
59
+ */
60
+ public function via($notifiable)
61
+ {
62
+ return ['mail', FcmChannel::class, ApnChannel::class];
63
+ }
64
+
65
+ /**
66
+ * Get the mail representation of the notification.
67
+ *
68
+ * @param mixed $notifiable
69
+ * @return \Illuminate\Notifications\Messages\MailMessage
70
+ */
71
+ public function toMail($notifiable)
72
+ {
73
+ $message = (new MailMessage)
74
+ ->subject('Your order from ' . $this->storefront->name . ' was canceled')
75
+ ->line('Your order from ' . $this->storefront->name . ' has been canceled, if your card has been charged you will be refunded.')
76
+ ->line('No further action is necessary.');
77
+
78
+ // $message->action('View Details', Utils::consoleUrl('', ['shift' => 'fleet-ops/orders/view/' . $this->order->public_id]));
79
+
80
+ return $message;
81
+ }
82
+
83
+ /**
84
+ * Get the firebase cloud message representation of the notification.
85
+ *
86
+ * @param mixed $notifiable
87
+ * @return array
88
+ */
89
+ public function toFcm($notifiable)
90
+ {
91
+ $notification = \NotificationChannels\Fcm\Resources\Notification::create()
92
+ ->setTitle('Your order from ' . $this->storefront->name . ' was canceled')
93
+ ->setBody('Your order from ' . $this->storefront->name . ' has been canceled, if your card has been charged you will be refunded.');
94
+
95
+ $message = FcmMessage::create()
96
+ ->setData(['order' => $this->order->uuid, 'id' => $this->order->public_id, 'type' => 'order_canceled'])
97
+ ->setNotification($notification)
98
+ ->setAndroid(
99
+ AndroidConfig::create()
100
+ ->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
101
+ ->setNotification(AndroidNotification::create()->setColor('#4391EA'))
102
+ )->setApns(
103
+ ApnsConfig::create()
104
+ ->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
105
+ );
106
+
107
+ return $message;
108
+ }
109
+
110
+ /**
111
+ * Get the apns message representation of the notification.
112
+ *
113
+ * @param mixed $notifiable
114
+ * @return array
115
+ */
116
+ public function toApn($notifiable)
117
+ {
118
+ $about = Storefront::findAbout($this->order->getMeta('storefront_id'));
119
+
120
+ if ($this->order->hasMeta('storefront_notification_channel')) {
121
+ $notificationChannel = NotificationChannel::where([
122
+ 'owner_uuid' => $about->uuid,
123
+ 'app_key' => $this->order->getMeta('storefront_notification_channel'),
124
+ 'scheme' => 'apn'
125
+ ])->first();
126
+ } else {
127
+ $notificationChannel = NotificationChannel::where([
128
+ 'owner_uuid' => $about->uuid,
129
+ 'scheme' => 'apn'
130
+ ])->first();
131
+ }
132
+
133
+ $config = (array) $notificationChannel->config;
134
+
135
+ try {
136
+ $channelClient = new PushOkClient(PuskOkToken::create($config));
137
+ } catch (Exception $e) {
138
+ app('sentry')->captureException($e);
139
+ return;
140
+ }
141
+
142
+ $message = ApnMessage::create()
143
+ ->badge(1)
144
+ ->title('Your order from ' . $this->storefront->name . ' was canceled')
145
+ ->body('Your order from ' . $this->storefront->name . ' has been canceled, if your card has been charged you will be refunded.')
146
+ ->custom('type', 'order_canceled')
147
+ ->custom('order', $this->order->uuid)
148
+ ->custom('id', $this->order->public_id)
149
+ ->action('view_order', ['id' => $this->order->public_id])
150
+ ->via($channelClient);
151
+
152
+ return $message;
153
+ }
154
+
155
+ public function fcmProject($notifiable, $message)
156
+ {
157
+ $about = Storefront::findAbout($this->order->getMeta('storefront_id'));
158
+
159
+ if ($this->order->hasMeta('storefront_notification_channel')) {
160
+ $notificationChannel = NotificationChannel::where([
161
+ 'owner_uuid' => $about->uuid,
162
+ 'app_key' => $this->order->getMeta('storefront_notification_channel'),
163
+ 'scheme' => 'fcm'
164
+ ])->first();
165
+ } else {
166
+ $notificationChannel = NotificationChannel::where([
167
+ 'owner_uuid' => $about->uuid,
168
+ 'scheme' => 'fcm'
169
+ ])->first();
170
+ }
171
+
172
+ if (!$notificationChannel) {
173
+ return 'app';
174
+ }
175
+
176
+ $this->configureFcm($notificationChannel);
177
+
178
+ return $notificationChannel->app_key;
179
+ }
180
+
181
+ public function configureFcm($notificationChannel)
182
+ {
183
+ $config = (array) $notificationChannel->config;
184
+ $fcmConfig = config('firebase.projects.app');
185
+
186
+ // set credentials
187
+ Utils::set($fcmConfig, 'credentials.file', $config['firebase_credentials_json']);
188
+
189
+ // set db url
190
+ Utils::set($fcmConfig, 'database.url', $config['firebase_database_url']);
191
+
192
+ config('firebase.projects.' . $notificationChannel->app_key, $fcmConfig);
193
+
194
+ return $fcmConfig;
195
+ }
196
+ }
@@ -0,0 +1,201 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\Storefront\Notifications;
4
+
5
+ use Exception;
6
+ use Fleetbase\FleetOps\Models\Order;
7
+ use Fleetbase\Storefront\Models\NotificationChannel;
8
+ use Fleetbase\Storefront\Support\Storefront;
9
+ use Fleetbase\FleetOps\Support\Utils;
10
+ use Illuminate\Bus\Queueable;
11
+ // use Illuminate\Contracts\Queue\ShouldQueue;
12
+ use Illuminate\Notifications\Messages\MailMessage;
13
+ use Illuminate\Notifications\Notification;
14
+ use NotificationChannels\Fcm\FcmChannel;
15
+ use NotificationChannels\Fcm\FcmMessage;
16
+ use NotificationChannels\Apn\ApnChannel;
17
+ use NotificationChannels\Apn\ApnMessage;
18
+ use NotificationChannels\Fcm\Resources\AndroidConfig;
19
+ use NotificationChannels\Fcm\Resources\AndroidFcmOptions;
20
+ use NotificationChannels\Fcm\Resources\AndroidNotification;
21
+ use NotificationChannels\Fcm\Resources\ApnsConfig;
22
+ use NotificationChannels\Fcm\Resources\ApnsFcmOptions;
23
+ use Pushok\Client as PushOkClient;
24
+ use Pushok\AuthProvider\Token as PuskOkToken;
25
+
26
+ class StorefrontOrderCompleted extends Notification
27
+ {
28
+ use Queueable;
29
+
30
+ public $storefront;
31
+ public Order $order;
32
+
33
+ /**
34
+ * Create a new notification instance.
35
+ *
36
+ * @return void
37
+ */
38
+ public function __construct(Order $order)
39
+ {
40
+ $this->order = $order->setRelations([]);
41
+ $this->storefront = Storefront::findAbout($this->order->getMeta('storefront_id'));
42
+ }
43
+
44
+ /**
45
+ * Get the notification's delivery channels.
46
+ *
47
+ * @param mixed $notifiable
48
+ * @return array
49
+ */
50
+ public function via($notifiable)
51
+ {
52
+ // $channels = ['mail'];
53
+ $channels = [];
54
+
55
+ if (!$this->storefront) {
56
+ return $channels;
57
+ }
58
+
59
+ $hasApnNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'apn'])->count();
60
+ $hasFcmNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'android'])->count();
61
+
62
+ if ($hasApnNotificationChannels) {
63
+ $channels[] = ApnChannel::class;
64
+ }
65
+ if ($hasFcmNotificationChannels) {
66
+ $channels[] = FcmChannel::class;
67
+ }
68
+
69
+ return $channels;
70
+ }
71
+
72
+ /**
73
+ * Get the mail representation of the notification.
74
+ *
75
+ * @param mixed $notifiable
76
+ * @return \Illuminate\Notifications\Messages\MailMessage
77
+ */
78
+ public function toMail($notifiable)
79
+ {
80
+ $message = (new MailMessage)
81
+ ->subject('Your order has been delivered')
82
+ ->line('Your order has been delivered, enjoy!');
83
+
84
+ // $message->action('View Details', Utils::consoleUrl('', ['shift' => 'fleet-ops/orders/view/' . $this->order->public_id]));
85
+
86
+ return $message;
87
+ }
88
+
89
+ /**
90
+ * Get the firebase cloud message representation of the notification.
91
+ *
92
+ * @param mixed $notifiable
93
+ * @return array
94
+ */
95
+ public function toFcm($notifiable)
96
+ {
97
+ $notification = \NotificationChannels\Fcm\Resources\Notification::create()
98
+ ->setTitle('Your order has been delivered')
99
+ ->setBody('Your order has been delivered, enjoy!');
100
+
101
+ $message = FcmMessage::create()
102
+ ->setData(['order' => $this->order->uuid, 'id' => $this->order->public_id, 'type' => 'order_completed'])
103
+ ->setNotification($notification)
104
+ ->setAndroid(
105
+ AndroidConfig::create()
106
+ ->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
107
+ ->setNotification(AndroidNotification::create()->setColor('#4391EA'))
108
+ )->setApns(
109
+ ApnsConfig::create()
110
+ ->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
111
+ );
112
+
113
+ return $message;
114
+ }
115
+
116
+ /**
117
+ * Get the apns message representation of the notification.
118
+ *
119
+ * @param mixed $notifiable
120
+ * @return array
121
+ */
122
+ public function toApn($notifiable)
123
+ {
124
+ $about = Storefront::findAbout($this->order->getMeta('storefront_id'));
125
+
126
+ if ($this->order->hasMeta('storefront_notification_channel')) {
127
+ $notificationChannel = NotificationChannel::where([
128
+ 'owner_uuid' => $about->uuid,
129
+ 'app_key' => $this->order->getMeta('storefront_notification_channel'),
130
+ 'scheme' => 'apn'
131
+ ])->first();
132
+ } else {
133
+ $notificationChannel = NotificationChannel::where([
134
+ 'owner_uuid' => $about->uuid,
135
+ 'scheme' => 'apn'
136
+ ])->first();
137
+ }
138
+
139
+ $config = (array) $notificationChannel->config;
140
+
141
+ try {
142
+ $channelClient = new PushOkClient(PuskOkToken::create($config));
143
+ } catch (Exception $e) {
144
+ app('sentry')->captureException($e);
145
+ return;
146
+ }
147
+
148
+ $message = ApnMessage::create()
149
+ ->badge(1)
150
+ ->title('Your order has been delivered')
151
+ ->body('Your order has been delivered, enjoy!')
152
+ ->custom('type', 'order_completed')
153
+ ->custom('order', $this->order->uuid)
154
+ ->custom('id', $this->order->public_id)
155
+ ->via($channelClient);
156
+
157
+ return $message;
158
+ }
159
+
160
+ public function fcmProject($notifiable, $message)
161
+ {
162
+ $about = Storefront::findAbout($this->order->getMeta('storefront_id'));
163
+
164
+ if ($this->order->hasMeta('storefront_notification_channel')) {
165
+ $notificationChannel = NotificationChannel::where([
166
+ 'owner_uuid' => $about->uuid,
167
+ 'app_key' => $this->order->getMeta('storefront_notification_channel'),
168
+ 'scheme' => 'fcm'
169
+ ])->first();
170
+ } else {
171
+ $notificationChannel = NotificationChannel::where([
172
+ 'owner_uuid' => $about->uuid,
173
+ 'scheme' => 'fcm'
174
+ ])->first();
175
+ }
176
+
177
+ if (!$notificationChannel) {
178
+ return 'app';
179
+ }
180
+
181
+ $this->configureFcm($notificationChannel);
182
+
183
+ return $notificationChannel->app_key;
184
+ }
185
+
186
+ public function configureFcm($notificationChannel)
187
+ {
188
+ $config = (array) $notificationChannel->config;
189
+ $fcmConfig = config('firebase.projects.app');
190
+
191
+ // set credentials
192
+ Utils::set($fcmConfig, 'credentials.file', $config['firebase_credentials_json']);
193
+
194
+ // set db url
195
+ Utils::set($fcmConfig, 'database.url', $config['firebase_database_url']);
196
+
197
+ config('firebase.projects.' . $notificationChannel->app_key, $fcmConfig);
198
+
199
+ return $fcmConfig;
200
+ }
201
+ }
@@ -0,0 +1,157 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\Storefront\Notifications;
4
+
5
+ use Illuminate\Bus\Queueable;
6
+ // use Illuminate\Contracts\Queue\ShouldQueue;
7
+ use Illuminate\Notifications\Messages\MailMessage;
8
+ use Illuminate\Notifications\Notification;
9
+ use NotificationChannels\Twilio\TwilioChannel;
10
+ use NotificationChannels\Twilio\TwilioSmsMessage;
11
+ use Fleetbase\FleetOps\Models\Order;
12
+ use Fleetbase\Storefront\Support\Storefront;
13
+ use Fleetbase\FleetOps\Support\Utils;
14
+
15
+ class StorefrontOrderCreated extends Notification
16
+ {
17
+ use Queueable;
18
+
19
+ // public ?Order $order;
20
+
21
+ /**
22
+ * Create a new notification instance.
23
+ *
24
+ * @return void
25
+ */
26
+ public function __construct(Order $order)
27
+ {
28
+ $storefrontId = $order->getMeta('storefront_id');
29
+
30
+ $this->order = $order;
31
+ $this->storefront = Storefront::findAbout($storefrontId);
32
+ }
33
+
34
+ /**
35
+ * Get the notification's delivery channels.
36
+ *
37
+ * @param mixed $notifiable
38
+ * @return array
39
+ */
40
+ public function via($notifiable)
41
+ {
42
+ return ['mail', TwilioChannel::class];
43
+ }
44
+
45
+ /**
46
+ * Get the twilio sms representation of the notification.
47
+ *
48
+ * @param mixed $notifiable
49
+ * @return \NotificationChannels\Twilio\TwilioSmsMessage;
50
+ */
51
+ public function toTwilio($notifiable)
52
+ {
53
+ $storeName = $this->storefront->name;
54
+ $isPickup = $this->order->getMeta('is_pickup');
55
+ $isDelivery = !$isPickup;
56
+ $method = $isPickup ? 'pickup' : 'delivery';
57
+ $items = $this->order->payload->entities->map(function ($entity) {
58
+ return $entity->name;
59
+ })->join(',');
60
+ $customerName = $this->order->customer->name;
61
+ $customerPhone = $this->order->customer->phone;
62
+ $deliveryAddress = $this->order->payload->dropoff->address;
63
+ $subtotal = $this->order->getMeta('subtotal');
64
+ $deliveryFee = $this->order->getMeta('delivery_fee');
65
+ $tip = $this->order->getMeta('tip');
66
+ $deliveryTip = $this->order->getMeta('delivery_tip');
67
+ $total = $this->order->getMeta('total');
68
+ $currency = $this->order->getMeta('currency');
69
+
70
+ $content = '🚨 ' . $storeName . ' has received new order!' . "\n\n" .
71
+ 'A new ' . $method . ' order was just created!' . "\n\n" .
72
+ 'Customer: ' . $customerName . ' (' . $customerPhone . ')' . "\n" .
73
+ 'Items: ' . $items . "\n";
74
+
75
+ if ($isDelivery) {
76
+ $content .= 'Address: ' . $deliveryAddress . "\n";
77
+ $content .= 'Delivery Fee: ' . Utils::moneyFormat($deliveryFee, $currency) . "\n";
78
+
79
+ if ($deliveryTip) {
80
+ $content .= 'Delivery Tip: ' . Utils::moneyFormat($deliveryTip, $currency) . "\n";
81
+ }
82
+ }
83
+
84
+ if ($tip) {
85
+ $content .= 'Tip: ' . Utils::moneyFormat($tip, $currency) . "\n";
86
+ }
87
+
88
+ $content .= 'Subtotal: ' . Utils::moneyFormat($subtotal, $currency) . "\n";
89
+ $content .= 'Total: ' . Utils::moneyFormat($total, $currency) . "\n";
90
+
91
+ return (new TwilioSmsMessage())->content($content);
92
+ }
93
+
94
+ /**
95
+ * Get the mail representation of the notification.
96
+ *
97
+ * @param mixed $notifiable
98
+ * @return \Illuminate\Notifications\Messages\MailMessage
99
+ */
100
+ public function toMail($notifiable)
101
+ {
102
+ $storeName = $this->storefront->name;
103
+ $isPickup = $this->order->getMeta('is_pickup');
104
+ $isDelivery = !$isPickup;
105
+ $method = $isPickup ? 'pickup' : 'delivery';
106
+ $items = $this->order->payload->entities->map(function ($entity) {
107
+ return $entity->name;
108
+ })->join(',');
109
+ $customerName = $this->order->customer->name;
110
+ $customerPhone = $this->order->customer->phone;
111
+ $deliveryAddress = $this->order->payload->dropoff->address;
112
+ $subtotal = $this->order->getMeta('subtotal');
113
+ $deliveryFee = $this->order->getMeta('delivery_fee');
114
+ $tip = $this->order->getMeta('tip');
115
+ $deliveryTip = $this->order->getMeta('delivery_tip');
116
+ $total = $this->order->getMeta('total');
117
+ $currency = $this->order->getMeta('currency');
118
+
119
+ $message = (new MailMessage)
120
+ ->subject('🚨 ' . $storeName . ' has received new order!')
121
+ ->greeting('Hello!')
122
+ ->line('A new ' . $method . ' order was just created!')
123
+ ->line('Customer: ' . $customerName . ' (' . $customerPhone . ')')
124
+ ->line('Items: ' . $items);
125
+
126
+ if ($isDelivery) {
127
+ $message->line('Address: ' . $deliveryAddress);
128
+ $message->line('Delivery Fee: ' . Utils::moneyFormat($deliveryFee, $currency));
129
+
130
+ if ($deliveryTip) {
131
+ $message->line('Delivery Tip: ' . Utils::moneyFormat($deliveryTip, $currency));
132
+ }
133
+ }
134
+
135
+ if ($tip) {
136
+ $message->line('Tip: ' . Utils::moneyFormat($tip, $currency));
137
+ }
138
+
139
+ $message->line('Subtotal: ' . Utils::moneyFormat($subtotal, $currency));
140
+ $message->line('Total: ' . Utils::moneyFormat($total, $currency));
141
+
142
+ return $message;
143
+ }
144
+
145
+ /**
146
+ * Get the array representation of the notification.
147
+ *
148
+ * @param mixed $notifiable
149
+ * @return array
150
+ */
151
+ public function toArray($notifiable)
152
+ {
153
+ return [
154
+ //
155
+ ];
156
+ }
157
+ }