@fleetbase/storefront-engine 0.4.7 → 0.4.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 (42) hide show
  1. package/addon/components/storefront-order-summary.hbs +69 -68
  2. package/addon/components/storefront-order-summary.js +10 -1
  3. package/addon/controllers/base-controller.js +2 -22
  4. package/addon/controllers/networks/index/network.js +25 -0
  5. package/addon/controllers/promotions/push-notifications.js +64 -0
  6. package/addon/controllers/promotions.js +16 -0
  7. package/addon/engine.js +1 -31
  8. package/addon/extension.js +35 -0
  9. package/addon/routes/customers/index.js +0 -9
  10. package/addon/routes/networks/index/network/customers.js +0 -9
  11. package/addon/routes/networks/index.js +0 -9
  12. package/addon/routes/orders/index.js +0 -9
  13. package/addon/routes/products/index.js +2 -8
  14. package/addon/routes/promotions/push-notifications.js +19 -0
  15. package/addon/routes/promotions.js +16 -0
  16. package/addon/routes.js +3 -1
  17. package/addon/styles/storefront-engine.css +4 -0
  18. package/addon/templates/application.hbs +7 -0
  19. package/addon/templates/networks/index/network/index.hbs +30 -8
  20. package/addon/templates/networks/index/network.hbs +5 -26
  21. package/addon/templates/promotions/push-notifications.hbs +85 -0
  22. package/addon/templates/promotions.hbs +8 -0
  23. package/addon/templates/settings/index.hbs +19 -0
  24. package/app/controllers/promotions/push-notifications.js +1 -0
  25. package/app/controllers/promotions.js +1 -0
  26. package/app/routes/promotions/push-notifications.js +1 -0
  27. package/app/routes/promotions.js +1 -0
  28. package/app/templates/promotions/push-notifications.hbs +1 -0
  29. package/app/templates/promotions.hbs +1 -0
  30. package/composer.json +1 -1
  31. package/config/environment.js +1 -1
  32. package/extension.json +1 -1
  33. package/package.json +4 -4
  34. package/server/src/Http/Controllers/ActionController.php +61 -0
  35. package/server/src/Http/Controllers/v1/CheckoutController.php +25 -9
  36. package/server/src/Models/Cart.php +2 -1
  37. package/server/src/Models/Network.php +25 -0
  38. package/server/src/Models/Store.php +25 -0
  39. package/server/src/Notifications/PromotionalPushNotification.php +166 -0
  40. package/server/src/Support/QPay.php +475 -3
  41. package/server/src/routes.php +1 -0
  42. package/translations/en-us.yaml +28 -0
