PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Http / Controllers / CheckoutController.php

CheckoutController.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Http/Controllers/CheckoutController.php

69 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Http\Controllers;
4
5
6 use FluentCart\Api\Checkout\CheckoutApi;
7 use FluentCart\App\Helpers\CartHelper;
8 use FluentCart\App\Helpers\Helper;
9 use FluentCart\App\Models\ShippingMethod;
10 use FluentCart\App\Services\RateLimiter;
11 use FluentCart\App\Modules\PaymentMethods\Core\GatewayManager;
12 use FluentCart\Framework\Http\Request\Request;
13
14 class CheckoutController extends Controller
15 {
16 /**
17 * @throws \Exception
18 */
19 public function placeOrder(Request $request)
20 {
21 RateLimiter::isSpamming('place_order_attempt', 5, 60, true);
22
23 CheckoutApi::placeOrder($request->all(), true);
24 }
25
26 public function getCheckoutSummary(Request $request)
27 {
28 $checkOutHelper = \FluentCart\App\Helpers\CartCheckoutHelper::make();
29 $shippingMethodId = $request->getSafe('shipping_method_id', 'sanitize_text_field');
30
31
32 $charge = 0;
33 $shippingMethod = ShippingMethod::query()->find($shippingMethodId);
34 if (!empty($shippingMethod)) {
35 $charge = CartHelper::calculateShippingMethodCharge($shippingMethod);
36 }
37
38 ob_start();
39 do_action('fluent_cart/views/checkout_page_cart_item_list', [
40 'checkout' => $checkOutHelper,
41 'items' => $checkOutHelper->getItems()
42 ]);
43 $views = ob_get_clean();
44
45 $items['views'] = $views;
46 $items['subtotal'] = $checkOutHelper->getItemsAmountSubtotal(true, true);
47
48 $total = $checkOutHelper->getItemsAmountTotal(false, false);
49
50 $items['has_subscriptions'] = $checkOutHelper->hasSubscription() === 'yes';
51 $items['shipping_charge'] = $charge;
52 $items['unformatted_total'] = $total + $charge;
53 $formatted = Helper::toDecimal($total + $charge, true);
54 $items['total'] = $formatted;
55 $items['shipping_charge_formated'] = Helper::toDecimal($charge, true);
56 $items['shipping_method_id'] = $shippingMethodId;
57
58 return [
59 'items' => $items
60 ];
61 }
62
63 public function getOrderInfo(Request $request)
64 {
65 $paymentManager = GatewayManager::getInstance()->get($request->getSafe('method', 'sanitize_text_field'));
66 return $paymentManager->getOrderInfo($request->all());
67 }
68 }
69