| @@ -24,10 +24,11 @@ | ||
| 24 | 24 | class SubscriptionTools |
| 25 | 25 | { |
| 26 | 26 | public static function definitions() |
| 27 | 27 | { |
| 28 | - $statuses = ContextTools::ENUMS['subscription_statuses']; | |
| 29 | - $intervals = ContextTools::ENUMS['billing_intervals']; | |
| 28 | + $enums = ContextTools::enums(); | |
| 29 | + $statuses = $enums['subscription_statuses']; | |
| 30 | + $intervals = $enums['billing_intervals']; | |
| 30 | 31 | |
| 31 | 32 | return [ |
| 32 | 33 | 'fluent-cart/list-subscriptions' => [ |
| 33 | 34 | 'label' => __('List Subscriptions', 'fluent-cart'), |
| @@ -49,9 +50,9 @@ | ||
| 49 | 50 | 'min_recurring' => ['type' => 'number', 'description' => 'Minimum recurring total in store currency.'], |
| 50 | 51 | 'advanced_filters' => ['type' => 'array', 'items' => ['type' => ['object', 'array']], 'description' => 'Pro: condition groups {property, operator, value} — outer array = OR groups, inner = AND. Call get-search-schema entity=subscriptions FIRST for properties/operators/format. AND-combines with the other filters here (summary_only included). An empty array means no advanced filter.'], |
| 51 | 52 | 'sort_by' => ['type' => 'string', 'enum' => ['id', 'next_billing_date', 'created_at', 'canceled_at', 'recurring_total'], 'default' => 'id'], |
| 52 | 53 | 'sort_type' => ['type' => 'string', 'enum' => ['ASC', 'DESC'], 'default' => 'DESC'], |
| 53 | - 'fields' => ['type' => 'array', 'items' => ['type' => 'string'], 'description' => 'Optional: return only these row keys to shrink the payload (subscription_id is always kept). Available: status, item_name, customer, recurring_total, billing_interval, next_billing_date, created_at, canceled_at, bill_count, bill_times, is_installment, installments_paid, installments_remaining, total_contract_value, currency, label. Omit for the full row.'], | |
| 54 | + 'fields' => ['type' => 'array', 'items' => ['type' => 'string'], 'description' => 'Optional: return only these row keys to shrink the payload (subscription_id is always kept). Available: status, item_name, customer, recurring_total, billing_interval, next_billing_date, created_at, canceled_at, bill_count, bill_times, plan_type, is_installment, installments_paid, installments_remaining, total_contract_value, currency, label. Omit for the full row.'], | |
| 54 | 55 | 'summary_only' => ['type' => 'boolean', 'description' => 'When true, return ONLY aggregates across all matching subscriptions — count_by_status, summed recurring_total, and total remaining installments — with no per-record array. Answers "how many active subs and how much is committed" with a tiny payload. Honors all the filters above.'], |
| 55 | 56 | 'page' => ['type' => 'integer', 'default' => 1], |
| 56 | 57 | 'per_page' => ['type' => 'integer', 'default' => 15, 'description' => 'Max 200.'], |
| 57 | 58 | ], |
| @@ -289,8 +290,11 @@ | ||
| 289 | 290 | 'bill_count' => (int) $sub->bill_count, |
| 290 | 291 | 'bill_times' => (int) $sub->bill_times, |
| 291 | 292 | // Derived installment view (bill_times > 0). total_contract_value is |
| 292 | 293 | // null for open-ended plans, which have no fixed committed total. |
| 294 | + // plan_type names the same distinction using the plan_types enum from | |
| 295 | + // get-store-context, so the enum, the filter and the row all agree. | |
| 296 | + 'plan_type' => $isInstallment ? 'installment' : 'recurring', | |
| 293 | 297 | 'is_installment' => $isInstallment, |
| 294 | 298 | 'installments_paid' => (int) $sub->bill_count, |
| 295 | 299 | 'installments_remaining' => $sub->installmentsRemaining(), |
| 296 | 300 | 'total_contract_value' => $isInstallment ? MCPHelper::money($sub->totalContractValue(), $currency) : null, |
| @@ -346,8 +350,9 @@ | ||
| 346 | 350 | 'recurring_total' => MCPHelper::money($sub->recurring_total, $currency), |
| 347 | 351 | 'bill_times' => (int) $sub->bill_times, |
| 348 | 352 | 'bill_count' => (int) $sub->bill_count, |
| 349 | 353 | 'collection_method' => $sub->collection_method, |
| 354 | + 'plan_type' => $sub->isInstallment() ? 'installment' : 'recurring', | |
| 350 | 355 | 'is_installment' => $sub->isInstallment(), |
| 351 | 356 | 'installments_paid' => (int) $sub->bill_count, |
| 352 | 357 | 'installments_remaining' => $sub->installmentsRemaining(), |
| 353 | 358 | 'total_contract_value' => $sub->isInstallment() ? MCPHelper::money($sub->totalContractValue(), $currency) : null, |