PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.26
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.26
1.6.6 1.6.5 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 All 49 releases
fluent-cart / app / Services / Renderer / ModalCheckoutRenderer.php

ModalCheckoutRenderer.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.26, at app/Services/Renderer/ModalCheckoutRenderer.php

649 lines 28.9 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\Services\Renderer;
4
5 use FluentCart\Api\PaymentMethods;
6 use FluentCart\Api\Resource\CustomerResource;
7 use FluentCart\Api\Resource\FrontendResource\CustomerAddressResource;
8 use FluentCart\Api\StoreSettings;
9 use FluentCart\App\App;
10 use FluentCart\App\Helpers\AddressHelper;
11 use FluentCart\App\Helpers\CartHelper;
12 use FluentCart\App\Helpers\Helper;
13 use FluentCart\App\Models\Cart;
14 use FluentCart\App\Models\ProductVariation;
15 use FluentCart\App\Services\Localization\LocalizationManager;
16 use FluentCart\App\Services\URL;
17 use FluentCart\App\Vite;
18 use FluentCart\Framework\Support\Arr;
19 use FluentCart\App\Models\ProductMeta;
20
21 class ModalCheckoutRenderer
22 {
23 private $cart;
24
25 private $requireShipping;
26
27 private $hasSubscription = false;
28
29 private $config = [];
30
31 private $storeSettings;
32
33 private $productMeta;
34
35 private $matchedVariation;
36
37 private $checkoutRenderer;
38
39 private $cartSummaryRenderer;
40
41 private $customer;
42
43 public function __construct(Cart $cart, $config = [])
44 {
45 $this->cart = $cart;
46 $this->config = $config;
47 $this->requireShipping = $cart->requireShipping();
48 $this->storeSettings = new StoreSettings();
49 $this->checkoutRenderer = new CheckoutRenderer($cart);
50 $this->cartSummaryRenderer = new CartSummaryRender($cart);
51 $this->hasSubscription = $cart->hasSubscription();
52 $this->customer = CustomerResource::getCurrentCustomer();
53
54 $this->productMeta = ProductMeta::query()->where('object_id', Arr::get($this->cart->cart_data, '0.post_id'))->where('meta_key', 'license_settings')->first();
55
56 $variations = $this->productMeta->meta_value['variations'] ?? [];
57
58 $cartItem = $this->cart->cart_data[0] ?? [];
59 $objectId = $cartItem['object_id'] ?? null;
60
61 $this->matchedVariation = $objectId && isset($variations[$objectId])
62 ? $variations[$objectId]
63 : null;
64 }
65
66 public function getFragment($fragmentName)
67 {
68 $maps = [
69 'payment_methods' => 'renderPaymentMethods',
70 'summary_group' => 'renderSummaryGroup'
71 ];
72
73 if(isset($maps[$fragmentName])) {
74 ob_start();
75 $this->{$maps[$fragmentName]}();
76 return ob_get_clean();
77 }
78
79 return '';
80
81 }
82
83 public function render()
84 {
85 ?>
86 <div class="fct-checkout-modal-container" data-fct-checkout-modal-container style="opacity: 0; visibility: hidden;">
87 <div class="fct-checkout-modal" data-fct-checkout-modal>
88 <div class="fct-checkout-modal-loader" data-fct-checkout-modal-loader>
89 <div class="fct-checkout-modal-loader-spinner"></div>
90 </div>
91 <button class="fct-checkout-modal-close" data-fct-checkout-modal-close aria-label="<?php echo esc_attr__('Close checkout', 'fluent-cart');?>">
92 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
93 <line x1="18" y1="6" x2="6" y2="18"></line>
94 <line x1="6" y1="6" x2="18" y2="18"></line>
95 </svg>
96 </button>
97 <div class="fct-checkout-modal-content">
98 <?php $this->renderIframe();?>
99 </div>
100 </div>
101 </div>
102 <?php
103 }
104
105 public function renderIframe()
106 {
107 ?>
108 <iframe class="fct-checkout-modal-iframe" data-fct-checkout-modal-iframe title="<?php echo esc_attr__('Checkout', 'fluent-cart');?>" frameborder="0" allowtransparency="true" spellcheck="false"></iframe>
109 <?php
110 }
111
112 public function renderForm()
113 {
114 ?>
115 <div class="fct-modal-checkout-form-wrapper" data-fluent-cart-checkout-page>
116 <form
117 class="fct-modal-checkout-form"
118 action="<?php echo esc_url(home_url('/')); ?>"
119 method="POST"
120 data-fluent-cart-checkout-page-checkout-form
121 enctype="multipart/form-data"
122 aria-label="<?php esc_attr_e('Checkout Form', 'fluent-cart'); ?>"
123 >
124 <div class="fct-modal-checkout-form-inner" data-fct-modal-checkout-form-inner>
125 <?php $this->renderCheckoutDetails(); ?>
126 <?php $this->renderCheckoutBilling(); ?>
127 </div>
128 </form>
129 </div>
130 <?php
131 }
132
133
134 public function renderCheckoutDetails()
135 {
136 ?>
137 <div class="fct-modal-checkout-details">
138 <?php $this->renderCheckoutSummary();?>
139
140 <?php $this->checkoutRenderer->renderAddressFields(); ?>
141
142 <div class="fct_checkout_shipping_methods <?php echo $this->requireShipping ? '' : 'is-hidden' ?>">
143 <?php $this->checkoutRenderer->renderShippingOptions(); ?>
144 </div>
145
146 <?php do_action('fluent_cart/before_payment_methods', ['cart' => $this->cart]); ?>
147
148 <?php $this->checkoutRenderer->agreeTerms(); ?>
149
150 <?php $this->renderSummaryGroup(); ?>
151
152 <?php //$this->renderCheckoutReviews();?>
153 </div>
154 <?php
155 }
156
157 public function renderCheckoutSummary()
158 {
159 $title = Arr::get($this->cart->cart_data, '0.title', '');
160 $postTitle = Arr::get($this->cart->cart_data, '0.post_title', '');
161 $subTotal = Helper::toDecimal(Arr::get($this->cart->cart_data, '0.subtotal', 0));
162 $media = Arr::get($this->cart->cart_data, '0.featured_media', '');
163
164 ?>
165 <div class="fct-modal-checkout-summary">
166 <div class="fct-modal-cs-img">
167 <img src="<?php echo esc_url($media);?>" alt="<?php echo esc_attr($postTitle);?>">
168 </div>
169
170 <div class="fct-modal-cs-content">
171 <div class="fct-modal-cs-line-item">
172 <div class="fct-modal-cs-item-content">
173 <h2 class="fct-modal-cs-item-name">
174 <?php echo esc_html($postTitle);?>
175 </h2>
176 <h3 class="fct-modal-cs-item-variation">
177 - <?php echo esc_html($title);?>
178 </h3>
179 </div>
180
181 <span class="fct-modal-cs-line-price">
182 <?php echo $subTotal;?>
183 </span>
184 </div>
185
186 <?php $this->renderPaymentTypeInfo(); ?>
187
188 <?php if($this->matchedVariation) :?>
189 <div class="fct-modal-cs-license">
190 <?php
191 $limit = Arr::get($this->matchedVariation, 'activation_limit');
192
193 if (empty($limit) || (int) $limit === 0) {
194 echo esc_html__('Unlimited Activation', 'fluent-cart');
195 } else {
196 echo esc_html(sprintf(__('Activation limit %d', 'fluent-cart'), $limit));
197 }
198 ?>
199 </div>
200 <?php endif;?>
201
202
203 </div>
204 </div>
205
206 <?php
207
208 }
209
210 public function renderPaymentTypeInfo() {
211 $otherInfo = Arr::get($this->cart->cart_data, '0.other_info', []);
212 $paymentType = Arr::get($otherInfo, 'payment_type', '');
213 $itemPrice = Arr::get($this->cart->cart_data, '0.unit_price', 0);
214
215
216 if ($paymentType === 'subscription') {
217 $subscriptionInfo = Helper::generateSubscriptionInfo($otherInfo, $itemPrice);
218 $setupFeeInfo = Helper::generateSetupFeeInfo($otherInfo);
219 $trialInfo = Helper::generateTrialInfo($otherInfo);
220 ?>
221 <div class="fct-modal-cs-payment-info">
222 <span class="sr-only">
223 <?php esc_html_e('Payment information', 'fluent-cart'); ?>
224 </span>
225
226 <span>
227 <?php echo wp_kses($subscriptionInfo, ['del' => true]); ?>&#44;
228 </span>
229
230 <?php if ($trialInfo): ?>
231 <span class="trial-days">
232 <?php echo esc_html($trialInfo); ?>&#44;
233 </span>
234 <?php endif; ?>
235
236 <?php if (!empty($setupFeeInfo)): ?>
237 <span class="setup-fee">
238 <?php echo esc_html($setupFeeInfo); ?>
239 </span>
240 <?php endif; ?>
241 </div>
242 <?php
243 }
244 }
245
246 public function renderPromoCode() {
247 ?>
248 <div class="fct-modal-checkout-promo-code">
249 <div class="fct-modal-input-control-wrap" data-fct-modal-input-control-wrap>
250 <button type="button" class="fct-modal-input-toggle-btn" data-fct-modal-input-toggle-btn>
251 <?php echo esc_html__('Have a promotional code?', 'fluent-cart');?>
252 </button>
253
254 <div class="fct-modal-input-controls fct-hidden" data-fct-modal-input-controls>
255 <span class="fct-input-icon">
256 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
257 <path fill="currentColor" d="M336 352c97.2 0 176-78.8 176-176S433.2 0 336 0 160 78.8 160 176c0 18.7 2.9 36.8 8.3 53.7L7 391c-4.5 4.5-7 10.6-7 17l0 80c0 13.3 10.7 24 24 24l80 0c13.3 0 24-10.7 24-24l0-40 40 0c13.3 0 24-10.7 24-24l0-40 40 0c6.4 0 12.5-2.5 17-7l33.3-33.3c16.9 5.4 35 8.3 53.7 8.3zM376 96a40 40 0 1 1 0 80 40 40 0 1 1 0-80z"/></svg>
258 </span>
259
260 <input
261 class="fct-input-field"
262 id="coupon"
263 type="text"
264 name="coupon"
265 placeholder="<?php echo esc_attr__('Enter promotion code', 'fluent-cart');?>"
266 >
267
268
269 <button type="button" class="fct-input-submit-btn" data-fluent-cart-checkout-page-coupon-validate>
270 <?php echo esc_html__('Apply', 'fluent-cart');?>
271 </button>
272 </div>
273 </div>
274 </div>
275 <?php
276 }
277 public function renderSummaryGroup() {
278 ?>
279
280 <div class="fct-modal-checkout-summary-group" data-fct-modal-checkout-summary-group>
281 <?php
282 $this->cartSummaryRenderer->renderItemsFooter();
283 ?>
284 </div>
285
286 <?php
287
288 }
289
290
291 public function showCouponApplied()
292 {
293 $discounts = $this->cart->getDiscountLines();
294
295 if (!$discounts) {
296 return;
297 }
298
299 ?>
300
301 <div class="fct-modal-coupon-applied" data-fluent-cart-checkout-page-discount-container>
302 <?php foreach ($discounts as $couponCode => $discount_data): ?>
303 <div class="fct-coupon-applied-item">
304 <div class="fct-coupon-info">
305 <span class="fct-coupon">
306 <span class="fct-coupon-icon">
307 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M32.5 96l0 149.5c0 17 6.7 33.3 18.7 45.3l192 192c25 25 65.5 25 90.5 0L483.2 333.3c25-25 25-65.5 0-90.5l-192-192C279.2 38.7 263 32 246 32L96.5 32c-35.3 0-64 28.7-64 64zm112 16a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>
308 </span>
309
310 <?php echo esc_html($discount_data['formatted_title']) ?>
311
312 <a
313 href="#"
314 class="fct-remove-coupon"
315 data-remove-coupon
316 data-coupon="<?php echo esc_attr($couponCode); ?>"
317 >
318 <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 384 512"><path d="M55.1 73.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L147.2 256 9.9 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192.5 301.3 329.9 438.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.8 256 375.1 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192.5 210.7 55.1 73.4z"/></svg>
319 </a>
320 </span>
321 <span class="fct-coupon-text">
322 <?php echo esc_html__( 'Coupon discount', 'fluent-cart'); ?>
323 </span>
324 </div>
325 <div class="fct-coupon-price">
326 &#8211;<?php echo esc_html($discount_data['actual_formatted_discount']) ?>
327 </div>
328 </div>
329 <?php endforeach; ?>
330 </div>
331
332 <?php
333 }
334
335 public function renderCheckoutReviews() {
336 ?>
337 <div class="fct-modal-checkout-reviews-wrap">
338 <div class="fct-modal-checkout-reviews">
339 <div class="fct-reviews-picture">
340 <img width="40" height="40" src="https://images.pexels.com/photos/23885849/pexels-photo-23885849.jpeg" alt="">
341 </div>
342 <div class="fct-reviews-content">
343 <div class="fct-reviews-text">
344 I got the annual unlimited websites premium version and I'm upgrading to the Lifetime Unlimited Websites plan real soon. Building WordPress website
345 </div>
346 <div class="fct-reviews-meta">
347 <div class="fct-review-stars">
348 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">
349 <path fill="currentColor" d="M309.5-18.9c-4.1-8-12.4-13.1-21.4-13.1s-17.3 5.1-21.4 13.1L193.1 125.3 33.2 150.7c-8.9 1.4-16.3 7.7-19.1 16.3s-.5 18 5.8 24.4l114.4 114.5-25.2 159.9c-1.4 8.9 2.3 17.9 9.6 23.2s16.9 6.1 25 2L288.1 417.6 432.4 491c8 4.1 17.7 3.3 25-2s11-14.2 9.6-23.2L441.7 305.9 556.1 191.4c6.4-6.4 8.6-15.8 5.8-24.4s-10.1-14.9-19.1-16.3L383 125.3 309.5-18.9z"/>
350 </svg>
351 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">
352 <path fill="currentColor" d="M309.5-18.9c-4.1-8-12.4-13.1-21.4-13.1s-17.3 5.1-21.4 13.1L193.1 125.3 33.2 150.7c-8.9 1.4-16.3 7.7-19.1 16.3s-.5 18 5.8 24.4l114.4 114.5-25.2 159.9c-1.4 8.9 2.3 17.9 9.6 23.2s16.9 6.1 25 2L288.1 417.6 432.4 491c8 4.1 17.7 3.3 25-2s11-14.2 9.6-23.2L441.7 305.9 556.1 191.4c6.4-6.4 8.6-15.8 5.8-24.4s-10.1-14.9-19.1-16.3L383 125.3 309.5-18.9z"/>
353 </svg>
354 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">
355 <path fill="currentColor" d="M309.5-18.9c-4.1-8-12.4-13.1-21.4-13.1s-17.3 5.1-21.4 13.1L193.1 125.3 33.2 150.7c-8.9 1.4-16.3 7.7-19.1 16.3s-.5 18 5.8 24.4l114.4 114.5-25.2 159.9c-1.4 8.9 2.3 17.9 9.6 23.2s16.9 6.1 25 2L288.1 417.6 432.4 491c8 4.1 17.7 3.3 25-2s11-14.2 9.6-23.2L441.7 305.9 556.1 191.4c6.4-6.4 8.6-15.8 5.8-24.4s-10.1-14.9-19.1-16.3L383 125.3 309.5-18.9z"/>
356 </svg>
357 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">
358 <path fill="currentColor" d="M309.5-18.9c-4.1-8-12.4-13.1-21.4-13.1s-17.3 5.1-21.4 13.1L193.1 125.3 33.2 150.7c-8.9 1.4-16.3 7.7-19.1 16.3s-.5 18 5.8 24.4l114.4 114.5-25.2 159.9c-1.4 8.9 2.3 17.9 9.6 23.2s16.9 6.1 25 2L288.1 417.6 432.4 491c8 4.1 17.7 3.3 25-2s11-14.2 9.6-23.2L441.7 305.9 556.1 191.4c6.4-6.4 8.6-15.8 5.8-24.4s-10.1-14.9-19.1-16.3L383 125.3 309.5-18.9z"/>
359 </svg>
360 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">
361 <path fill="currentColor" d="M309.5-18.9c-4.1-8-12.4-13.1-21.4-13.1s-17.3 5.1-21.4 13.1L193.1 125.3 33.2 150.7c-8.9 1.4-16.3 7.7-19.1 16.3s-.5 18 5.8 24.4l114.4 114.5-25.2 159.9c-1.4 8.9 2.3 17.9 9.6 23.2s16.9 6.1 25 2L288.1 417.6 432.4 491c8 4.1 17.7 3.3 25-2s11-14.2 9.6-23.2L441.7 305.9 556.1 191.4c6.4-6.4 8.6-15.8 5.8-24.4s-10.1-14.9-19.1-16.3L383 125.3 309.5-18.9z"/>
362 </svg>
363 </div>
364 <div class="fct-review-author-info">
365 <span class="fct-author-name">Bryson Suleiman,</span>
366 <span class="fct-author-role">Founder and WordPress Expert at Webbryson</span>
367 </div>
368 </div>
369 </div>
370 </div>
371 </div>
372
373 <?php
374
375 }
376
377
378 public function renderCheckoutBilling() {
379 $user = wp_get_current_user();
380 $formRender = new FormFieldRenderer();
381 $fullName = trim(
382 ($this->customer->first_name ?? '') . ' ' . ($this->customer->last_name ?? '')
383 );
384
385 if (!$fullName && $user) {
386 $fullName = $user->display_name;
387 }
388
389 $fieldsSchema = CheckoutFieldsSchema::getFieldsSettings();
390
391 $fullNameField = Arr::get($fieldsSchema, 'basic_info.full_name', []);
392 $emailField = Arr::get($fieldsSchema, 'basic_info.email', []);
393 $isRequiredFullName = Arr::get($fullNameField, 'required', 'no') === 'yes' ? 'yes' : '';
394 $isRequiredEmail = Arr::get($emailField, 'required', 'no') === 'yes' ? 'yes' : '';
395
396 ?>
397 <div class="fct-modal-checkout-billing-wrap">
398 <!-- Account Details -->
399 <div class="fct-modal-account-details" data-fct-checkout-form-section>
400 <div class="fct-modal-form-info">
401 <div class="fct-modal-form-field col-6">
402 <?php
403 $formRender->renderField([
404 'label' => esc_attr__('Full name', 'fluent-cart') . ($isRequiredFullName ? ' *' : ''),
405 'id' => 'billing_full_name',
406 'type' => 'text',
407 'placeholder' => __('Jon Doe', 'fluent-cart'),
408 'name' => 'billing_full_name',
409 'autocomplete' => 'given-name',
410 'aria-label' => esc_attr__('Full name', 'fluent-cart'),
411 'required' => $isRequiredFullName,
412 'value' => $fullName
413 ]);
414 ?>
415 </div>
416 <div class="fct-modal-form-field col-6">
417 <?php
418 $formRender->renderField([
419 'label' => esc_attr__('Email address', 'fluent-cart') . ($isRequiredEmail ? ' *' : ''),
420 'id' => 'billing_email',
421 'type' => 'text',
422 'placeholder' => 'jon.doe@example.com',
423 'name' => 'billing_email',
424 'autocomplete' => 'email',
425 'required' => $isRequiredEmail,
426 'aria-label' => esc_attr__('Email address', 'fluent-cart'),
427 'value' => $this->customer->email ?? $user->user_email,
428 'disabled' => (bool)($this->customer->email ?? $user->user_email)
429 ]);
430 ?>
431 </div>
432
433 <!-- <div class="fct-modal-form-field col-3">-->
434 <!-- --><?php
435 // $formRender->renderField([
436 // 'label' => __('Last name', 'fluent-cart'),
437 // 'id' => 'billing_last_name',
438 // 'type' => 'text',
439 // 'placeholder' => __('Doe', 'fluent-cart'),
440 // 'name' => 'billing_last_name',
441 // 'autocomplete' => 'given-name',
442 // 'required' => true,
443 // 'value' => $this->customer->last_name ?? ''
444 // ]);
445 // ?>
446 <!-- </div>-->
447 </div>
448
449 <?php $this->checkoutRenderer->renderCreateAccountField(); ?>
450
451 <!-- Error Message -->
452 <div class="fct_form_error fct_error_billing_personal_information_section"></div>
453 </div>
454
455 <!-- Billing Details -->
456 <div class="fct-modal-billing-details">
457 <header class="fct-modal-billing-header">
458 <h4 class="fct-modal-billing-title">
459 <?php echo esc_html__('Billing information', 'fluent-cart');?>
460 </h4>
461 </header>
462
463 <div class="fct_checkout_payment_methods" data-fluent-cart-checkout-payment-methods>
464 <?php $this->renderPaymentMethods(); ?>
465 </div>
466
467 <div class="fct-modal-checkout-btn-wrap">
468 <?php (new CheckoutRenderer($this->cart))->renderCheckoutButton(); ?>
469 </div>
470 </div>
471 </div>
472
473 <?php
474
475 }
476
477 public function renderPaymentMethods()
478 {
479 if ($this->cart->getEstimatedTotal() <= 0) {
480 if (!$this->cart->hasSubscription() || $this->cart->getEstimatedRecurringTotal() <= 0) {
481 return '';
482 }
483 }
484
485 $selectedPaymentMethod = Arr::get($this->cart->checkout_data, 'form_data._fct_pay_method', '');
486 $activePaymentMethods = PaymentMethods::getActiveMethodInstance($this->cart);
487
488 $activePaymentMethods = apply_filters('fluent_cart/checkout_active_payment_methods', $activePaymentMethods, [
489 'cart' => $this->cart
490 ]);
491
492 // filter the active payment methods to only include the selected payment method
493 $selectedModalPaymentMethod = apply_filters('fluent_cart/modal_checkout/filter_active_payment_methods', []);
494 if (!empty($selectedModalPaymentMethod)) {
495 $activePaymentMethods = array_filter($activePaymentMethods, function ($method) use ($selectedModalPaymentMethod) {
496 return in_array($method->getMeta('route'), $selectedModalPaymentMethod);
497 });
498 }
499
500 if (!$selectedPaymentMethod && !empty($activePaymentMethods)) {
501 $selectedPaymentMethod = $activePaymentMethods[0] ? $activePaymentMethods[0]->getMeta('route') : '';
502 }
503
504 $checkoutMethodStyle = $this->storeSettings->get('checkout_method_style', 'logo');
505
506 ?>
507 <div id="fluent_payment_methods" class="fct_modal_payment_methods fluent_payment_methods">
508 <!-- Payment Methods -->
509 <div class="fct_payment_methods_list fct_payment_method_mode_<?php echo esc_attr($checkoutMethodStyle); ?>">
510 <?php if (!empty($activePaymentMethods)): ?>
511 <?php foreach ($activePaymentMethods as $method) {
512 $isSelected = ($selectedPaymentMethod === $method->getMeta('route'));
513
514 $this->renderPaymentMethod($method, [
515 'selected_id' => $selectedPaymentMethod,
516 'style' => $checkoutMethodStyle,
517 'aria_checked' => $isSelected ? 'true' : 'false',
518 'role' => 'radio'
519 ]);
520 } ?>
521 <?php else: ?>
522 <?php
523 $emptyText = esc_html__('No Payment method is activated for this site yet.', 'fluent-cart');
524 if (current_user_can('manage_options')) {
525 $emptyText .= '<a href="' . esc_url(URL::getDashboardUrl('settings/payments')) . '" target="_blank">' . esc_html__('Activate from settings.', 'fluent-cart') . '</a>';
526 }
527 echo '<div class="fct-empty-state">' . wp_kses_post($emptyText) . '</div>';
528 ?>
529 <?php endif; ?>
530 </div>
531
532 <!-- Payment Method Content -->
533 <div class="fct_payment_method_contents">
534 <?php foreach ($activePaymentMethods as $method) {
535 $this->renderPaymentMethodContent($method, [
536 'style' => $checkoutMethodStyle
537 ]);
538 } ?>
539 </div>
540
541
542
543 </div>
544 <?php
545 }
546
547
548 public function renderPaymentMethod($method, $config = [])
549 {
550 $route = $method->getMeta('route');
551 $methodTitle = $method->getMeta('title');
552 $methodStyle = Arr::get($config, 'style', 'logo');
553
554 $inputAttributes = array_filter([
555 'class' => 'form-radio-input',
556 'type' => 'radio',
557 'name' => '_fct_pay_method',
558 'id' => 'fluent_cart_payment_method_' . $route,
559 'value' => $route,
560 'required' => true,
561 'checked' => $route === Arr::get($config, 'selected_id', '') ? 'true' : '',
562 'role' => Arr::get($config, 'role', 'radio'),
563 'aria-checked' => Arr::get($config, 'aria_checked', 'false'),
564 ]);
565
566 $wrapperClass = $methodStyle === 'logo' ? 'fct_payment_method_logo' : 'fct_payment_method';
567
568 $wrapperAttributes = [
569 'class' => $wrapperClass . ' ' . 'fct_payment_method_wrapper fct_payment_method_' . $route,
570 'tabindex' => '0',
571 'role' => 'presentation'
572 ];
573
574 ?>
575 <div <?php RenderHelper::renderAtts($wrapperAttributes); ?>>
576 <span class="fct-payment-method-loader">
577 <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24">
578 <circle cx="12" cy="12" r="10" opacity="0.2" fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="2.5"></circle>
579
580 <path d="m12,2c5.52,0,10,4.48,10,10" fill="none" stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2.5">
581 <animateTransform attributeName="transform" attributeType="XML" type="rotate" dur="0.5s" from="0 12 12" to="360 12 12" repeatCount="indefinite"></animateTransform>
582 </path>
583 </svg>
584 </span>
585
586 <input <?php RenderHelper::renderAtts($inputAttributes); ?>/>
587
588 <label for="<?php echo esc_attr('fluent_cart_payment_method_' . $route); ?>">
589 <?php
590 if ($methodStyle === 'logo') {
591 $method->prepare('logo', $this->hasSubscription);
592 } else {
593 $method->prepare('radio', $this->hasSubscription);
594 }
595 ?>
596
597 <?php echo esc_html($methodTitle); ?>
598 </label>
599 </div>
600 <?php
601 }
602
603 public function renderPaymentMethodContent($method, $config = []) {
604 $route = $method->getMeta('route');
605 $methodTitle = $method->getMeta('title');
606 $methodStyle = Arr::get($config, 'style', 'logo');
607 $pmContext = [
608 'route' => $route,
609 'method_title' => $methodTitle,
610 'method_style' => $methodStyle,
611 ];
612 $paymentMethodClass = apply_filters_deprecated('fluent_cart_payment_method_list_class', ['', $pmContext], '1.3.16', 'fluent_cart/payment_method_list_class', 'Use fluent_cart/payment_method_list_class instead of fluent_cart_payment_method_list_class.');
613 $paymentMethodClass = apply_filters('fluent_cart/payment_method_list_class', $paymentMethodClass, $pmContext);
614
615 ?>
616 <div class="fluent-cart-checkout_embed_payment_wrapper">
617 <?php if ($method->getMeta('instructions')): ?>
618 <div class="fct-modal-payment-method-instructions">
619 <?php echo wp_kses_post($method->getMeta('instructions')); ?>
620 </div>
621 <?php endif; ?>
622
623 <div class="<?php echo "fluent-cart-checkout_embed_payment_container fluent-cart-checkout_embed_payment_container_" . esc_attr($route . ' ' . $paymentMethodClass); ?>"
624 aria-hidden="true">
625 <?php do_action(
626 'fluent_cart/checkout_embed_payment_method_content',
627 [
628 'method' => $method,
629 'cart' => $this->cart,
630 'route' => $route
631 ]
632 ); ?>
633 </div>
634 </div>
635
636 <?php
637 }
638
639
640
641
642
643
644
645
646
647
648 }
649