@fleetbase/storefront-engine 0.2.5 → 0.2.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/addon/controllers/products/index/category/new.js +5 -9
- package/addon/models/product-addon-category.js +10 -1
- package/addon/models/product-variant.js +0 -2
- package/addon/models/product.js +35 -2
- package/addon/serializers/product.js +16 -0
- package/addon/templates/products/index/category/new.hbs +2 -2
- package/composer.json +3 -3
- package/extension.json +1 -1
- package/package.json +132 -132
- package/server/src/Auth/Schemas/Storefront.php +31 -39
- package/server/src/Console/Commands/NotifyStorefrontOrderNearby.php +9 -11
- package/server/src/Expansions/ContactFilterExpansion.php +1 -1
- package/server/src/Expansions/EntityExpansion.php +12 -12
- package/server/src/Expansions/OrderFilterExpansion.php +1 -1
- package/server/src/Expansions/VendorFilterExpansion.php +1 -1
- package/server/src/Http/Controllers/ActionController.php +9 -11
- package/server/src/Http/Controllers/AddonCategoryController.php +1 -1
- package/server/src/Http/Controllers/CustomerController.php +1 -1
- package/server/src/Http/Controllers/GatewayController.php +1 -1
- package/server/src/Http/Controllers/MetricsController.php +17 -17
- package/server/src/Http/Controllers/NetworkController.php +16 -26
- package/server/src/Http/Controllers/NotificationChannelController.php +1 -1
- package/server/src/Http/Controllers/OrderController.php +18 -22
- package/server/src/Http/Controllers/ProductAddonCategoryController.php +1 -2
- package/server/src/Http/Controllers/ProductAddonController.php +1 -2
- package/server/src/Http/Controllers/ProductController.php +89 -44
- package/server/src/Http/Controllers/ProductHourController.php +1 -1
- package/server/src/Http/Controllers/ProductVariantController.php +1 -1
- package/server/src/Http/Controllers/ProductVariantOptionController.php +1 -1
- package/server/src/Http/Controllers/ReviewController.php +1 -1
- package/server/src/Http/Controllers/StoreController.php +1 -2
- package/server/src/Http/Controllers/StoreHourController.php +1 -1
- package/server/src/Http/Controllers/StoreLocationController.php +1 -1
- package/server/src/Http/Controllers/StorefrontController.php +0 -2
- package/server/src/Http/Controllers/VoteController.php +1 -1
- package/server/src/Http/Controllers/v1/CartController.php +16 -26
- package/server/src/Http/Controllers/v1/CategoryController.php +3 -4
- package/server/src/Http/Controllers/v1/CheckoutController.php +283 -286
- package/server/src/Http/Controllers/v1/CustomerController.php +54 -67
- package/server/src/Http/Controllers/v1/GatewayControllerController.php +0 -2
- package/server/src/Http/Controllers/v1/NetworkController.php +26 -23
- package/server/src/Http/Controllers/v1/PaymentMethodController.php +0 -2
- package/server/src/Http/Controllers/v1/ProductController.php +1 -4
- package/server/src/Http/Controllers/v1/ReviewController.php +31 -35
- package/server/src/Http/Controllers/v1/ServiceQuoteController.php +57 -53
- package/server/src/Http/Controllers/v1/StoreController.php +8 -16
- package/server/src/Http/Filter/AddonCategoryFilter.php +1 -1
- package/server/src/Http/Filter/OrderFilter.php +2 -2
- package/server/src/Http/Middleware/SetStorefrontSession.php +9 -20
- package/server/src/Http/Requests/AddStoreToNetworkCategory.php +3 -3
- package/server/src/Http/Requests/CreateCustomerRequest.php +5 -7
- package/server/src/Http/Requests/CreateReviewRequest.php +4 -5
- package/server/src/Http/Requests/GetServiceQuoteFromCart.php +2 -2
- package/server/src/Http/Requests/InitializeCheckoutRequest.php +5 -5
- package/server/src/Http/Requests/NetworkActionRequest.php +2 -2
- package/server/src/Http/Requests/VerifyCreateCustomerRequest.php +2 -2
- package/server/src/Http/Resources/Cart.php +19 -18
- package/server/src/Http/Resources/Category.php +12 -11
- package/server/src/Http/Resources/Customer.php +15 -14
- package/server/src/Http/Resources/Gateway.php +12 -11
- package/server/src/Http/Resources/Media.php +9 -8
- package/server/src/Http/Resources/Network.php +32 -31
- package/server/src/Http/Resources/Product.php +88 -85
- package/server/src/Http/Resources/Review.php +14 -13
- package/server/src/Http/Resources/ReviewCustomer.php +12 -11
- package/server/src/Http/Resources/Store.php +38 -36
- package/server/src/Http/Resources/StoreHour.php +9 -8
- package/server/src/Http/Resources/StoreLocation.php +9 -8
- package/server/src/Imports/ProductsImport.php +0 -2
- package/server/src/Jobs/DownloadProductImageUrl.php +7 -4
- package/server/src/Listeners/HandleOrderCompleted.php +2 -1
- package/server/src/Listeners/HandleOrderDispatched.php +2 -1
- package/server/src/Listeners/HandleOrderDriverAssigned.php +2 -1
- package/server/src/Listeners/HandleOrderStarted.php +4 -3
- package/server/src/Mail/StorefrontNetworkInvite.php +7 -6
- package/server/src/Models/AddonCategory.php +2 -4
- package/server/src/Models/Cart.php +117 -124
- package/server/src/Models/Checkout.php +14 -12
- package/server/src/Models/Customer.php +9 -9
- package/server/src/Models/Gateway.php +22 -22
- package/server/src/Models/Network.php +41 -52
- package/server/src/Models/NetworkStore.php +6 -5
- package/server/src/Models/NotificationChannel.php +11 -9
- package/server/src/Models/PaymentMethod.php +9 -7
- package/server/src/Models/Product.php +152 -30
- package/server/src/Models/ProductAddon.php +14 -11
- package/server/src/Models/ProductAddonCategory.php +9 -8
- package/server/src/Models/ProductHour.php +6 -5
- package/server/src/Models/ProductStoreLocation.php +7 -5
- package/server/src/Models/ProductVariant.php +15 -11
- package/server/src/Models/ProductVariantOption.php +12 -9
- package/server/src/Models/Review.php +9 -7
- package/server/src/Models/Store.php +68 -84
- package/server/src/Models/StoreHour.php +6 -5
- package/server/src/Models/StoreLocation.php +12 -8
- package/server/src/Models/StorefrontModel.php +1 -1
- package/server/src/Models/Vote.php +8 -6
- package/server/src/Notifications/StorefrontOrderCanceled.php +15 -19
- package/server/src/Notifications/StorefrontOrderCompleted.php +15 -19
- package/server/src/Notifications/StorefrontOrderCreated.php +31 -36
- package/server/src/Notifications/StorefrontOrderDriverAssigned.php +15 -20
- package/server/src/Notifications/StorefrontOrderEnroute.php +14 -19
- package/server/src/Notifications/StorefrontOrderNearby.php +16 -21
- package/server/src/Notifications/StorefrontOrderPreparing.php +15 -18
- package/server/src/Notifications/StorefrontOrderReadyForPickup.php +15 -18
- package/server/src/Observers/NetworkObserver.php +2 -3
- package/server/src/Observers/ProductObserver.php +17 -33
- package/server/src/Providers/EventServiceProvider.php +15 -4
- package/server/src/Providers/StorefrontServiceProvider.php +8 -10
- package/server/src/Support/Metrics.php +12 -12
- package/server/src/Support/OrderConfig.php +3 -2
- package/server/src/Support/QPay.php +22 -20
- package/server/src/Support/Storefront.php +18 -17
- package/server/src/routes.php +1 -1
|
@@ -2,18 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Fleetbase\Storefront\Http\Controllers\v1;
|
|
4
4
|
|
|
5
|
-
use Fleetbase\Http\Controllers\Controller;
|
|
6
|
-
use Fleetbase\Storefront\Http\Requests\CaptureOrderRequest;
|
|
7
|
-
use Fleetbase\Storefront\Http\Requests\InitializeCheckoutRequest;
|
|
8
|
-
use Fleetbase\Storefront\Notifications\StorefrontOrderPreparing;
|
|
9
|
-
use Fleetbase\Storefront\Models\Cart;
|
|
10
|
-
use Fleetbase\Storefront\Models\Checkout;
|
|
11
|
-
use Fleetbase\Storefront\Models\Gateway;
|
|
12
|
-
use Fleetbase\Storefront\Models\Product;
|
|
13
|
-
use Fleetbase\Storefront\Models\StoreLocation;
|
|
14
|
-
use Fleetbase\Storefront\Models\Store;
|
|
15
|
-
use Fleetbase\Storefront\Support\QPay;
|
|
16
|
-
use Fleetbase\Storefront\Support\Storefront;
|
|
17
5
|
use Fleetbase\FleetOps\Http\Resources\v1\Order as OrderResource;
|
|
18
6
|
use Fleetbase\FleetOps\Models\Contact;
|
|
19
7
|
use Fleetbase\FleetOps\Models\Entity;
|
|
@@ -22,8 +10,20 @@ use Fleetbase\FleetOps\Models\Payload;
|
|
|
22
10
|
use Fleetbase\FleetOps\Models\Place;
|
|
23
11
|
use Fleetbase\FleetOps\Models\ServiceQuote;
|
|
24
12
|
use Fleetbase\FleetOps\Support\Utils;
|
|
13
|
+
use Fleetbase\Http\Controllers\Controller;
|
|
25
14
|
use Fleetbase\Models\Transaction;
|
|
26
15
|
use Fleetbase\Models\TransactionItem;
|
|
16
|
+
use Fleetbase\Storefront\Http\Requests\CaptureOrderRequest;
|
|
17
|
+
use Fleetbase\Storefront\Http\Requests\InitializeCheckoutRequest;
|
|
18
|
+
use Fleetbase\Storefront\Models\Cart;
|
|
19
|
+
use Fleetbase\Storefront\Models\Checkout;
|
|
20
|
+
use Fleetbase\Storefront\Models\Gateway;
|
|
21
|
+
use Fleetbase\Storefront\Models\Product;
|
|
22
|
+
use Fleetbase\Storefront\Models\Store;
|
|
23
|
+
use Fleetbase\Storefront\Models\StoreLocation;
|
|
24
|
+
use Fleetbase\Storefront\Notifications\StorefrontOrderPreparing;
|
|
25
|
+
use Fleetbase\Storefront\Support\QPay;
|
|
26
|
+
use Fleetbase\Storefront\Support\Storefront;
|
|
27
27
|
use Illuminate\Http\Request;
|
|
28
28
|
use Illuminate\Support\Arr;
|
|
29
29
|
use Illuminate\Support\Str;
|
|
@@ -33,27 +33,27 @@ class CheckoutController extends Controller
|
|
|
33
33
|
{
|
|
34
34
|
public function beforeCheckout(InitializeCheckoutRequest $request)
|
|
35
35
|
{
|
|
36
|
-
$gatewayCode
|
|
37
|
-
$customerId
|
|
38
|
-
$cartId
|
|
39
|
-
$serviceQuoteId
|
|
36
|
+
$gatewayCode = $request->input('gateway');
|
|
37
|
+
$customerId = $request->input('customer');
|
|
38
|
+
$cartId = $request->input('cart');
|
|
39
|
+
$serviceQuoteId = $request->or(['serviceQuote', 'service_quote']);
|
|
40
40
|
$isCashOnDelivery = $request->input('cash') || $gatewayCode === 'cash';
|
|
41
|
-
$isPickup
|
|
42
|
-
$tip
|
|
43
|
-
$deliveryTip
|
|
41
|
+
$isPickup = $request->input('pickup', false);
|
|
42
|
+
$tip = $request->input('tip', false);
|
|
43
|
+
$deliveryTip = $request->or(['delivery_tip', 'deliveryTip'], false);
|
|
44
44
|
|
|
45
45
|
// create checkout options
|
|
46
46
|
$checkoutOptions = Utils::createObject([
|
|
47
|
-
'is_pickup'
|
|
48
|
-
'is_cod'
|
|
49
|
-
'tip'
|
|
50
|
-
'delivery_tip' => $deliveryTip
|
|
47
|
+
'is_pickup' => $isPickup,
|
|
48
|
+
'is_cod' => $isCashOnDelivery,
|
|
49
|
+
'tip' => $tip,
|
|
50
|
+
'delivery_tip' => $deliveryTip,
|
|
51
51
|
]);
|
|
52
52
|
|
|
53
53
|
// find and validate cart session
|
|
54
|
-
$cart
|
|
55
|
-
$gateway
|
|
56
|
-
$customer
|
|
54
|
+
$cart = Cart::retrieve($cartId);
|
|
55
|
+
$gateway = Storefront::findGateway($gatewayCode);
|
|
56
|
+
$customer = Contact::findFromCustomerId($customerId);
|
|
57
57
|
$serviceQuote = ServiceQuote::select(['amount', 'meta', 'uuid', 'public_id'])->where('public_id', $serviceQuoteId)->first();
|
|
58
58
|
|
|
59
59
|
// handle cash orders
|
|
@@ -84,7 +84,7 @@ class CheckoutController extends Controller
|
|
|
84
84
|
$isPickup = $checkoutOptions->is_pickup;
|
|
85
85
|
|
|
86
86
|
// get amount/subtotal
|
|
87
|
-
$amount
|
|
87
|
+
$amount = static::calculateCheckoutAmount($cart, $serviceQuote, $checkoutOptions);
|
|
88
88
|
$currency = $cart->currency ?? session('storefront_currency');
|
|
89
89
|
|
|
90
90
|
// get store id if applicable
|
|
@@ -106,24 +106,24 @@ class CheckoutController extends Controller
|
|
|
106
106
|
|
|
107
107
|
// create checkout token
|
|
108
108
|
$checkout = Checkout::create([
|
|
109
|
-
'company_uuid'
|
|
110
|
-
'store_uuid'
|
|
111
|
-
'network_uuid'
|
|
112
|
-
'cart_uuid'
|
|
113
|
-
'gateway_uuid'
|
|
109
|
+
'company_uuid' => session('company'),
|
|
110
|
+
'store_uuid' => $storeId,
|
|
111
|
+
'network_uuid' => session('storefront_network'),
|
|
112
|
+
'cart_uuid' => $cart->uuid,
|
|
113
|
+
'gateway_uuid' => $gateway->uuid ?? null,
|
|
114
114
|
'service_quote_uuid' => $serviceQuote->uuid,
|
|
115
|
-
'owner_uuid'
|
|
116
|
-
'owner_type'
|
|
117
|
-
'amount'
|
|
118
|
-
'currency'
|
|
119
|
-
'is_cod'
|
|
120
|
-
'is_pickup'
|
|
121
|
-
'options'
|
|
122
|
-
'cart_state'
|
|
115
|
+
'owner_uuid' => $customer->uuid,
|
|
116
|
+
'owner_type' => 'contact',
|
|
117
|
+
'amount' => $amount,
|
|
118
|
+
'currency' => $currency,
|
|
119
|
+
'is_cod' => true,
|
|
120
|
+
'is_pickup' => $isPickup,
|
|
121
|
+
'options' => $checkoutOptions,
|
|
122
|
+
'cart_state' => $cart->toArray(),
|
|
123
123
|
]);
|
|
124
124
|
|
|
125
125
|
return response()->json([
|
|
126
|
-
'token' => $checkout->token
|
|
126
|
+
'token' => $checkout->token,
|
|
127
127
|
]);
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -133,7 +133,7 @@ class CheckoutController extends Controller
|
|
|
133
133
|
$isPickup = $checkoutOptions->is_pickup;
|
|
134
134
|
|
|
135
135
|
// get amount/subtotal
|
|
136
|
-
$amount
|
|
136
|
+
$amount = static::calculateCheckoutAmount($cart, $serviceQuote, $checkoutOptions);
|
|
137
137
|
$currency = $cart->currency ?? session('storefront_currency');
|
|
138
138
|
|
|
139
139
|
// check for secret key first
|
|
@@ -173,33 +173,33 @@ class CheckoutController extends Controller
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
$paymentIntent = \Stripe\PaymentIntent::create([
|
|
176
|
-
'amount'
|
|
176
|
+
'amount' => $amount,
|
|
177
177
|
'currency' => $currency,
|
|
178
|
-
'customer' => $customer->getMeta('stripe_id')
|
|
178
|
+
'customer' => $customer->getMeta('stripe_id'),
|
|
179
179
|
]);
|
|
180
180
|
|
|
181
181
|
// create checkout token
|
|
182
182
|
$checkout = Checkout::create([
|
|
183
|
-
'company_uuid'
|
|
184
|
-
'store_uuid'
|
|
185
|
-
'network_uuid'
|
|
186
|
-
'cart_uuid'
|
|
187
|
-
'gateway_uuid'
|
|
183
|
+
'company_uuid' => session('company'),
|
|
184
|
+
'store_uuid' => session('storefront_store'),
|
|
185
|
+
'network_uuid' => session('storefront_network'),
|
|
186
|
+
'cart_uuid' => $cart->uuid,
|
|
187
|
+
'gateway_uuid' => $gateway->uuid,
|
|
188
188
|
'service_quote_uuid' => $serviceQuote->uuid,
|
|
189
|
-
'owner_uuid'
|
|
190
|
-
'owner_type'
|
|
191
|
-
'amount'
|
|
192
|
-
'currency'
|
|
193
|
-
'is_pickup'
|
|
194
|
-
'options'
|
|
195
|
-
'cart_state'
|
|
189
|
+
'owner_uuid' => $customer->uuid,
|
|
190
|
+
'owner_type' => 'contact',
|
|
191
|
+
'amount' => $amount,
|
|
192
|
+
'currency' => $currency,
|
|
193
|
+
'is_pickup' => $isPickup,
|
|
194
|
+
'options' => $checkoutOptions,
|
|
195
|
+
'cart_state' => $cart->toArray(),
|
|
196
196
|
]);
|
|
197
197
|
|
|
198
198
|
return response()->json([
|
|
199
199
|
'paymentIntent' => $paymentIntent->client_secret,
|
|
200
|
-
'ephemeralKey'
|
|
201
|
-
'customerId'
|
|
202
|
-
'token'
|
|
200
|
+
'ephemeralKey' => $ephemeralKey->secret,
|
|
201
|
+
'customerId' => $customer->getMeta('stripe_id'),
|
|
202
|
+
'token' => $checkout->token,
|
|
203
203
|
]);
|
|
204
204
|
}
|
|
205
205
|
|
|
@@ -212,7 +212,7 @@ class CheckoutController extends Controller
|
|
|
212
212
|
$isPickup = $checkoutOptions->is_pickup;
|
|
213
213
|
|
|
214
214
|
// get amount/subtotal
|
|
215
|
-
$amount
|
|
215
|
+
$amount = static::calculateCheckoutAmount($cart, $serviceQuote, $checkoutOptions);
|
|
216
216
|
$currency = $cart->currency ?? session('storefront_currency');
|
|
217
217
|
|
|
218
218
|
// check for secret key first
|
|
@@ -231,41 +231,41 @@ class CheckoutController extends Controller
|
|
|
231
231
|
$qpay = $qpay->setAuthToken();
|
|
232
232
|
|
|
233
233
|
// Create invoice description
|
|
234
|
-
$invoiceAmount
|
|
235
|
-
$invoiceCode
|
|
236
|
-
$invoiceDescription
|
|
234
|
+
$invoiceAmount = round($amount / 100);
|
|
235
|
+
$invoiceCode = $gateway->sandbox ? 'TEST_INVOICE' : $gateway->config->invoice_id;
|
|
236
|
+
$invoiceDescription = $about->name . ' cart checkout';
|
|
237
237
|
$invoiceReceiverCode = $gateway->public_id;
|
|
238
|
-
$senderInvoiceNo
|
|
238
|
+
$senderInvoiceNo = $cart->id;
|
|
239
239
|
|
|
240
240
|
// Create qpay invoice
|
|
241
241
|
$invoice = $qpay->createSimpleInvoice($invoiceAmount, $invoiceCode, $invoiceDescription, $invoiceReceiverCode, $senderInvoiceNo);
|
|
242
242
|
|
|
243
243
|
// Create checkout token
|
|
244
244
|
$checkout = Checkout::create([
|
|
245
|
-
'company_uuid'
|
|
246
|
-
'store_uuid'
|
|
247
|
-
'network_uuid'
|
|
248
|
-
'cart_uuid'
|
|
249
|
-
'gateway_uuid'
|
|
245
|
+
'company_uuid' => session('company'),
|
|
246
|
+
'store_uuid' => session('storefront_store'),
|
|
247
|
+
'network_uuid' => session('storefront_network'),
|
|
248
|
+
'cart_uuid' => $cart->uuid,
|
|
249
|
+
'gateway_uuid' => $gateway->uuid,
|
|
250
250
|
'service_quote_uuid' => $serviceQuote->uuid,
|
|
251
|
-
'owner_uuid'
|
|
252
|
-
'owner_type'
|
|
253
|
-
'amount'
|
|
254
|
-
'currency'
|
|
255
|
-
'is_pickup'
|
|
256
|
-
'options'
|
|
257
|
-
'cart_state'
|
|
251
|
+
'owner_uuid' => $customer->uuid,
|
|
252
|
+
'owner_type' => 'contact',
|
|
253
|
+
'amount' => $amount,
|
|
254
|
+
'currency' => $currency,
|
|
255
|
+
'is_pickup' => $isPickup,
|
|
256
|
+
'options' => $checkoutOptions,
|
|
257
|
+
'cart_state' => $cart->toArray(),
|
|
258
258
|
]);
|
|
259
259
|
|
|
260
260
|
return response()->json([
|
|
261
261
|
'invoice' => $invoice,
|
|
262
|
-
'token'
|
|
262
|
+
'token' => $checkout->token,
|
|
263
263
|
]);
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
public function captureOrder(CaptureOrderRequest $request)
|
|
267
267
|
{
|
|
268
|
-
$token
|
|
268
|
+
$token = $request->input('token');
|
|
269
269
|
$transactionDetails = $request->input('transactionDetails', []); // optional details to be supplied about transaction
|
|
270
270
|
|
|
271
271
|
// validate transaction details
|
|
@@ -274,31 +274,31 @@ class CheckoutController extends Controller
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
// get checkout data to create order
|
|
277
|
-
$about
|
|
278
|
-
$checkout
|
|
279
|
-
$customer
|
|
277
|
+
$about = Storefront::about();
|
|
278
|
+
$checkout = Checkout::where('token', $token)->with(['gateway', 'owner', 'serviceQuote', 'cart'])->first();
|
|
279
|
+
$customer = $checkout->owner;
|
|
280
280
|
$serviceQuote = $checkout->serviceQuote;
|
|
281
|
-
$gateway
|
|
282
|
-
$origin
|
|
283
|
-
$destination
|
|
284
|
-
$cart
|
|
281
|
+
$gateway = $checkout->is_cod ? Gateway::cash() : $checkout->gateway;
|
|
282
|
+
$origin = $serviceQuote->getMeta('origin', []);
|
|
283
|
+
$destination = $serviceQuote->getMeta('destination');
|
|
284
|
+
$cart = $checkout->cart;
|
|
285
285
|
|
|
286
286
|
// if cart is null then cart has either been deleted or expired
|
|
287
287
|
if (!$cart) {
|
|
288
288
|
return response()->json([
|
|
289
|
-
'error' => 'Cart expired'
|
|
289
|
+
'error' => 'Cart expired',
|
|
290
290
|
], 400);
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
// $amount = $checkout->amount ?? ($checkout->is_pickup ? $cart->subtotal : $cart->subtotal + $serviceQuote->amount);
|
|
294
|
-
$amount
|
|
294
|
+
$amount = static::calculateCheckoutAmount($cart, $serviceQuote, $checkout->options);
|
|
295
295
|
$currency = $checkout->currency ?? ($cart->currency ?? session('storefront_currency'));
|
|
296
|
-
$store
|
|
296
|
+
$store = $about;
|
|
297
297
|
|
|
298
298
|
// check if order is via network for a single store
|
|
299
|
-
$isNetworkOrder
|
|
300
|
-
$isMultiCart
|
|
301
|
-
$isSingleStoreCheckout
|
|
299
|
+
$isNetworkOrder = $about->is_network === true;
|
|
300
|
+
$isMultiCart = $cart->isMultiCart;
|
|
301
|
+
$isSingleStoreCheckout = $isNetworkOrder && !$isMultiCart;
|
|
302
302
|
$isMultipleStoreCheckout = $isNetworkOrder && $isMultiCart;
|
|
303
303
|
|
|
304
304
|
// if multi store checkout send to captureMultipleOrders()
|
|
@@ -331,40 +331,40 @@ class CheckoutController extends Controller
|
|
|
331
331
|
|
|
332
332
|
// setup transaction meta
|
|
333
333
|
$transactionMeta = [
|
|
334
|
-
'storefront'
|
|
334
|
+
'storefront' => $store->name,
|
|
335
335
|
'storefront_id' => $store->public_id,
|
|
336
|
-
...$transactionDetails
|
|
336
|
+
...$transactionDetails,
|
|
337
337
|
];
|
|
338
338
|
|
|
339
339
|
if ($about->is_network) {
|
|
340
|
-
$transactionMeta['storefront_network']
|
|
340
|
+
$transactionMeta['storefront_network'] = $about->name;
|
|
341
341
|
$transactionMeta['storefront_network_id'] = $about->public_id;
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
// create transactions for cart
|
|
345
345
|
$transaction = Transaction::create([
|
|
346
|
-
'company_uuid'
|
|
347
|
-
'customer_uuid'
|
|
348
|
-
'customer_type'
|
|
346
|
+
'company_uuid' => session('company'),
|
|
347
|
+
'customer_uuid' => $customer->uuid,
|
|
348
|
+
'customer_type' => 'contact',
|
|
349
349
|
'gateway_transaction_id' => Utils::or($transactionDetails, ['id', 'transaction_id']) ?? Transaction::generateNumber(),
|
|
350
|
-
'gateway'
|
|
351
|
-
'gateway_uuid'
|
|
352
|
-
'amount'
|
|
353
|
-
'currency'
|
|
354
|
-
'description'
|
|
355
|
-
'type'
|
|
356
|
-
'status'
|
|
357
|
-
'meta'
|
|
350
|
+
'gateway' => $gateway->code,
|
|
351
|
+
'gateway_uuid' => $gateway->uuid,
|
|
352
|
+
'amount' => $amount,
|
|
353
|
+
'currency' => $currency,
|
|
354
|
+
'description' => 'Storefront order',
|
|
355
|
+
'type' => 'storefront',
|
|
356
|
+
'status' => 'success',
|
|
357
|
+
'meta' => $transactionMeta,
|
|
358
358
|
]);
|
|
359
359
|
|
|
360
360
|
// create transaction items
|
|
361
361
|
foreach ($cart->items as $cartItem) {
|
|
362
362
|
TransactionItem::create([
|
|
363
363
|
'transaction_uuid' => $transaction->uuid,
|
|
364
|
-
'amount'
|
|
365
|
-
'currency'
|
|
366
|
-
'details'
|
|
367
|
-
'code'
|
|
364
|
+
'amount' => $cartItem->subtotal,
|
|
365
|
+
'currency' => $checkout->currency,
|
|
366
|
+
'details' => Storefront::getFullDescriptionFromCartItem($cartItem),
|
|
367
|
+
'code' => 'product',
|
|
368
368
|
]);
|
|
369
369
|
}
|
|
370
370
|
|
|
@@ -372,10 +372,10 @@ class CheckoutController extends Controller
|
|
|
372
372
|
if (!$checkout->is_pickup) {
|
|
373
373
|
TransactionItem::create([
|
|
374
374
|
'transaction_uuid' => $transaction->uuid,
|
|
375
|
-
'amount'
|
|
376
|
-
'currency'
|
|
377
|
-
'details'
|
|
378
|
-
'code'
|
|
375
|
+
'amount' => $serviceQuote->amount,
|
|
376
|
+
'currency' => $serviceQuote->currency,
|
|
377
|
+
'details' => 'Delivery fee',
|
|
378
|
+
'code' => 'delivery_fee',
|
|
379
379
|
]);
|
|
380
380
|
}
|
|
381
381
|
|
|
@@ -383,10 +383,10 @@ class CheckoutController extends Controller
|
|
|
383
383
|
if ($checkout->hasOption('tip')) {
|
|
384
384
|
TransactionItem::create([
|
|
385
385
|
'transaction_uuid' => $transaction->uuid,
|
|
386
|
-
'amount'
|
|
387
|
-
'currency'
|
|
388
|
-
'details'
|
|
389
|
-
'code'
|
|
386
|
+
'amount' => static::calculateTipAmount($checkout->getOption('tip'), $cart->subtotal),
|
|
387
|
+
'currency' => $checkout->currency,
|
|
388
|
+
'details' => 'Tip',
|
|
389
|
+
'code' => 'tip',
|
|
390
390
|
]);
|
|
391
391
|
}
|
|
392
392
|
|
|
@@ -394,10 +394,10 @@ class CheckoutController extends Controller
|
|
|
394
394
|
if ($checkout->hasOption('delivery_tip')) {
|
|
395
395
|
TransactionItem::create([
|
|
396
396
|
'transaction_uuid' => $transaction->uuid,
|
|
397
|
-
'amount'
|
|
398
|
-
'currency'
|
|
399
|
-
'details'
|
|
400
|
-
'code'
|
|
397
|
+
'amount' => static::calculateTipAmount($checkout->getOption('delivery_tip'), $cart->subtotal),
|
|
398
|
+
'currency' => $checkout->currency,
|
|
399
|
+
'details' => 'Delivery Tip',
|
|
400
|
+
'code' => 'delivery_tip',
|
|
401
401
|
]);
|
|
402
402
|
}
|
|
403
403
|
|
|
@@ -410,16 +410,16 @@ class CheckoutController extends Controller
|
|
|
410
410
|
if (!$origin) {
|
|
411
411
|
$storeLocation = collect($cart->items)->map(function ($cartItem) {
|
|
412
412
|
$storeLocationId = $cartItem->store_location_id;
|
|
413
|
-
|
|
413
|
+
|
|
414
414
|
// if no store location id set, use first locations id
|
|
415
415
|
if (!$storeLocationId) {
|
|
416
416
|
$store = Store::where('public_id', $cartItem->store_id)->first();
|
|
417
|
-
|
|
417
|
+
|
|
418
418
|
if ($store) {
|
|
419
419
|
$storeLocationId = Utils::get($store, 'locations.0.public_id');
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
|
-
|
|
422
|
+
|
|
423
423
|
return $storeLocationId;
|
|
424
424
|
})->unique()->filter()->map(function ($storeLocationId) {
|
|
425
425
|
return StoreLocation::where('public_id', $storeLocationId)->first();
|
|
@@ -431,22 +431,22 @@ class CheckoutController extends Controller
|
|
|
431
431
|
}
|
|
432
432
|
|
|
433
433
|
// convert payload destinations to Place
|
|
434
|
-
$origin
|
|
434
|
+
$origin = Place::createFromMixed($origin);
|
|
435
435
|
$destination = Place::createFromMixed($destination);
|
|
436
436
|
|
|
437
437
|
// create payload for order
|
|
438
438
|
$payloadDetails = [
|
|
439
|
-
'company_uuid'
|
|
440
|
-
'pickup_uuid'
|
|
441
|
-
'dropoff_uuid'
|
|
442
|
-
'return_uuid'
|
|
439
|
+
'company_uuid' => session('company'),
|
|
440
|
+
'pickup_uuid' => $origin instanceof Place ? $origin->uuid : null,
|
|
441
|
+
'dropoff_uuid' => $destination instanceof Place ? $destination->uuid : null,
|
|
442
|
+
'return_uuid' => $origin instanceof Place ? $origin->uuid : null,
|
|
443
443
|
'payment_method' => $gateway->type,
|
|
444
|
-
'type'
|
|
444
|
+
'type' => 'storefront',
|
|
445
445
|
];
|
|
446
446
|
|
|
447
447
|
// if cash on delivery set cod attributes
|
|
448
448
|
if ($checkout->is_cod) {
|
|
449
|
-
$payloadDetails['cod_amount']
|
|
449
|
+
$payloadDetails['cod_amount'] = $amount;
|
|
450
450
|
$payloadDetails['cod_currency'] = $checkout->currency;
|
|
451
451
|
// @todo could be card if card swipe on delivery
|
|
452
452
|
$payloadDetails['cod_payment_method'] = 'cash';
|
|
@@ -458,17 +458,17 @@ class CheckoutController extends Controller
|
|
|
458
458
|
// create entities
|
|
459
459
|
foreach ($cart->items as $cartItem) {
|
|
460
460
|
$product = Product::where('public_id', $cartItem->product_id)->first();
|
|
461
|
-
$entity
|
|
462
|
-
'company_uuid'
|
|
463
|
-
'payload_uuid'
|
|
461
|
+
$entity = Entity::fromStorefrontProduct($product)->fill([
|
|
462
|
+
'company_uuid' => session('company'),
|
|
463
|
+
'payload_uuid' => $payload->uuid,
|
|
464
464
|
'customer_uuid' => $customer->uuid,
|
|
465
465
|
'customer_type' => 'contact',
|
|
466
466
|
])->setMetas([
|
|
467
|
-
'variants'
|
|
468
|
-
'addons'
|
|
469
|
-
'subtotal'
|
|
470
|
-
'quantity'
|
|
471
|
-
'scheduled_at' => $cartItem->scheduled_at ?? null
|
|
467
|
+
'variants' => $cartItem->variants,
|
|
468
|
+
'addons' => $cartItem->addons,
|
|
469
|
+
'subtotal' => $cartItem->subtotal,
|
|
470
|
+
'quantity' => $cartItem->quantity,
|
|
471
|
+
'scheduled_at' => $cartItem->scheduled_at ?? null,
|
|
472
472
|
]);
|
|
473
473
|
|
|
474
474
|
$entity->save();
|
|
@@ -476,46 +476,46 @@ class CheckoutController extends Controller
|
|
|
476
476
|
|
|
477
477
|
// create order meta
|
|
478
478
|
$orderMeta = [
|
|
479
|
-
'storefront'
|
|
479
|
+
'storefront' => $store->name,
|
|
480
480
|
'storefront_id' => $store->public_id,
|
|
481
481
|
];
|
|
482
482
|
|
|
483
483
|
// if network add network to order meta
|
|
484
484
|
if ($isNetworkOrder) {
|
|
485
|
-
$orderMeta['storefront_network']
|
|
485
|
+
$orderMeta['storefront_network'] = $about->name;
|
|
486
486
|
$orderMeta['storefront_network_id'] = $about->public_id;
|
|
487
487
|
}
|
|
488
488
|
|
|
489
489
|
$orderMeta = array_merge($orderMeta, [
|
|
490
|
-
'checkout_id'
|
|
491
|
-
'subtotal'
|
|
492
|
-
'delivery_fee' =>
|
|
493
|
-
'tip'
|
|
494
|
-
'delivery_tip' =>
|
|
495
|
-
'total'
|
|
496
|
-
'currency'
|
|
497
|
-
'require_pod'
|
|
498
|
-
'pod_method'
|
|
499
|
-
'is_pickup'
|
|
500
|
-
...$transactionDetails
|
|
490
|
+
'checkout_id' => $checkout->public_id,
|
|
491
|
+
'subtotal' => Utils::numbersOnly($cart->subtotal),
|
|
492
|
+
'delivery_fee' => $checkout->is_pickip ? 0 : Utils::numbersOnly($serviceQuote->amount),
|
|
493
|
+
'tip' => $checkout->getOption('tip'),
|
|
494
|
+
'delivery_tip' => $checkout->getOption('delivery_tip'),
|
|
495
|
+
'total' => Utils::numbersOnly($amount),
|
|
496
|
+
'currency' => $currency,
|
|
497
|
+
'require_pod' => $about->getOption('require_pod'),
|
|
498
|
+
'pod_method' => $about->pod_method,
|
|
499
|
+
'is_pickup' => $checkout->is_pickup,
|
|
500
|
+
...$transactionDetails,
|
|
501
501
|
]);
|
|
502
502
|
|
|
503
503
|
// initialize order creation input
|
|
504
504
|
$orderInput = [
|
|
505
|
-
'company_uuid'
|
|
506
|
-
'payload_uuid'
|
|
507
|
-
'customer_uuid'
|
|
508
|
-
'customer_type'
|
|
505
|
+
'company_uuid' => $store->company_uuid ?? session('company'),
|
|
506
|
+
'payload_uuid' => $payload->uuid,
|
|
507
|
+
'customer_uuid' => $customer->uuid,
|
|
508
|
+
'customer_type' => 'contact',
|
|
509
509
|
'transaction_uuid' => $transaction->uuid,
|
|
510
|
-
'adhoc'
|
|
511
|
-
'type'
|
|
512
|
-
'status'
|
|
513
|
-
'meta'
|
|
510
|
+
'adhoc' => $about->isOption('auto_dispatch'),
|
|
511
|
+
'type' => 'storefront',
|
|
512
|
+
'status' => 'created',
|
|
513
|
+
'meta' => $orderMeta,
|
|
514
514
|
];
|
|
515
515
|
|
|
516
516
|
// if it's integrated vendor order apply to meta
|
|
517
517
|
if ($integratedVendorOrder) {
|
|
518
|
-
$orderMeta['integrated_vendor']
|
|
518
|
+
$orderMeta['integrated_vendor'] = $serviceQuote->integratedVendor->public_id;
|
|
519
519
|
$orderMeta['integrated_vendor_order'] = $integratedVendorOrder;
|
|
520
520
|
// order input
|
|
521
521
|
$orderInput['facilitator_uuid'] = $serviceQuote->integratedVendor->uuid;
|
|
@@ -550,7 +550,7 @@ class CheckoutController extends Controller
|
|
|
550
550
|
$checkout->update([
|
|
551
551
|
'order_uuid' => $order->uuid,
|
|
552
552
|
// 'store_uuid' => $about->uuid,
|
|
553
|
-
'captured' => true
|
|
553
|
+
'captured' => true,
|
|
554
554
|
]);
|
|
555
555
|
|
|
556
556
|
return new OrderResource($order);
|
|
@@ -558,7 +558,7 @@ class CheckoutController extends Controller
|
|
|
558
558
|
|
|
559
559
|
public function captureMultipleOrders(CaptureOrderRequest $request)
|
|
560
560
|
{
|
|
561
|
-
$token
|
|
561
|
+
$token = $request->input('token');
|
|
562
562
|
$transactionDetails = $request->input('transactionDetails', []); // optional details to be supplied about transaction
|
|
563
563
|
|
|
564
564
|
// validate transaction details
|
|
@@ -567,19 +567,19 @@ class CheckoutController extends Controller
|
|
|
567
567
|
}
|
|
568
568
|
|
|
569
569
|
// get checkout data to create order
|
|
570
|
-
$about
|
|
571
|
-
$checkout
|
|
572
|
-
$customer
|
|
570
|
+
$about = Storefront::about();
|
|
571
|
+
$checkout = Checkout::where('token', $token)->with(['gateway', 'owner', 'serviceQuote', 'cart'])->first();
|
|
572
|
+
$customer = $checkout->owner;
|
|
573
573
|
$serviceQuote = $checkout->serviceQuote;
|
|
574
|
-
$gateway
|
|
575
|
-
$origins
|
|
574
|
+
$gateway = $checkout->is_cod ? Gateway::cash() : $checkout->gateway;
|
|
575
|
+
$origins = $serviceQuote->getMeta('origin');
|
|
576
576
|
// set origin
|
|
577
|
-
$origin
|
|
578
|
-
$waypoints
|
|
577
|
+
$origin = Arr::first($origins);
|
|
578
|
+
$waypoints = array_slice($origins, 1);
|
|
579
579
|
$destination = $serviceQuote->getMeta('destination');
|
|
580
|
-
$cart
|
|
580
|
+
$cart = $checkout->cart;
|
|
581
581
|
// $amount = $checkout->amount ?? ($checkout->is_pickup ? $cart->subtotal : $cart->subtotal + $serviceQuote->amount);
|
|
582
|
-
$amount
|
|
582
|
+
$amount = static::calculateCheckoutAmount($cart, $serviceQuote, $checkout->options);
|
|
583
583
|
$currency = $checkout->currency ?? ($cart->currency ?? session('storefront_currency'));
|
|
584
584
|
|
|
585
585
|
if (!$about) {
|
|
@@ -601,25 +601,25 @@ class CheckoutController extends Controller
|
|
|
601
601
|
|
|
602
602
|
// setup transaction meta
|
|
603
603
|
$transactionMeta = [
|
|
604
|
-
'storefront_network'
|
|
604
|
+
'storefront_network' => $about->name,
|
|
605
605
|
'storefront_network_id' => $about->public_id,
|
|
606
|
-
...$transactionDetails
|
|
606
|
+
...$transactionDetails,
|
|
607
607
|
];
|
|
608
608
|
|
|
609
609
|
// create transactions for cart
|
|
610
610
|
$transaction = Transaction::create([
|
|
611
|
-
'company_uuid'
|
|
612
|
-
'customer_uuid'
|
|
613
|
-
'customer_type'
|
|
611
|
+
'company_uuid' => session('company'),
|
|
612
|
+
'customer_uuid' => $customer->uuid,
|
|
613
|
+
'customer_type' => 'contact',
|
|
614
614
|
'gateway_transaction_id' => Utils::or($transactionDetails, ['id', 'transaction_id']) ?? Transaction::generateNumber(),
|
|
615
|
-
'gateway'
|
|
616
|
-
'gateway_uuid'
|
|
617
|
-
'amount'
|
|
618
|
-
'currency'
|
|
619
|
-
'description'
|
|
620
|
-
'type'
|
|
621
|
-
'status'
|
|
622
|
-
'meta'
|
|
615
|
+
'gateway' => $gateway->code,
|
|
616
|
+
'gateway_uuid' => $gateway->uuid,
|
|
617
|
+
'amount' => $amount,
|
|
618
|
+
'currency' => $currency,
|
|
619
|
+
'description' => 'Storefront network order',
|
|
620
|
+
'type' => 'storefront',
|
|
621
|
+
'status' => 'success',
|
|
622
|
+
'meta' => $transactionMeta,
|
|
623
623
|
]);
|
|
624
624
|
|
|
625
625
|
// create transaction items
|
|
@@ -628,16 +628,16 @@ class CheckoutController extends Controller
|
|
|
628
628
|
|
|
629
629
|
TransactionItem::create([
|
|
630
630
|
'transaction_uuid' => $transaction->uuid,
|
|
631
|
-
'amount'
|
|
632
|
-
'currency'
|
|
633
|
-
'details'
|
|
634
|
-
'code'
|
|
635
|
-
'meta'
|
|
636
|
-
'storefront_network'
|
|
631
|
+
'amount' => $cartItem->subtotal,
|
|
632
|
+
'currency' => $checkout->currency,
|
|
633
|
+
'details' => Storefront::getFullDescriptionFromCartItem($cartItem),
|
|
634
|
+
'code' => 'product',
|
|
635
|
+
'meta' => [
|
|
636
|
+
'storefront_network' => $about->name,
|
|
637
637
|
'storefront_network_id' => $about->public_id,
|
|
638
|
-
'storefront'
|
|
639
|
-
'storefront_id'
|
|
640
|
-
]
|
|
638
|
+
'storefront' => $store->name ?? null,
|
|
639
|
+
'storefront_id' => $store->public_id ?? null,
|
|
640
|
+
],
|
|
641
641
|
]);
|
|
642
642
|
}
|
|
643
643
|
|
|
@@ -645,10 +645,10 @@ class CheckoutController extends Controller
|
|
|
645
645
|
if (!$checkout->is_pickup) {
|
|
646
646
|
TransactionItem::create([
|
|
647
647
|
'transaction_uuid' => $transaction->uuid,
|
|
648
|
-
'amount'
|
|
649
|
-
'currency'
|
|
650
|
-
'details'
|
|
651
|
-
'code'
|
|
648
|
+
'amount' => $serviceQuote->amount,
|
|
649
|
+
'currency' => $serviceQuote->currency,
|
|
650
|
+
'details' => 'Delivery fee',
|
|
651
|
+
'code' => 'delivery_fee',
|
|
652
652
|
]);
|
|
653
653
|
}
|
|
654
654
|
|
|
@@ -656,10 +656,10 @@ class CheckoutController extends Controller
|
|
|
656
656
|
if ($checkout->hasOption('tip')) {
|
|
657
657
|
TransactionItem::create([
|
|
658
658
|
'transaction_uuid' => $transaction->uuid,
|
|
659
|
-
'amount'
|
|
660
|
-
'currency'
|
|
661
|
-
'details'
|
|
662
|
-
'code'
|
|
659
|
+
'amount' => static::calculateTipAmount($checkout->getOption('tip'), $cart->subtotal),
|
|
660
|
+
'currency' => $checkout->currency,
|
|
661
|
+
'details' => 'Tip',
|
|
662
|
+
'code' => 'tip',
|
|
663
663
|
]);
|
|
664
664
|
}
|
|
665
665
|
|
|
@@ -667,10 +667,10 @@ class CheckoutController extends Controller
|
|
|
667
667
|
if ($checkout->hasOption('delivery_tip')) {
|
|
668
668
|
TransactionItem::create([
|
|
669
669
|
'transaction_uuid' => $transaction->uuid,
|
|
670
|
-
'amount'
|
|
671
|
-
'currency'
|
|
672
|
-
'details'
|
|
673
|
-
'code'
|
|
670
|
+
'amount' => static::calculateTipAmount($checkout->getOption('delivery_tip'), $cart->subtotal),
|
|
671
|
+
'currency' => $checkout->currency,
|
|
672
|
+
'details' => 'Delivery Tip',
|
|
673
|
+
'code' => 'delivery_tip',
|
|
674
674
|
]);
|
|
675
675
|
}
|
|
676
676
|
|
|
@@ -687,12 +687,12 @@ class CheckoutController extends Controller
|
|
|
687
687
|
|
|
688
688
|
// create payload
|
|
689
689
|
$payload = Payload::create([
|
|
690
|
-
'company_uuid'
|
|
691
|
-
'pickup_uuid'
|
|
692
|
-
'dropoff_uuid'
|
|
693
|
-
'return_uuid'
|
|
690
|
+
'company_uuid' => $store->company_uuid,
|
|
691
|
+
'pickup_uuid' => $pickup instanceof Place ? $pickup->uuid : null,
|
|
692
|
+
'dropoff_uuid' => $destination instanceof Place ? $destination->uuid : null,
|
|
693
|
+
'return_uuid' => $pickup instanceof Place ? $pickup->uuid : null,
|
|
694
694
|
'payment_method' => $gateway->type,
|
|
695
|
-
'type'
|
|
695
|
+
'type' => 'storefront',
|
|
696
696
|
]);
|
|
697
697
|
|
|
698
698
|
// get cart items from this store
|
|
@@ -703,16 +703,16 @@ class CheckoutController extends Controller
|
|
|
703
703
|
$product = Product::where('public_id', $cartItem->product_id)->first();
|
|
704
704
|
|
|
705
705
|
$entity = Entity::fromStorefrontProduct($product)->fill([
|
|
706
|
-
'company_uuid'
|
|
707
|
-
'payload_uuid'
|
|
706
|
+
'company_uuid' => $store->company_uuid,
|
|
707
|
+
'payload_uuid' => $payload->uuid,
|
|
708
708
|
'customer_uuid' => $customer->uuid,
|
|
709
709
|
'customer_type' => 'contact',
|
|
710
710
|
])->setMetas([
|
|
711
|
-
'variants'
|
|
712
|
-
'addons'
|
|
713
|
-
'subtotal'
|
|
714
|
-
'quantity'
|
|
715
|
-
'scheduled_at' => $cartItem->scheduled_at ?? null
|
|
711
|
+
'variants' => $cartItem->variants,
|
|
712
|
+
'addons' => $cartItem->addons,
|
|
713
|
+
'subtotal' => $cartItem->subtotal,
|
|
714
|
+
'quantity' => $cartItem->quantity,
|
|
715
|
+
'scheduled_at' => $cartItem->scheduled_at ?? null,
|
|
716
716
|
]);
|
|
717
717
|
|
|
718
718
|
$entity->save();
|
|
@@ -723,39 +723,39 @@ class CheckoutController extends Controller
|
|
|
723
723
|
|
|
724
724
|
// prepare order meta
|
|
725
725
|
$orderMeta = [
|
|
726
|
-
'is_master_order'
|
|
727
|
-
'storefront'
|
|
728
|
-
'storefront_id'
|
|
729
|
-
'storefront_network'
|
|
726
|
+
'is_master_order' => false,
|
|
727
|
+
'storefront' => $store->name,
|
|
728
|
+
'storefront_id' => $store->public_id,
|
|
729
|
+
'storefront_network' => $about->name,
|
|
730
730
|
'storefront_network_id' => $about->public_id,
|
|
731
|
-
'checkout_id'
|
|
732
|
-
'subtotal'
|
|
733
|
-
'delivery_fee'
|
|
734
|
-
'tip'
|
|
735
|
-
'delivery_tip'
|
|
736
|
-
'total'
|
|
737
|
-
'currency'
|
|
738
|
-
'require_pod'
|
|
739
|
-
'pod_method'
|
|
740
|
-
'is_pickup'
|
|
741
|
-
...$transactionDetails
|
|
731
|
+
'checkout_id' => $checkout->public_id,
|
|
732
|
+
'subtotal' => $subtotal,
|
|
733
|
+
'delivery_fee' => 0,
|
|
734
|
+
'tip' => 0,
|
|
735
|
+
'delivery_tip' => 0,
|
|
736
|
+
'total' => $subtotal,
|
|
737
|
+
'currency' => $currency,
|
|
738
|
+
'require_pod' => $about->getOption('require_pod'),
|
|
739
|
+
'pod_method' => $about->pod_method,
|
|
740
|
+
'is_pickup' => $checkout->is_pickup,
|
|
741
|
+
...$transactionDetails,
|
|
742
742
|
];
|
|
743
743
|
|
|
744
744
|
// prepare order input
|
|
745
745
|
$orderInput = [
|
|
746
|
-
'company_uuid'
|
|
747
|
-
'payload_uuid'
|
|
748
|
-
'customer_uuid'
|
|
749
|
-
'customer_type'
|
|
746
|
+
'company_uuid' => $store->company_uuid,
|
|
747
|
+
'payload_uuid' => $payload->uuid,
|
|
748
|
+
'customer_uuid' => $customer->uuid,
|
|
749
|
+
'customer_type' => 'contact',
|
|
750
750
|
'transaction_uuid' => $transaction->uuid,
|
|
751
|
-
'adhoc'
|
|
752
|
-
'type'
|
|
753
|
-
'status'
|
|
751
|
+
'adhoc' => $about->isOption('auto_dispatch'),
|
|
752
|
+
'type' => 'storefront',
|
|
753
|
+
'status' => 'created',
|
|
754
754
|
];
|
|
755
755
|
|
|
756
756
|
// if it's integrated vendor order apply to meta
|
|
757
757
|
if ($integratedVendorOrder) {
|
|
758
|
-
$orderMeta['integrated_vendor']
|
|
758
|
+
$orderMeta['integrated_vendor'] = $serviceQuote->integratedVendor->public_id;
|
|
759
759
|
$orderMeta['integrated_vendor_order'] = $integratedVendorOrder;
|
|
760
760
|
// order input
|
|
761
761
|
$orderInput['facilitator_uuid'] = $serviceQuote->integratedVendor->uuid;
|
|
@@ -795,12 +795,12 @@ class CheckoutController extends Controller
|
|
|
795
795
|
|
|
796
796
|
// create master payload
|
|
797
797
|
$payload = Payload::create([
|
|
798
|
-
'company_uuid'
|
|
799
|
-
'pickup_uuid'
|
|
800
|
-
'dropoff_uuid'
|
|
801
|
-
'return_uuid'
|
|
798
|
+
'company_uuid' => session('company'),
|
|
799
|
+
'pickup_uuid' => $origin instanceof Place ? $origin->uuid : null,
|
|
800
|
+
'dropoff_uuid' => $destination instanceof Place ? $destination->uuid : null,
|
|
801
|
+
'return_uuid' => $origin instanceof Place ? $origin->uuid : null,
|
|
802
802
|
'payment_method' => $gateway->type,
|
|
803
|
-
'type'
|
|
803
|
+
'type' => 'storefront',
|
|
804
804
|
])->setWaypoints($waypoints);
|
|
805
805
|
|
|
806
806
|
// create entities
|
|
@@ -808,16 +808,16 @@ class CheckoutController extends Controller
|
|
|
808
808
|
$product = Product::where('public_id', $cartItem->product_id)->first();
|
|
809
809
|
|
|
810
810
|
$entity = Entity::fromStorefrontProduct($product)->fill([
|
|
811
|
-
'company_uuid'
|
|
812
|
-
'payload_uuid'
|
|
811
|
+
'company_uuid' => session('company'),
|
|
812
|
+
'payload_uuid' => $payload->uuid,
|
|
813
813
|
'customer_uuid' => $customer->uuid,
|
|
814
814
|
'customer_type' => 'contact',
|
|
815
815
|
])->setMetas([
|
|
816
|
-
'variants'
|
|
817
|
-
'addons'
|
|
818
|
-
'subtotal'
|
|
819
|
-
'quantity'
|
|
820
|
-
'scheduled_at' => $cartItem->scheduled_at ?? null
|
|
816
|
+
'variants' => $cartItem->variants,
|
|
817
|
+
'addons' => $cartItem->addons,
|
|
818
|
+
'subtotal' => $cartItem->subtotal,
|
|
819
|
+
'quantity' => $cartItem->quantity,
|
|
820
|
+
'scheduled_at' => $cartItem->scheduled_at ?? null,
|
|
821
821
|
]);
|
|
822
822
|
|
|
823
823
|
$entity->save();
|
|
@@ -825,40 +825,40 @@ class CheckoutController extends Controller
|
|
|
825
825
|
|
|
826
826
|
// prepare master order meta
|
|
827
827
|
$masterOrderMeta = [
|
|
828
|
-
'is_master_order'
|
|
829
|
-
'related_orders'
|
|
830
|
-
'storefront'
|
|
831
|
-
'storefront_id'
|
|
832
|
-
'storefront_network'
|
|
828
|
+
'is_master_order' => true,
|
|
829
|
+
'related_orders' => collect($multipleOrders)->pluck('public_id')->toArray(),
|
|
830
|
+
'storefront' => $about->name,
|
|
831
|
+
'storefront_id' => $about->public_id,
|
|
832
|
+
'storefront_network' => $about->name,
|
|
833
833
|
'storefront_network_id' => $about->public_id,
|
|
834
|
-
'checkout_id'
|
|
835
|
-
'subtotal'
|
|
836
|
-
'delivery_fee'
|
|
837
|
-
'tip'
|
|
838
|
-
'delivery_tip'
|
|
839
|
-
'total'
|
|
840
|
-
'currency'
|
|
841
|
-
'require_pod'
|
|
842
|
-
'pod_method'
|
|
843
|
-
'is_pickup'
|
|
844
|
-
...$transactionDetails
|
|
834
|
+
'checkout_id' => $checkout->public_id,
|
|
835
|
+
'subtotal' => Utils::numbersOnly($cart->subtotal),
|
|
836
|
+
'delivery_fee' => $checkout->is_pickip ? 0 : Utils::numbersOnly($serviceQuote->amount),
|
|
837
|
+
'tip' => $checkout->getOption('tip'),
|
|
838
|
+
'delivery_tip' => $checkout->getOption('delivery_tip'),
|
|
839
|
+
'total' => Utils::numbersOnly($amount),
|
|
840
|
+
'currency' => $currency,
|
|
841
|
+
'require_pod' => $about->getOption('require_pod'),
|
|
842
|
+
'pod_method' => $about->pod_method,
|
|
843
|
+
'is_pickup' => $checkout->is_pickup,
|
|
844
|
+
...$transactionDetails,
|
|
845
845
|
];
|
|
846
846
|
|
|
847
847
|
// prepare master order input
|
|
848
848
|
$masterOrderInput = [
|
|
849
|
-
'company_uuid'
|
|
850
|
-
'payload_uuid'
|
|
851
|
-
'customer_uuid'
|
|
852
|
-
'customer_type'
|
|
849
|
+
'company_uuid' => session('company'),
|
|
850
|
+
'payload_uuid' => $payload->uuid,
|
|
851
|
+
'customer_uuid' => $customer->uuid,
|
|
852
|
+
'customer_type' => 'contact',
|
|
853
853
|
'transaction_uuid' => $transaction->uuid,
|
|
854
|
-
'adhoc'
|
|
855
|
-
'type'
|
|
856
|
-
'status'
|
|
854
|
+
'adhoc' => $about->isOption('auto_dispatch'),
|
|
855
|
+
'type' => 'storefront',
|
|
856
|
+
'status' => 'created',
|
|
857
857
|
];
|
|
858
858
|
|
|
859
859
|
// if it's integrated vendor order apply to meta
|
|
860
860
|
if ($integratedVendorOrder) {
|
|
861
|
-
$masterOrderMeta['integrated_vendor']
|
|
861
|
+
$masterOrderMeta['integrated_vendor'] = $serviceQuote->integratedVendor->public_id;
|
|
862
862
|
$masterOrderMeta['integrated_vendor_order'] = $integratedVendorOrder;
|
|
863
863
|
// order input
|
|
864
864
|
$masterOrderInput['facilitator_uuid'] = $serviceQuote->integratedVendor->uuid;
|
|
@@ -895,7 +895,7 @@ class CheckoutController extends Controller
|
|
|
895
895
|
$checkout->update([
|
|
896
896
|
'order_uuid' => $order->uuid,
|
|
897
897
|
// 'store_uuid' => $about->uuid,
|
|
898
|
-
'captured' => true
|
|
898
|
+
'captured' => true,
|
|
899
899
|
]);
|
|
900
900
|
|
|
901
901
|
return new OrderResource($order);
|
|
@@ -908,20 +908,17 @@ class CheckoutController extends Controller
|
|
|
908
908
|
/**
|
|
909
909
|
* Calculates the total checkout amount.
|
|
910
910
|
*
|
|
911
|
-
* @param Cart $cart
|
|
912
|
-
* @param ServiceQuote $serviceQuote
|
|
913
911
|
* @param stdClass $checkoutOptions
|
|
914
|
-
* @return integer
|
|
915
912
|
*/
|
|
916
913
|
private static function calculateCheckoutAmount(Cart $cart, ServiceQuote $serviceQuote, $checkoutOptions): int
|
|
917
914
|
{
|
|
918
915
|
// cast checkout options to object always
|
|
919
916
|
$checkoutOptions = (object) $checkoutOptions;
|
|
920
|
-
$subtotal
|
|
921
|
-
$total
|
|
922
|
-
$tip
|
|
923
|
-
$deliveryTip
|
|
924
|
-
$isPickup
|
|
917
|
+
$subtotal = (int) $cart->subtotal;
|
|
918
|
+
$total = $subtotal;
|
|
919
|
+
$tip = $checkoutOptions->tip ?? false;
|
|
920
|
+
$deliveryTip = $checkoutOptions->delivery_tip ?? false;
|
|
921
|
+
$isPickup = $checkoutOptions->is_pickup ?? false;
|
|
925
922
|
|
|
926
923
|
if ($tip) {
|
|
927
924
|
$tipAmount = static::calculateTipAmount($tip, $subtotal);
|