PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
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 / ShortCodeParser / Parsers / SubscriptionParser.php

SubscriptionParser.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.5, at app/Services/ShortCodeParser/Parsers/SubscriptionParser.php

71 lines 2.6 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\ShortCodeParser\Parsers;
4
5 use FluentCart\App\Helpers\Helper;
6 use FluentCart\App\Services\DateTime\DateFormatter;
7 use FluentCart\Framework\Support\Arr;
8
9 class SubscriptionParser extends BaseParser
10 {
11 private $subscription;
12
13 /**
14 * Only used as the timezone context for DateFormatter — the order carries the
15 * user_tz captured at checkout. Null when the shortcode runs without one, in
16 * which case DateFormatter falls back to UTC.
17 */
18 private $order;
19
20 public function __construct($data)
21 {
22 $this->subscription = Arr::get($data, 'subscription');
23 $this->order = Arr::get($data, 'order');
24 parent::__construct($data);
25 }
26
27 public function parse($accessor = null, $code = null, $transformer = null): ?string
28 {
29 $subscription = $this->subscription;
30
31 if (!$subscription) {
32 return '';
33 }
34
35 switch ($accessor) {
36 case 'sl':
37 return (string) (isset($subscription->sl) ? $subscription->sl : '');
38 case 'item_name':
39 return esc_html($subscription->display_item_name);
40 case 'status':
41 return esc_html($subscription->status);
42 case 'billing_interval':
43 return esc_html($subscription->billing_interval);
44 case 'recurring_amount':
45 return $subscription->recurring_amount ? (string) ($subscription->recurring_amount / 100) : '0';
46 case 'recurring_amount_formatted':
47 return esc_html(Helper::toDecimal($subscription->recurring_amount));
48 case 'payment_info':
49 return wp_kses_post($subscription->payment_info);
50 case 'next_billing_date':
51 return $subscription->next_billing_date
52 ? esc_html(DateFormatter::format($subscription->next_billing_date, false, $this->order))
53 : __('N/A', 'fluent-cart');
54 case 'bill_times':
55 return $subscription->bill_times
56 ? esc_html($subscription->bill_times)
57 : __('Unlimited', 'fluent-cart');
58 case 'bill_count':
59 return esc_html($subscription->bill_count);
60 case 'trial_days':
61 return esc_html($subscription->trial_days ?: '0');
62 case 'expire_at':
63 return $subscription->expire_at
64 ? esc_html(DateFormatter::format($subscription->expire_at, false, $this->order))
65 : __('Never', 'fluent-cart');
66 default:
67 return Arr::get((array) $subscription, $accessor, '');
68 }
69 }
70 }
71