@@ -0,0 +1,166 @@
1
+ <?php
2
+
3
+ namespace Fleetbase\Storefront\Notifications;
4
+
5
+ use Fleetbase\Storefront\Models\Store;
6
+ use Fleetbase\Storefront\Support\PushNotification;
7
+ use Illuminate\Bus\Queueable;
8
+ use Illuminate\Notifications\Notification;
9
+ use NotificationChannels\Apn\ApnChannel;
10
+ use NotificationChannels\Fcm\FcmChannel;
11
+
12
+ class PromotionalPushNotification extends Notification
13
+ {
14
+ use Queueable;
15
+
16
+ /**
17
+ * The notification title.
18
+ */
19
+ public string $title;
20
+
21
+ /**
22
+ * The notification body.
23
+ */
24
+ public string $body;
25
+
26
+ /**
27
+ * The store instance.
28
+ */
29
+ public Store $store;
30
+
31
+ /**
32
+ * The time the notification was sent.
33
+ */
34
+ public string $sentAt;
35
+
36
+ /**
37
+ * The ID of the notification.
38
+ */
39
+ public string $notificationId;
40
+
41
+ /**
42
+ * Create a new notification instance.
43
+ *
44
+ * @return void
45
+ */
46
+ public function __construct(string $title, string $body, Store $store)
47
+ {
48
+ $this->title = $title;
49
+ $this->body = $body;
50
+ $this->store = $store;
51
+ $this->sentAt = now()->toDateTimeString();
52
+ $this->notificationId = uniqid('notification_');
53
+ }
54
+
55
+ /**
56
+ * Get the notification's delivery channels.
57
+ */
58
+ public function via($notifiable): array
59
+ {
60
+ $channels = [];
61
+
62
+ // Check if store has APN notification channel configured
63
+ $apnChannel = PushNotification::getNotificationChannel('apn', $this->store);
64
+ if ($apnChannel) {
65
+ $channels[] = ApnChannel::class;
66
+ }
67
+
68
+ // Check if store has FCM notification channel configured
69
+ $fcmChannel = PushNotification::getNotificationChannel('fcm', $this->store);
70
+ if ($fcmChannel) {
71
+ $channels[] = FcmChannel::class;
72
+ }
73
+
74
+ return $channels;
75
+ }
76
+
77
+ /**
78
+ * Get the APN representation of the notification.
79
+ */
80
+ public function toApn($notifiable)
81
+ {
82
+ $client = PushNotification::getApnClient($this->store);
83
+ if (!$client) {
84
+ return null;
85
+ }
86
+
87
+ return \NotificationChannels\Apn\ApnMessage::create()
88
+ ->badge(1)
89
+ ->title($this->title)
90
+ ->body($this->body)
91
+ ->custom('type', 'promotional')
92
+ ->custom('store', $this->store->uuid)
93
+ ->custom('store_id', $this->store->public_id)
94
+ ->via($client);
95
+ }
96
+
97
+ /**
98
+ * Get the FCM representation of the notification.
99
+ */
100
+ public function toFcm($notifiable)
101
+ {
102
+ $notificationChannel = PushNotification::getNotificationChannel('fcm', $this->store);
103
+ if (!$notificationChannel) {
104
+ return null;
105
+ }
106
+
107
+ // Configure FCM
108
+ PushNotification::configureFcm($notificationChannel);
109
+
110
+ // Get FCM Client
111
+ $container = \Illuminate\Container\Container::getInstance();
112
+ $projectManager = new \Kreait\Laravel\Firebase\FirebaseProjectManager($container);
113
+ $client = $projectManager->project($notificationChannel->app_key)->messaging();
114
+
115
+ // Create Notification
116
+ $notification = new \NotificationChannels\Fcm\Resources\Notification(
117
+ title: $this->title,
118
+ body: $this->body
119
+ );
120
+
121
+ return (new \NotificationChannels\Fcm\FcmMessage(notification: $notification))
122
+ ->data([
123
+ 'type' => 'promotional',
124
+ 'store' => $this->store->uuid,
125
+ 'store_id' => $this->store->public_id,
126
+ ])
127
+ ->custom([
128
+ 'android' => [
129
+ 'notification' => [
130
+ 'color' => '#4391EA',
131
+ 'sound' => 'default',
132
+ ],
133
+ 'fcm_options' => [
134
+ 'analytics_label' => 'promotional',
135
+ ],
136
+ ],
137
+ 'apns' => [
138
+ 'payload' => [
139
+ 'aps' => [
140
+ 'sound' => 'default',
141
+ ],
142
+ ],
143
+ 'fcm_options' => [
144
+ 'analytics_label' => 'promotional',
145
+ ],
146
+ ],
147
+ ])
148
+ ->usingClient($client);
149
+ }
150
+
151
+ /**
152
+ * Get the array representation of the notification.
153
+ */
154
+ public function toArray($notifiable): array
155
+ {
156
+ return [
157
+ 'title' => $this->title,
158
+ 'body' => $this->body,
159
+ 'store' => $this->store->uuid,
160
+ 'store_id' => $this->store->public_id,
161
+ 'type' => 'promotional',
162
+ 'sent_at' => $this->sentAt,
163
+ 'notification_id' => $this->notificationId,
164
+ ];
165
+ }
166
+ }