@fleetbase/storefront-engine 0.4.5 → 0.4.7

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/composer.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetbase/storefront-api",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "Headless Commerce & Marketplace Extension for Fleetbase",
5
5
  "keywords": [
6
6
  "fleetbase-extension",
package/extension.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "Storefront",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "Headless Commerce & Marketplace Extension for Fleetbase",
5
5
  "repository": "https://github.com/fleetbase/storefront",
6
6
  "license": "AGPL-3.0-or-later",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fleetbase/storefront-engine",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "Headless Commerce & Marketplace Extension for Fleetbase",
5
5
  "fleetbase": {
6
6
  "route": "storefront",
@@ -43,7 +43,7 @@ return [
43
43
  |--------------------------------------------------------------------------
44
44
  */
45
45
  'throttle' => [
46
- 'max_attempts' => env('STOREFRONT_THROTTLE_REQUESTS_PER_MINUTE', 500),
46
+ 'max_attempts' => env('STOREFRONT_THROTTLE_REQUESTS_PER_MINUTE', 600),
47
47
  'decay_minutes' => env('STOREFRONT_THROTTLE_DECAY_MINUTES', 1),
48
48
  ],
49
49
  ];
@@ -474,7 +474,7 @@ class CheckoutController extends Controller
474
474
  $invoiceAmount = $amount;
475
475
  $invoiceCode = $gateway->sandbox ? 'TEST_INVOICE' : $gateway->config?->invoice_id ?? null;
476
476
  $invoiceDescription = $about->name . ' cart checkout';
477
- $invoiceReceiverCode = $checkout->public_id;
477
+ $invoiceReceiverCode = 'CITIZEN';
478
478
  $senderInvoiceNo = $checkout->public_id;
479
479
  $districtCode = $gateway->config?->district_code ?? null;
480
480
  $invoiceReceiverData = Utils::filterArray([
@@ -482,18 +482,18 @@ class CheckoutController extends Controller
482
482
  'email' => $customer->email ?? null,
483
483
  'phone' => $customer->phone ?? null,
484
484
  ]);
485
- $lines = [];
485
+ $lines = QPay::createQpayInitialLines($cart, $serviceQuote, $checkoutOptions);
486
486
  foreach ($cart->items as $item) {
487
487
  $lines[] = [
488
488
  'line_description' => $item->name,
489
- 'line_quantity' => $item->quantity ?? 1,
489
+ 'line_quantity' => number_format($item->quantity ?? 1, 2, '.', ''),
490
490
  'line_unit_price' => number_format($item->price, 2, '.', ''),
491
491
  'note' => $checkout->public_id,
492
- 'classification_code' => '0111100',
492
+ 'classification_code' => '6511100',
493
493
  'taxes' => [
494
494
  [
495
- // 'tax_code' => 'VAT', // only works without this
496
- 'description' => 'НӨАТ',
495
+ 'tax_code' => 'VAT',
496
+ 'description' => 'VAT',
497
497
  'amount' => QPay::calculateTax($item->subtotal),
498
498
  'note' => $checkout->public_id,
499
499
  ],
@@ -139,23 +139,29 @@ class CustomerController extends Controller
139
139
  $customer = new Contact($attributes);
140
140
  $meta = ['identity' => $identity];
141
141
 
142
- if ($isEmail) {
143
- VerificationCode::generateEmailVerificationFor($customer, 'storefront_create_customer', [
144
- 'messageCallback' => function ($verification) use ($about) {
145
- return "Your {$about->name} verification code is {$verification->code}";
146
- },
147
- 'meta' => $meta,
148
- ]);
149
- } else {
150
- VerificationCode::generateSmsVerificationFor($customer, 'storefront_create_customer', [
151
- 'messageCallback' => function ($verification) use ($about) {
152
- return "Your {$about->name} verification code is {$verification->code}";
153
- },
154
- 'meta' => $meta,
155
- ]);
156
- }
142
+ try {
143
+ if ($isEmail) {
144
+ VerificationCode::generateEmailVerificationFor($customer, 'storefront_create_customer', [
145
+ 'messageCallback' => function ($verification) use ($about) {
146
+ return "Your {$about->name} verification code is {$verification->code}";
147
+ },
148
+ 'meta' => $meta,
149
+ ]);
150
+ } else {
151
+ VerificationCode::generateSmsVerificationFor($customer, 'storefront_create_customer', [
152
+ 'messageCallback' => function ($verification) use ($about) {
153
+ return "Your {$about->name} verification code is {$verification->code}";
154
+ },
155
+ 'meta' => $meta,
156
+ ]);
157
+ }
157
158
 
158
- return response()->json(['status' => 'ok']);
159
+ return response()->json(['status' => 'ok']);
160
+ } catch (\Exception $e) {
161
+ return response()->apiError(app()->hasDebugModeEnabled() ? $e->getMessage() : 'Error sending verification code.');
162
+ } catch (\Twilio\Exceptions\RestException $e) {
163
+ return response()->apiError($e->getMessage());
164
+ }
159
165
  }
160
166
 
161
167
  /**
@@ -157,8 +157,16 @@ class OrderController extends Controller
157
157
  return $ebarimt; // Return error response if creation failed
158
158
  }
159
159
 
160
+ // get ebarimt qr data
161
+ $qrData = data_get($ebarimt, 'ebarimt_qr_data');
162
+ if (!empty($qrData)) {
163
+ $order->updateMeta('ebarimt_qr_data', $qrData);
164
+ }
165
+
160
166
  // Store receipt in order metadata
161
- $order->updateMeta('ebarimt', $ebarimt);
167
+ if ($order->doesntHaveMeta('ebarimt')) {
168
+ $order->updateMeta('ebarimt', $ebarimt);
169
+ }
162
170
 
163
171
  return response()->json($ebarimt);
164
172
  }
@@ -83,7 +83,7 @@ class FoodTruck extends StorefrontModel
83
83
  */
84
84
  public function vehicle(): BelongsTo
85
85
  {
86
- return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Vehicle::class, 'vehicle_uuid', 'uuid');
86
+ return $this->setConnection(config('fleetbase.connection.db'))->belongsTo(Vehicle::class, 'vehicle_uuid', 'uuid')->withTrashed();
87
87
  }
88
88
 
89
89
  /**
@@ -2,7 +2,10 @@
2
2
 
3
3
  namespace Fleetbase\Storefront\Support;
4
4
 
5
+ use Fleetbase\FleetOps\Models\ServiceQuote;
6
+ use Fleetbase\Storefront\Models\Cart;
5
7
  use Fleetbase\Storefront\Models\Checkout;
8
+ use Fleetbase\Storefront\Support\Storefront;
6
9
  use Fleetbase\Support\Utils;
7
10
  use GuzzleHttp\Client;
8
11
  use Illuminate\Support\Str;
@@ -312,11 +315,84 @@ class QPay
312
315
  ];
313
316
  }
314
317
 
315
- public static function calculateTax($amount): string
318
+ public static function calculateTax($amount): float
316
319
  {
317
- $result = ((float) $amount / 1.1) * 0.10;
318
- $result = floor($result * 100) / 100;
320
+ $result = ((float) $amount / 1.1) * 0.10;
321
+ $truncated = floor($result * 10000) / 10000;
319
322
 
320
- return number_format($result, 2, '.', '');
323
+ return $truncated;
324
+ }
325
+
326
+ public static function createQpayInitialLines(Cart $cart, ?ServiceQuote $serviceQuote, $checkoutOptions): array
327
+ {
328
+ // Prepare dependencies
329
+ $checkoutOptions = (object) $checkoutOptions;
330
+ $subtotal = (int) $cart->subtotal;
331
+ $total = $subtotal;
332
+ $tip = $checkoutOptions->tip ?? false;
333
+ $deliveryTip = $checkoutOptions->delivery_tip ?? false;
334
+ $isPickup = $checkoutOptions->is_pickup ?? false;
335
+
336
+ // Initialize lines
337
+ $lines = [];
338
+
339
+ if ($tip) {
340
+ $tipAmount = Storefront::calculateTipAmount($tip, $subtotal);
341
+ $lines[] = [
342
+ 'line_description' => 'Tip',
343
+ 'line_quantity' => number_format(1, 2, '.', ''),
344
+ 'line_unit_price' => number_format($tipAmount, 2, '.', ''),
345
+ 'note' => 'Tip',
346
+ 'classification_code' => '6511100',
347
+ 'taxes' => [
348
+ [
349
+ 'tax_code' => 'VAT',
350
+ 'description' => 'VAT',
351
+ 'amount' => QPay::calculateTax($tipAmount),
352
+ 'note' => 'Tip',
353
+ ],
354
+ ],
355
+ ];
356
+ }
357
+
358
+ if ($deliveryTip && !$isPickup) {
359
+ $deliveryTipAmount = Storefront::calculateTipAmount($deliveryTip, $subtotal);
360
+ $lines[] = [
361
+ 'line_description' => 'Delivery Tip',
362
+ 'line_quantity' => number_format(1, 2, '.', ''),
363
+ 'line_unit_price' => number_format($deliveryTipAmount, 2, '.', ''),
364
+ 'note' => 'Delivery Tip',
365
+ 'classification_code' => '6511100',
366
+ 'taxes' => [
367
+ [
368
+ 'tax_code' => 'VAT',
369
+ 'description' => 'VAT',
370
+ 'amount' => QPay::calculateTax($deliveryTipAmount),
371
+ 'note' => 'Delivery Tip',
372
+ ],
373
+ ],
374
+ ];
375
+ }
376
+
377
+ if (!$isPickup) {
378
+ $serviceQuoteAmount = Utils::numbersOnly($serviceQuote->amount);
379
+ $lines[] = [
380
+ 'line_description' => 'Delivery Fee',
381
+ 'line_quantity' => number_format(1, 2, '.', ''),
382
+ 'line_unit_price' => number_format($serviceQuoteAmount, 2, '.', ''),
383
+ 'note' => 'Delivery Fee',
384
+ 'classification_code' => '6511100',
385
+ 'taxes' => [
386
+ [
387
+ 'tax_code' => 'VAT',
388
+ 'description' => 'VAT',
389
+ 'amount' => QPay::calculateTax($serviceQuoteAmount),
390
+ 'note' => 'Delivery Fee',
391
+ ],
392
+ ],
393
+ ];
394
+ }
395
+
396
+ return $lines;
321
397
  }
322
398
  }
@@ -21,6 +21,7 @@ use Illuminate\Support\Facades\DB;
21
21
  use Illuminate\Support\Facades\Log;
22
22
  use Illuminate\Support\Facades\Notification;
23
23
  use Illuminate\Support\Facades\Redis;
24
+ use Illuminate\Support\Facades\Schema;
24
25
  use Illuminate\Support\Str;
25
26
  use Laravel\Sanctum\PersonalAccessToken;
26
27
 
@@ -729,4 +730,17 @@ class Storefront
729
730
 
730
731
  return null;
731
732
  }
733
+
734
+ public static function calculateTipAmount($tip, $subtotal)
735
+ {
736
+ $tipAmount = 0;
737
+
738
+ if (is_string($tip) && Str::endsWith($tip, '%')) {
739
+ $tipAmount = Utils::calculatePercentage(Utils::numbersOnly($tip), $subtotal);
740
+ } else {
741
+ $tipAmount = Utils::numbersOnly($tip);
742
+ }
743
+
744
+ return $tipAmount;
745
+ }
732
746
  }