@fleetbase/storefront-engine 0.3.24 → 0.3.26
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.
- package/addon/adapters/catalog.js +1 -0
- package/addon/adapters/food-truck.js +1 -0
- package/addon/components/customer-panel/orders.hbs +7 -1
- package/addon/components/modals/assign-food-truck-catalogs.hbs +14 -0
- package/addon/components/modals/create-catalog.hbs +96 -0
- package/addon/components/modals/create-first-store.hbs +6 -1
- package/addon/components/modals/create-food-truck.hbs +69 -0
- package/addon/components/modals/manage-addons.js +1 -15
- package/addon/components/order-panel.hbs +2 -2
- package/addon/components/widget/customers.hbs +5 -5
- package/addon/components/widget/orders.hbs +7 -4
- package/addon/components/widget/orders.js +11 -1
- package/addon/controllers/catalogs/index.js +121 -0
- package/addon/controllers/food-trucks/index.js +100 -0
- package/addon/models/catalog-category.js +6 -0
- package/addon/models/catalog-hour.js +72 -0
- package/addon/models/catalog.js +45 -0
- package/addon/models/food-truck.js +47 -0
- package/addon/models/product.js +1 -0
- package/addon/routes/catalogs/index.js +22 -0
- package/addon/routes/catalogs.js +3 -0
- package/addon/routes/food-trucks/index.js +22 -0
- package/addon/routes/food-trucks.js +3 -0
- package/addon/routes.js +6 -0
- package/addon/serializers/catalog-category.js +15 -0
- package/addon/serializers/catalog.js +16 -0
- package/addon/serializers/food-truck.js +18 -0
- package/addon/serializers/product-variant.js +0 -1
- package/addon/styles/storefront-engine.css +15 -5
- package/addon/templates/application.hbs +14 -0
- package/addon/templates/catalogs/index.hbs +46 -0
- package/addon/templates/catalogs.hbs +1 -0
- package/addon/templates/customers/index.hbs +1 -1
- package/addon/templates/food-trucks/index.hbs +52 -0
- package/addon/templates/food-trucks.hbs +1 -0
- package/addon/templates/networks/index.hbs +14 -2
- package/addon/templates/products/index/category/new.hbs +10 -3
- package/addon/templates/products/index/index.hbs +1 -2
- package/addon/templates/products/index.hbs +16 -2
- package/app/adapters/catalog.js +1 -0
- package/app/adapters/food-truck.js +1 -0
- package/app/components/modals/assign-food-truck-catalogs.js +1 -0
- package/app/components/modals/create-catalog.js +1 -0
- package/app/components/modals/create-food-truck.js +1 -0
- package/app/controllers/catalogs/index.js +1 -0
- package/app/controllers/food-trucks/index.js +1 -0
- package/app/models/catalog-category.js +1 -0
- package/app/models/catalog-hour.js +1 -0
- package/app/models/catalog.js +1 -0
- package/app/models/food-truck.js +1 -0
- package/app/routes/catalogs/index.js +1 -0
- package/app/routes/catalogs.js +1 -0
- package/app/routes/food-trucks/index.js +1 -0
- package/app/routes/food-trucks.js +1 -0
- package/app/serializers/catalog-category.js +1 -0
- package/app/serializers/catalog.js +1 -0
- package/app/serializers/food-truck.js +1 -0
- package/app/templates/catalogs/index.js +1 -0
- package/app/templates/catalogs.js +1 -0
- package/app/templates/food-trucks/index.js +1 -0
- package/app/templates/food-trucks.js +1 -0
- package/composer.json +1 -1
- package/extension.json +1 -1
- package/package.json +1 -1
- package/server/migrations/2025_01_30_042853_create_catalogs_table.php +41 -0
- package/server/migrations/2025_01_30_044728_create_catalog_category_products_table.php +35 -0
- package/server/migrations/2025_01_30_050611_create_food_trucks_table.php +72 -0
- package/server/migrations/2025_01_30_052157_create_catalog_subjects_table.php +54 -0
- package/server/migrations/2025_01_30_052402_create_catalog_hours_table.php +39 -0
- package/server/src/Auth/Schemas/Storefront.php +16 -0
- package/server/src/Console/Commands/PurgeExpiredCarts.php +13 -3
- package/server/src/Http/Controllers/CatalogCategoryController.php +13 -0
- package/server/src/Http/Controllers/CatalogController.php +13 -0
- package/server/src/Http/Controllers/CatalogHourController.php +13 -0
- package/server/src/Http/Controllers/FoodTruckController.php +13 -0
- package/server/src/Http/Controllers/v1/CatalogController.php +38 -0
- package/server/src/Http/Controllers/v1/CategoryController.php +1 -1
- package/server/src/Http/Controllers/v1/CheckoutController.php +4 -0
- package/server/src/Http/Controllers/v1/CustomerController.php +5 -1
- package/server/src/Http/Controllers/v1/FoodTruckController.php +39 -0
- package/server/src/Http/Controllers/v1/ProductController.php +1 -1
- package/server/src/Http/Controllers/v1/ReviewController.php +8 -6
- package/server/src/Http/Controllers/v1/StoreController.php +10 -0
- package/server/src/Http/Filter/FoodTruckFilter.php +37 -0
- package/server/src/Http/Resources/Catalog.php +34 -0
- package/server/src/Http/Resources/CatalogCategory.php +38 -0
- package/server/src/Http/Resources/CatalogProduct.php +55 -0
- package/server/src/Http/Resources/FoodTruck.php +42 -0
- package/server/src/Http/Resources/Product.php +1 -0
- package/server/src/Http/Resources/ReviewCustomer.php +2 -0
- package/server/src/Models/AddonCategory.php +12 -0
- package/server/src/Models/Cart.php +6 -0
- package/server/src/Models/Catalog.php +213 -0
- package/server/src/Models/CatalogCategory.php +118 -0
- package/server/src/Models/CatalogHour.php +46 -0
- package/server/src/Models/CatalogProduct.php +25 -0
- package/server/src/Models/CatalogSubject.php +70 -0
- package/server/src/Models/FoodTruck.php +182 -0
- package/server/src/Models/Product.php +29 -2
- package/server/src/Models/Review.php +2 -2
- package/server/src/Notifications/StorefrontOrderCanceled.php +80 -121
- package/server/src/Notifications/StorefrontOrderCompleted.php +86 -131
- package/server/src/Notifications/StorefrontOrderCreated.php +29 -15
- package/server/src/Notifications/StorefrontOrderDriverAssigned.php +96 -130
- package/server/src/Notifications/StorefrontOrderEnroute.php +89 -129
- package/server/src/Notifications/StorefrontOrderNearby.php +103 -132
- package/server/src/Notifications/StorefrontOrderPreparing.php +84 -134
- package/server/src/Notifications/StorefrontOrderReadyForPickup.php +89 -134
- package/server/src/Observers/CatalogObserver.php +40 -0
- package/server/src/Observers/FoodTruckObserver.php +24 -0
- package/server/src/Observers/ProductObserver.php +23 -41
- package/server/src/Providers/StorefrontServiceProvider.php +5 -3
- package/server/src/Support/PushNotification.php +127 -0
- package/server/src/routes.php +10 -0
- package/translations/en-us.yaml +5 -0
|
@@ -3,32 +3,55 @@
|
|
|
3
3
|
namespace Fleetbase\Storefront\Notifications;
|
|
4
4
|
|
|
5
5
|
use Fleetbase\FleetOps\Models\Order;
|
|
6
|
-
use Fleetbase\
|
|
7
|
-
use Fleetbase\Storefront\Models\
|
|
6
|
+
use Fleetbase\Storefront\Models\Network;
|
|
7
|
+
use Fleetbase\Storefront\Models\Store;
|
|
8
|
+
use Fleetbase\Storefront\Support\PushNotification;
|
|
8
9
|
use Fleetbase\Storefront\Support\Storefront;
|
|
9
10
|
use Illuminate\Bus\Queueable;
|
|
10
|
-
// use Illuminate\Contracts\Queue\ShouldQueue;
|
|
11
11
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
12
12
|
use Illuminate\Notifications\Notification;
|
|
13
13
|
use NotificationChannels\Apn\ApnChannel;
|
|
14
|
-
use NotificationChannels\Apn\ApnMessage;
|
|
15
14
|
use NotificationChannels\Fcm\FcmChannel;
|
|
16
|
-
use NotificationChannels\Fcm\FcmMessage;
|
|
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\AuthProvider\Token as PuskOkToken;
|
|
23
|
-
use Pushok\Client as PushOkClient;
|
|
24
15
|
|
|
25
16
|
class StorefrontOrderCompleted extends Notification
|
|
26
17
|
{
|
|
27
18
|
use Queueable;
|
|
28
19
|
|
|
29
|
-
|
|
20
|
+
/**
|
|
21
|
+
* The order instance this notification is for.
|
|
22
|
+
*/
|
|
30
23
|
public Order $order;
|
|
31
24
|
|
|
25
|
+
/**
|
|
26
|
+
* The order instance this notification is for.
|
|
27
|
+
*/
|
|
28
|
+
public Store|Network $storefront;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The time the notification was sent.
|
|
32
|
+
*/
|
|
33
|
+
public string $sentAt;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The ID of the notification.
|
|
37
|
+
*/
|
|
38
|
+
public string $notificationId;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The notification subject.
|
|
42
|
+
*/
|
|
43
|
+
public string $subject;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The notification body.
|
|
47
|
+
*/
|
|
48
|
+
public string $body;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The notification order status.
|
|
52
|
+
*/
|
|
53
|
+
public string $status;
|
|
54
|
+
|
|
32
55
|
/**
|
|
33
56
|
* Create a new notification instance.
|
|
34
57
|
*
|
|
@@ -36,35 +59,22 @@ class StorefrontOrderCompleted extends Notification
|
|
|
36
59
|
*/
|
|
37
60
|
public function __construct(Order $order)
|
|
38
61
|
{
|
|
39
|
-
$this->order
|
|
40
|
-
$this->storefront
|
|
62
|
+
$this->order = $order;
|
|
63
|
+
$this->storefront = Storefront::findAbout($order->getMeta('storefront_id'));
|
|
64
|
+
$this->sentAt = now()->toDateTimeString();
|
|
65
|
+
$this->notificationId = uniqid('notification_');
|
|
66
|
+
|
|
67
|
+
$this->subject = 'Your order from ' . $this->storefront->name . ' has been delivered';
|
|
68
|
+
$this->body = 'Your order from ' . $this->storefront->name . ' has been delivered, enjoy!';
|
|
69
|
+
$this->status = 'order_completed';
|
|
41
70
|
}
|
|
42
71
|
|
|
43
72
|
/**
|
|
44
73
|
* Get the notification's delivery channels.
|
|
45
|
-
*
|
|
46
|
-
* @return array
|
|
47
74
|
*/
|
|
48
|
-
public function via($notifiable)
|
|
75
|
+
public function via($notifiable): array
|
|
49
76
|
{
|
|
50
|
-
|
|
51
|
-
$channels = [];
|
|
52
|
-
|
|
53
|
-
if (!$this->storefront) {
|
|
54
|
-
return $channels;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
$hasApnNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'apn'])->count();
|
|
58
|
-
$hasFcmNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'android'])->count();
|
|
59
|
-
|
|
60
|
-
if ($hasApnNotificationChannels) {
|
|
61
|
-
$channels[] = ApnChannel::class;
|
|
62
|
-
}
|
|
63
|
-
if ($hasFcmNotificationChannels) {
|
|
64
|
-
$channels[] = FcmChannel::class;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return $channels;
|
|
77
|
+
return ['mail', 'database', FcmChannel::class, ApnChannel::class];
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
/**
|
|
@@ -75,8 +85,8 @@ class StorefrontOrderCompleted extends Notification
|
|
|
75
85
|
public function toMail($notifiable)
|
|
76
86
|
{
|
|
77
87
|
$message = (new MailMessage())
|
|
78
|
-
->subject(
|
|
79
|
-
->line(
|
|
88
|
+
->subject($this->subject)
|
|
89
|
+
->line($this->body);
|
|
80
90
|
|
|
81
91
|
// $message->action('View Details', Utils::consoleUrl('', ['shift' => 'fleet-ops/orders/view/' . $this->order->public_id]));
|
|
82
92
|
|
|
@@ -86,112 +96,57 @@ class StorefrontOrderCompleted extends Notification
|
|
|
86
96
|
/**
|
|
87
97
|
* Get the firebase cloud message representation of the notification.
|
|
88
98
|
*
|
|
89
|
-
* @return
|
|
99
|
+
* @return \NotificationChannels\Fcm\FcmMessage
|
|
90
100
|
*/
|
|
91
101
|
public function toFcm($notifiable)
|
|
92
102
|
{
|
|
93
|
-
|
|
94
|
-
->
|
|
95
|
-
->
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
->setAndroid(
|
|
101
|
-
AndroidConfig::create()
|
|
102
|
-
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
|
|
103
|
-
->setNotification(AndroidNotification::create()->setColor('#4391EA'))
|
|
104
|
-
)->setApns(
|
|
105
|
-
ApnsConfig::create()
|
|
106
|
-
->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
return $message;
|
|
103
|
+
return PushNotification::createFcmMessage(
|
|
104
|
+
$this->order,
|
|
105
|
+
$this->subject,
|
|
106
|
+
$this->body,
|
|
107
|
+
$this->status,
|
|
108
|
+
$notifiable
|
|
109
|
+
);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
113
|
* Get the apns message representation of the notification.
|
|
114
114
|
*
|
|
115
|
-
* @return
|
|
115
|
+
* @return \NotificationChannels\Apn\ApnMessage
|
|
116
116
|
*/
|
|
117
117
|
public function toApn($notifiable)
|
|
118
118
|
{
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
$
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
])->first();
|
|
127
|
-
} else {
|
|
128
|
-
$notificationChannel = NotificationChannel::where([
|
|
129
|
-
'owner_uuid' => $about->uuid,
|
|
130
|
-
'scheme' => 'apn',
|
|
131
|
-
])->first();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
$config = (array) $notificationChannel->config;
|
|
135
|
-
|
|
136
|
-
try {
|
|
137
|
-
$channelClient = new PushOkClient(PuskOkToken::create($config));
|
|
138
|
-
} catch (\Exception $e) {
|
|
139
|
-
app('sentry')->captureException($e);
|
|
140
|
-
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
$message = ApnMessage::create()
|
|
145
|
-
->badge(1)
|
|
146
|
-
->title('Your order has been delivered')
|
|
147
|
-
->body('Your order has been delivered, enjoy!')
|
|
148
|
-
->custom('type', 'order_completed')
|
|
149
|
-
->custom('order', $this->order->uuid)
|
|
150
|
-
->custom('id', $this->order->public_id)
|
|
151
|
-
->via($channelClient);
|
|
152
|
-
|
|
153
|
-
return $message;
|
|
119
|
+
return PushNotification::createApnMessage(
|
|
120
|
+
$this->order,
|
|
121
|
+
$this->subject,
|
|
122
|
+
$this->body,
|
|
123
|
+
$this->status,
|
|
124
|
+
$notifiable
|
|
125
|
+
);
|
|
154
126
|
}
|
|
155
127
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if ($this->order->hasMeta('storefront_notification_channel')) {
|
|
161
|
-
$notificationChannel = NotificationChannel::where([
|
|
162
|
-
'owner_uuid' => $about->uuid,
|
|
163
|
-
'app_key' => $this->order->getMeta('storefront_notification_channel'),
|
|
164
|
-
'scheme' => 'fcm',
|
|
165
|
-
])->first();
|
|
166
|
-
} else {
|
|
167
|
-
$notificationChannel = NotificationChannel::where([
|
|
168
|
-
'owner_uuid' => $about->uuid,
|
|
169
|
-
'scheme' => 'fcm',
|
|
170
|
-
])->first();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (!$notificationChannel) {
|
|
174
|
-
return 'app';
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
$this->configureFcm($notificationChannel);
|
|
178
|
-
|
|
179
|
-
return $notificationChannel->app_key;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
public function configureFcm($notificationChannel)
|
|
128
|
+
/**
|
|
129
|
+
* Get the array representation of the notification.
|
|
130
|
+
*/
|
|
131
|
+
public function toArray($notifiable): array
|
|
183
132
|
{
|
|
184
|
-
$
|
|
185
|
-
$
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
133
|
+
$this->order->loadMissing(['customer', 'company']);
|
|
134
|
+
$customer = $this->order->customer;
|
|
135
|
+
$company = $this->order->company;
|
|
136
|
+
|
|
137
|
+
return [
|
|
138
|
+
'notifiable' => $notifiable->public_id,
|
|
139
|
+
'notification_id' => $this->notificationId,
|
|
140
|
+
'sent_at' => $this->sentAt,
|
|
141
|
+
'subject' => $this->subject,
|
|
142
|
+
'message' => $this->status,
|
|
143
|
+
'storefront' => $this->storefront->name,
|
|
144
|
+
'storefront_id' => $this->storefront->public_id,
|
|
145
|
+
'id' => $customer->public_id,
|
|
146
|
+
'email' => $customer->email,
|
|
147
|
+
'phone' => $customer->phone,
|
|
148
|
+
'companyId' => $company->public_id,
|
|
149
|
+
'company' => $company->name,
|
|
150
|
+
];
|
|
196
151
|
}
|
|
197
152
|
}
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
namespace Fleetbase\Storefront\Notifications;
|
|
4
4
|
|
|
5
5
|
use Fleetbase\FleetOps\Models\Order;
|
|
6
|
-
|
|
7
|
-
use Fleetbase\
|
|
6
|
+
use Fleetbase\Storefront\Models\Network;
|
|
7
|
+
use Fleetbase\Storefront\Models\Store;
|
|
8
8
|
use Fleetbase\Storefront\Support\Storefront;
|
|
9
|
+
use Fleetbase\Support\Utils;
|
|
9
10
|
use Illuminate\Bus\Queueable;
|
|
10
11
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
11
12
|
use Illuminate\Notifications\Notification;
|
|
@@ -16,7 +17,25 @@ class StorefrontOrderCreated extends Notification
|
|
|
16
17
|
{
|
|
17
18
|
use Queueable;
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
/**
|
|
21
|
+
* The order instance this notification is for.
|
|
22
|
+
*/
|
|
23
|
+
public Order $order;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The order instance this notification is for.
|
|
27
|
+
*/
|
|
28
|
+
public Store|Network $storefront;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The time the notification was sent.
|
|
32
|
+
*/
|
|
33
|
+
public string $sentAt;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The ID of the notification.
|
|
37
|
+
*/
|
|
38
|
+
public string $notificationId;
|
|
20
39
|
|
|
21
40
|
/**
|
|
22
41
|
* Create a new notification instance.
|
|
@@ -25,18 +44,16 @@ class StorefrontOrderCreated extends Notification
|
|
|
25
44
|
*/
|
|
26
45
|
public function __construct(Order $order)
|
|
27
46
|
{
|
|
28
|
-
$
|
|
29
|
-
|
|
30
|
-
$this->
|
|
31
|
-
$this->
|
|
47
|
+
$this->order = $order;
|
|
48
|
+
$this->storefront = Storefront::findAbout($order->getMeta('storefront_id'));
|
|
49
|
+
$this->sentAt = now()->toDateTimeString();
|
|
50
|
+
$this->notificationId = uniqid('notification_');
|
|
32
51
|
}
|
|
33
52
|
|
|
34
53
|
/**
|
|
35
54
|
* Get the notification's delivery channels.
|
|
36
|
-
*
|
|
37
|
-
* @return array
|
|
38
55
|
*/
|
|
39
|
-
public function via($notifiable)
|
|
56
|
+
public function via($notifiable): array
|
|
40
57
|
{
|
|
41
58
|
return ['mail', TwilioChannel::class];
|
|
42
59
|
}
|
|
@@ -141,12 +158,9 @@ class StorefrontOrderCreated extends Notification
|
|
|
141
158
|
|
|
142
159
|
/**
|
|
143
160
|
* Get the array representation of the notification.
|
|
144
|
-
*
|
|
145
|
-
* @return array
|
|
146
161
|
*/
|
|
147
|
-
public function toArray($notifiable)
|
|
162
|
+
public function toArray($notifiable): array
|
|
148
163
|
{
|
|
149
|
-
return [
|
|
150
|
-
];
|
|
164
|
+
return [...$this->order->toArray()];
|
|
151
165
|
}
|
|
152
166
|
}
|
|
@@ -2,31 +2,62 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\Storefront\Notifications;
|
|
4
4
|
|
|
5
|
+
use Fleetbase\FleetOps\Models\Driver;
|
|
5
6
|
use Fleetbase\FleetOps\Models\Order;
|
|
6
|
-
use Fleetbase\
|
|
7
|
-
use Fleetbase\Storefront\Models\
|
|
7
|
+
use Fleetbase\Storefront\Models\Network;
|
|
8
|
+
use Fleetbase\Storefront\Models\Store;
|
|
9
|
+
use Fleetbase\Storefront\Support\PushNotification;
|
|
8
10
|
use Fleetbase\Storefront\Support\Storefront;
|
|
9
|
-
// use Fleetbase\FleetOps\Support\Utils;
|
|
10
11
|
use Illuminate\Bus\Queueable;
|
|
11
|
-
// use Illuminate\Contracts\Queue\ShouldQueue;
|
|
12
12
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
13
13
|
use Illuminate\Notifications\Notification;
|
|
14
14
|
use NotificationChannels\Apn\ApnChannel;
|
|
15
|
-
use NotificationChannels\Apn\ApnMessage;
|
|
16
15
|
use NotificationChannels\Fcm\FcmChannel;
|
|
17
|
-
use NotificationChannels\Fcm\FcmMessage;
|
|
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\AuthProvider\Token as PuskOkToken;
|
|
24
|
-
use Pushok\Client as PushOkClient;
|
|
25
16
|
|
|
26
17
|
class StorefrontOrderDriverAssigned extends Notification
|
|
27
18
|
{
|
|
28
19
|
use Queueable;
|
|
29
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The order instance this notification is for.
|
|
23
|
+
*/
|
|
24
|
+
public Order $order;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The driver assigned to the order.
|
|
28
|
+
*/
|
|
29
|
+
public Driver $driver;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The order instance this notification is for.
|
|
33
|
+
*/
|
|
34
|
+
public Store|Network $storefront;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The time the notification was sent.
|
|
38
|
+
*/
|
|
39
|
+
public string $sentAt;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The ID of the notification.
|
|
43
|
+
*/
|
|
44
|
+
public string $notificationId;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The notification subject.
|
|
48
|
+
*/
|
|
49
|
+
public string $subject;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The notification body.
|
|
53
|
+
*/
|
|
54
|
+
public string $body;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The notification order status.
|
|
58
|
+
*/
|
|
59
|
+
public string $status;
|
|
60
|
+
|
|
30
61
|
/**
|
|
31
62
|
* Create a new notification instance.
|
|
32
63
|
*
|
|
@@ -34,9 +65,15 @@ class StorefrontOrderDriverAssigned extends Notification
|
|
|
34
65
|
*/
|
|
35
66
|
public function __construct(Order $order)
|
|
36
67
|
{
|
|
37
|
-
$this->order
|
|
38
|
-
$this->
|
|
39
|
-
$this->
|
|
68
|
+
$this->order = $order;
|
|
69
|
+
$this->storefront = Storefront::findAbout($order->getMeta('storefront_id'));
|
|
70
|
+
$this->driver = $order->driverAssigned;
|
|
71
|
+
$this->sentAt = now()->toDateTimeString();
|
|
72
|
+
$this->notificationId = uniqid('notification_');
|
|
73
|
+
|
|
74
|
+
$this->subject = 'Your driver is ' . $this->driver->name;
|
|
75
|
+
$this->body = 'A driver has been assigned to your order from ' . $this->storefront->name . ', they are currently en-route for pickup';
|
|
76
|
+
$this->status = 'order_driver_assigned';
|
|
40
77
|
}
|
|
41
78
|
|
|
42
79
|
/**
|
|
@@ -46,24 +83,7 @@ class StorefrontOrderDriverAssigned extends Notification
|
|
|
46
83
|
*/
|
|
47
84
|
public function via($notifiable)
|
|
48
85
|
{
|
|
49
|
-
|
|
50
|
-
$channels = [];
|
|
51
|
-
|
|
52
|
-
if (!$this->storefront) {
|
|
53
|
-
return $channels;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
$hasApnNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'apn'])->count();
|
|
57
|
-
$hasFcmNotificationChannels = NotificationChannel::where(['owner_uuid' => $this->storefront->uuid, 'scheme' => 'android'])->count();
|
|
58
|
-
|
|
59
|
-
if ($hasApnNotificationChannels) {
|
|
60
|
-
$channels[] = ApnChannel::class;
|
|
61
|
-
}
|
|
62
|
-
if ($hasFcmNotificationChannels) {
|
|
63
|
-
$channels[] = FcmChannel::class;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return $channels;
|
|
86
|
+
return ['mail', 'database', FcmChannel::class, ApnChannel::class];
|
|
67
87
|
}
|
|
68
88
|
|
|
69
89
|
/**
|
|
@@ -74,8 +94,8 @@ class StorefrontOrderDriverAssigned extends Notification
|
|
|
74
94
|
public function toMail($notifiable)
|
|
75
95
|
{
|
|
76
96
|
$message = (new MailMessage())
|
|
77
|
-
->subject(
|
|
78
|
-
->line(
|
|
97
|
+
->subject($this->subject)
|
|
98
|
+
->line($this->body);
|
|
79
99
|
|
|
80
100
|
// $message->action('View Details', Utils::consoleUrl('', ['shift' => 'fleet-ops/orders/view/' . $this->order->public_id]));
|
|
81
101
|
|
|
@@ -85,111 +105,57 @@ class StorefrontOrderDriverAssigned extends Notification
|
|
|
85
105
|
/**
|
|
86
106
|
* Get the firebase cloud message representation of the notification.
|
|
87
107
|
*
|
|
88
|
-
* @return
|
|
108
|
+
* @return \NotificationChannels\Fcm\FcmMessage
|
|
89
109
|
*/
|
|
90
110
|
public function toFcm($notifiable)
|
|
91
111
|
{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
->
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
->setAndroid(
|
|
100
|
-
AndroidConfig::create()
|
|
101
|
-
->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics'))
|
|
102
|
-
->setNotification(AndroidNotification::create()->setColor('#4391EA'))
|
|
103
|
-
)->setApns(
|
|
104
|
-
ApnsConfig::create()
|
|
105
|
-
->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
return $message;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public function fcmProject($notifiable, $message)
|
|
112
|
-
{
|
|
113
|
-
$about = Storefront::findAbout($this->order->getMeta('storefront_id'));
|
|
114
|
-
|
|
115
|
-
if ($this->order->hasMeta('storefront_notification_channel')) {
|
|
116
|
-
$notificationChannel = NotificationChannel::where([
|
|
117
|
-
'owner_uuid' => $about->uuid,
|
|
118
|
-
'app_key' => $this->order->getMeta('storefront_notification_channel'),
|
|
119
|
-
'scheme' => 'fcm',
|
|
120
|
-
])->first();
|
|
121
|
-
} else {
|
|
122
|
-
$notificationChannel = NotificationChannel::where([
|
|
123
|
-
'owner_uuid' => $about->uuid,
|
|
124
|
-
'scheme' => 'fcm',
|
|
125
|
-
])->first();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (!$notificationChannel) {
|
|
129
|
-
return 'app';
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
$this->configureFcm($notificationChannel);
|
|
133
|
-
|
|
134
|
-
return $notificationChannel->app_key;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public function configureFcm($notificationChannel)
|
|
138
|
-
{
|
|
139
|
-
$config = (array) $notificationChannel->config;
|
|
140
|
-
$fcmConfig = config('firebase.projects.app');
|
|
141
|
-
|
|
142
|
-
// set credentials
|
|
143
|
-
Utils::set($fcmConfig, 'credentials.file', $config['firebase_credentials_json']);
|
|
144
|
-
|
|
145
|
-
// set db url
|
|
146
|
-
Utils::set($fcmConfig, 'database.url', $config['firebase_database_url']);
|
|
147
|
-
|
|
148
|
-
config('firebase.projects.' . $notificationChannel->app_key, $fcmConfig);
|
|
149
|
-
|
|
150
|
-
return $fcmConfig;
|
|
112
|
+
return PushNotification::createFcmMessage(
|
|
113
|
+
$this->order,
|
|
114
|
+
$this->subject,
|
|
115
|
+
$this->body,
|
|
116
|
+
$this->status,
|
|
117
|
+
$notifiable
|
|
118
|
+
);
|
|
151
119
|
}
|
|
152
120
|
|
|
153
121
|
/**
|
|
154
122
|
* Get the apns message representation of the notification.
|
|
155
123
|
*
|
|
156
|
-
* @return
|
|
124
|
+
* @return \NotificationChannels\Apn\ApnMessage
|
|
157
125
|
*/
|
|
158
126
|
public function toApn($notifiable)
|
|
159
127
|
{
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
$
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
} else {
|
|
169
|
-
$notificationChannel = NotificationChannel::where([
|
|
170
|
-
'owner_uuid' => $about->uuid,
|
|
171
|
-
'scheme' => 'apn',
|
|
172
|
-
])->first();
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
$config = (array) $notificationChannel->config;
|
|
176
|
-
|
|
177
|
-
try {
|
|
178
|
-
$channelClient = new PushOkClient(PuskOkToken::create($config));
|
|
179
|
-
} catch (\Exception $e) {
|
|
180
|
-
// stop silently
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
$message = ApnMessage::create()
|
|
185
|
-
->badge(1)
|
|
186
|
-
->title('Your driver is ' . $this->driver->name)
|
|
187
|
-
->body('A driver has been assigned to your order, they are en-route for pickup')
|
|
188
|
-
->custom('type', 'order_driver_assigned')
|
|
189
|
-
->custom('order', $this->order->uuid)
|
|
190
|
-
->custom('id', $this->order->public_id)
|
|
191
|
-
->via($channelClient);
|
|
128
|
+
return PushNotification::createApnMessage(
|
|
129
|
+
$this->order,
|
|
130
|
+
$this->subject,
|
|
131
|
+
$this->body,
|
|
132
|
+
$this->status,
|
|
133
|
+
$notifiable
|
|
134
|
+
);
|
|
135
|
+
}
|
|
192
136
|
|
|
193
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Get the array representation of the notification.
|
|
139
|
+
*/
|
|
140
|
+
public function toArray($notifiable): array
|
|
141
|
+
{
|
|
142
|
+
$this->order->loadMissing(['customer', 'company']);
|
|
143
|
+
$customer = $this->order->customer;
|
|
144
|
+
$company = $this->order->company;
|
|
145
|
+
|
|
146
|
+
return [
|
|
147
|
+
'notifiable' => $notifiable->public_id,
|
|
148
|
+
'notification_id' => $this->notificationId,
|
|
149
|
+
'sent_at' => $this->sentAt,
|
|
150
|
+
'subject' => $this->subject,
|
|
151
|
+
'message' => $this->status,
|
|
152
|
+
'storefront' => $this->storefront->name,
|
|
153
|
+
'storefront_id' => $this->storefront->public_id,
|
|
154
|
+
'id' => $customer->public_id,
|
|
155
|
+
'email' => $customer->email,
|
|
156
|
+
'phone' => $customer->phone,
|
|
157
|
+
'companyId' => $company->public_id,
|
|
158
|
+
'company' => $company->name,
|
|
159
|
+
];
|
|
194
160
|
}
|
|
195
161
|
}
|