@fleetbase/storefront-engine 0.4.6 → 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 +1 -1
- package/extension.json +1 -1
- package/package.json +1 -1
- package/server/config/storefront.php +1 -1
- package/server/src/Http/Controllers/v1/CheckoutController.php +2 -2
- package/server/src/Http/Controllers/v1/CustomerController.php +22 -16
- package/server/src/Support/QPay.php +76 -0
- package/server/src/Support/Storefront.php +14 -0
package/composer.json
CHANGED
package/extension.json
CHANGED
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@ return [
|
|
|
43
43
|
|--------------------------------------------------------------------------
|
|
44
44
|
*/
|
|
45
45
|
'throttle' => [
|
|
46
|
-
'max_attempts' => env('STOREFRONT_THROTTLE_REQUESTS_PER_MINUTE',
|
|
46
|
+
'max_attempts' => env('STOREFRONT_THROTTLE_REQUESTS_PER_MINUTE', 600),
|
|
47
47
|
'decay_minutes' => env('STOREFRONT_THROTTLE_DECAY_MINUTES', 1),
|
|
48
48
|
],
|
|
49
49
|
];
|
|
@@ -482,14 +482,14 @@ 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
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' => '
|
|
492
|
+
'classification_code' => '6511100',
|
|
493
493
|
'taxes' => [
|
|
494
494
|
[
|
|
495
495
|
'tax_code' => 'VAT',
|
|
@@ -139,23 +139,29 @@ class CustomerController extends Controller
|
|
|
139
139
|
$customer = new Contact($attributes);
|
|
140
140
|
$meta = ['identity' => $identity];
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -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;
|
|
@@ -319,4 +322,77 @@ class QPay
|
|
|
319
322
|
|
|
320
323
|
return $truncated;
|
|
321
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;
|
|
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
|
}
|