Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fleetbase/storefront-api",
"version": "0.4.6",
"version": "0.4.7",
"description": "Headless Commerce & Marketplace Extension for Fleetbase",
"keywords": [
"fleetbase-extension",
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Storefront",
"version": "0.4.6",
"version": "0.4.7",
"description": "Headless Commerce & Marketplace Extension for Fleetbase",
"repository": "https://github.com/fleetbase/storefront",
"license": "AGPL-3.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/storefront-engine",
"version": "0.4.6",
"version": "0.4.7",
"description": "Headless Commerce & Marketplace Extension for Fleetbase",
"fleetbase": {
"route": "storefront",
Expand Down
2 changes: 1 addition & 1 deletion server/config/storefront.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
|--------------------------------------------------------------------------
*/
'throttle' => [
'max_attempts' => env('STOREFRONT_THROTTLE_REQUESTS_PER_MINUTE', 500),
'max_attempts' => env('STOREFRONT_THROTTLE_REQUESTS_PER_MINUTE', 600),
'decay_minutes' => env('STOREFRONT_THROTTLE_DECAY_MINUTES', 1),
],
];
4 changes: 2 additions & 2 deletions server/src/Http/Controllers/v1/CheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,14 +482,14 @@ public static function initializeQPayCheckout(Contact $customer, Gateway $gatewa
'email' => $customer->email ?? null,
'phone' => $customer->phone ?? null,
]);
$lines = [];
$lines = QPay::createQpayInitialLines($cart, $serviceQuote, $checkoutOptions);
foreach ($cart->items as $item) {
$lines[] = [
'line_description' => $item->name,
'line_quantity' => number_format($item->quantity ?? 1, 2, '.', ''),
'line_unit_price' => number_format($item->price, 2, '.', ''),
'note' => $checkout->public_id,
'classification_code' => '0111100',
'classification_code' => '6511100',
'taxes' => [
[
'tax_code' => 'VAT',
Expand Down
38 changes: 22 additions & 16 deletions server/src/Http/Controllers/v1/CustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,29 @@ public function requestCustomerCreationCode(VerifyCreateCustomerRequest $request
$customer = new Contact($attributes);
$meta = ['identity' => $identity];

if ($isEmail) {
VerificationCode::generateEmailVerificationFor($customer, 'storefront_create_customer', [
'messageCallback' => function ($verification) use ($about) {
return "Your {$about->name} verification code is {$verification->code}";
},
'meta' => $meta,
]);
} else {
VerificationCode::generateSmsVerificationFor($customer, 'storefront_create_customer', [
'messageCallback' => function ($verification) use ($about) {
return "Your {$about->name} verification code is {$verification->code}";
},
'meta' => $meta,
]);
}
try {
if ($isEmail) {
VerificationCode::generateEmailVerificationFor($customer, 'storefront_create_customer', [
'messageCallback' => function ($verification) use ($about) {
return "Your {$about->name} verification code is {$verification->code}";
},
'meta' => $meta,
]);
} else {
VerificationCode::generateSmsVerificationFor($customer, 'storefront_create_customer', [
'messageCallback' => function ($verification) use ($about) {
return "Your {$about->name} verification code is {$verification->code}";
},
'meta' => $meta,
]);
}

return response()->json(['status' => 'ok']);
return response()->json(['status' => 'ok']);
} catch (\Exception $e) {
return response()->apiError(app()->hasDebugModeEnabled() ? $e->getMessage() : 'Error sending verification code.');
} catch (\Twilio\Exceptions\RestException $e) {
return response()->apiError($e->getMessage());
}
}

/**
Expand Down
76 changes: 76 additions & 0 deletions server/src/Support/QPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Fleetbase\Storefront\Support;

use Fleetbase\FleetOps\Models\ServiceQuote;
use Fleetbase\Storefront\Models\Cart;
use Fleetbase\Storefront\Models\Checkout;
use Fleetbase\Storefront\Support\Storefront;
use Fleetbase\Support\Utils;
use GuzzleHttp\Client;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -319,4 +322,77 @@ public static function calculateTax($amount): float

return $truncated;
}

public static function createQpayInitialLines(Cart $cart, ?ServiceQuote $serviceQuote, $checkoutOptions): array
{
// Prepare dependencies
$checkoutOptions = (object) $checkoutOptions;
$subtotal = (int) $cart->subtotal;
$total = $subtotal;
$tip = $checkoutOptions->tip ?? false;
$deliveryTip = $checkoutOptions->delivery_tip ?? false;
$isPickup = $checkoutOptions->is_pickup ?? false;

// Initialize lines
$lines = [];

if ($tip) {
$tipAmount = Storefront::calculateTipAmount($tip, $subtotal);
$lines[] = [
'line_description' => 'Tip',
'line_quantity' => number_format(1, 2, '.', ''),
'line_unit_price' => number_format($tipAmount, 2, '.', ''),
'note' => 'Tip',
'classification_code' => '6511100',
'taxes' => [
[
'tax_code' => 'VAT',
'description' => 'VAT',
'amount' => QPay::calculateTax($tipAmount),
'note' => 'Tip',
],
],
];
}

if ($deliveryTip && !$isPickup) {
$deliveryTipAmount = Storefront::calculateTipAmount($deliveryTip, $subtotal);
$lines[] = [
'line_description' => 'Delivery Tip',
'line_quantity' => number_format(1, 2, '.', ''),
'line_unit_price' => number_format($deliveryTipAmount, 2, '.', ''),
'note' => 'Delivery Tip',
'classification_code' => '6511100',
'taxes' => [
[
'tax_code' => 'VAT',
'description' => 'VAT',
'amount' => QPay::calculateTax($deliveryTipAmount),
'note' => 'Delivery Tip',
],
],
];
}

if (!$isPickup) {
$serviceQuoteAmount = Utils::numbersOnly($serviceQuote->amount);
$lines[] = [
'line_description' => 'Delivery Fee',
'line_quantity' => number_format(1, 2, '.', ''),
'line_unit_price' => number_format($serviceQuoteAmount, 2, '.', ''),
'note' => 'Delivery Fee',
'classification_code' => '6511100',
'taxes' => [
[
'tax_code' => 'VAT',
'description' => 'VAT',
'amount' => QPay::calculateTax($serviceQuoteAmount),
'note' => 'Delivery Fee',
],
],
];
}

return $lines;
}
}
14 changes: 14 additions & 0 deletions server/src/Support/Storefront.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
use Laravel\Sanctum\PersonalAccessToken;

Expand Down Expand Up @@ -729,4 +730,17 @@ protected static function resolveSubjectToModel(Store|Network|string|null $subje

return null;
}

public static function calculateTipAmount($tip, $subtotal)
{
$tipAmount = 0;

if (is_string($tip) && Str::endsWith($tip, '%')) {
$tipAmount = Utils::calculatePercentage(Utils::numbersOnly($tip), $subtotal);
} else {
$tipAmount = Utils::numbersOnly($tip);
}

return $tipAmount;
}
}
Loading