| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services\ShortCodeParser\Parsers; |
| 4 |
|
| 5 |
use FluentCart\App\Helpers\Helper; |
| 6 |
use FluentCart\Framework\Support\Arr; |
| 7 |
|
| 8 |
class SubscriptionParser extends BaseParser |
| 9 |
{ |
| 10 |
private $subscription; |
| 11 |
|
| 12 |
public function __construct($data) |
| 13 |
{ |
| 14 |
$this->subscription = Arr::get($data, 'subscription'); |
| 15 |
parent::__construct($data); |
| 16 |
} |
| 17 |
|
| 18 |
public function parse($accessor = null, $code = null, $transformer = null): ?string |
| 19 |
{ |
| 20 |
$subscription = $this->subscription; |
| 21 |
|
| 22 |
if (!$subscription) { |
| 23 |
return ''; |
| 24 |
} |
| 25 |
|
| 26 |
switch ($accessor) { |
| 27 |
case 'sl': |
| 28 |
return (string) (isset($subscription->sl) ? $subscription->sl : ''); |
| 29 |
case 'item_name': |
| 30 |
return esc_html($subscription->display_item_name); |
| 31 |
case 'status': |
| 32 |
return esc_html($subscription->status); |
| 33 |
case 'billing_interval': |
| 34 |
return esc_html($subscription->billing_interval); |
| 35 |
case 'recurring_amount': |
| 36 |
return $subscription->recurring_amount ? (string) ($subscription->recurring_amount / 100) : '0'; |
| 37 |
case 'recurring_amount_formatted': |
| 38 |
return esc_html(Helper::toDecimal($subscription->recurring_amount)); |
| 39 |
case 'payment_info': |
| 40 |
return wp_kses_post($subscription->payment_info); |
| 41 |
case 'next_billing_date': |
| 42 |
return $subscription->next_billing_date |
| 43 |
? esc_html(date('M j, Y', strtotime($subscription->next_billing_date))) |
| 44 |
: __('N/A', 'fluent-cart'); |
| 45 |
case 'bill_times': |
| 46 |
return $subscription->bill_times |
| 47 |
? esc_html($subscription->bill_times) |
| 48 |
: __('Unlimited', 'fluent-cart'); |
| 49 |
case 'bill_count': |
| 50 |
return esc_html($subscription->bill_count); |
| 51 |
case 'trial_days': |
| 52 |
return esc_html($subscription->trial_days ?: '0'); |
| 53 |
case 'expire_at': |
| 54 |
return $subscription->expire_at |
| 55 |
? esc_html(date('M j, Y', strtotime($subscription->expire_at))) |
| 56 |
: __('Never', 'fluent-cart'); |
| 57 |
default: |
| 58 |
return Arr::get((array) $subscription, $accessor, ''); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|