PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.0
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.0
1.7.0 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 All 50 releases
fluent-cart / app / Helpers / Status.php

Status.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.7.0, at app/Helpers/Status.php

567 lines 20.1 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\Helpers;
4
5 class Status
6 {
7 // product statuses: publish, draft, pending, private, future
8 public const PRODUCT_PUBLISH = 'publish';
9 public const PRODUCT_DRAFT = 'draft';
10 public const PRODUCT_PRIVATE = 'private';
11 public const PRODUCT_FUTURE = 'future';
12 public const PRODUCT_TRASH = 'trash';
13
14 // Order Statuses
15 public const ORDER_PROCESSING = 'processing';
16 public const ORDER_COMPLETED = 'completed';
17 public const ORDER_ON_HOLD = 'on-hold';
18 public const ORDER_CANCELED = 'canceled';
19 public const ORDER_FAILED = 'failed';
20
21 public const ORDER_MODE_TEST = 'test';
22 public const ORDER_MODE_LIVE = 'live';
23
24 // Payment Statuses
25 public const PAYMENT_PENDING = 'pending';
26 public const PAYMENT_PAID = 'paid';
27 public const PAYMENT_PARTIALLY_PAID = 'partially_paid';
28 public const PAYMENT_FAILED = 'failed';
29 public const PAYMENT_REFUNDED = 'refunded';
30 public const PAYMENT_PARTIALLY_REFUNDED = 'partially_refunded';
31 public const PAYMENT_AUTHORIZED = 'authorized';
32 public const PAYMENT_SCHEDULED = 'payment_scheduled';
33
34 // Transaction Statuses
35 // Product review statuses — fct_product_reviews.status values
36 public const REVIEW_APPROVED = 'approved';
37 public const REVIEW_PENDING = 'pending';
38 public const REVIEW_SPAM = 'spam';
39 public const REVIEW_TRASH = 'trash';
40
41 // Review permission modes — who may submit a review
42 public const REVIEW_PERMISSION_VERIFIED_BUYERS = 'verified_buyers';
43 public const REVIEW_PERMISSION_LOGGED_IN = 'logged_in';
44 public const REVIEW_PERMISSION_ANYONE = 'anyone';
45
46 public const TRANSACTION_SUCCEEDED = 'succeeded';
47 public const TRANSACTION_AUTHORIZED = 'authorized';
48 public const TRANSACTION_PENDING = 'pending';
49 public const TRANSACTION_REFUNDED = 'refunded';
50 public const TRANSACTION_FAILED = 'failed';
51 public const TRANSACTION_DISPUTE_LOST = 'dispute_lost';
52
53
54 // Transaction table transaction_type status
55 public const TRANSACTION_TYPE_CHARGE = 'charge';
56 public const TRANSACTION_TYPE_REFUND = 'refund';
57 public const TRANSACTION_TYPE_DISPUTE = 'dispute';
58
59 // todo: will remove after some necessary test
60 public const TRANSACTION_TYPE_SIGNUP = 'signup_fee';
61
62 // Subscription Statuses
63 public const SUBSCRIPTION_PENDING = 'pending';
64 public const SUBSCRIPTION_INTENDED = 'intended';
65 public const SUBSCRIPTION_TRIALING = 'trialing';
66 public const SUBSCRIPTION_ACTIVE = 'active';
67
68 public const SUBSCRIPTION_CANCELED = 'canceled';
69 public const SUBSCRIPTION_PAUSED = 'paused';
70 public const SUBSCRIPTION_PAST_DUE = 'past_due';
71 public const SUBSCRIPTION_EXPIRED = 'expired';
72 public const SUBSCRIPTION_FAILING = 'failing';
73 public const SUBSCRIPTION_EXPIRING = 'expiring';
74 public const SUBSCRIPTION_COMPLETED = 'completed';
75 public const SUBSCRIPTION_AUTHENTICATED = 'authenticated';
76 public const SUBSCRIPTION_CREATED = 'created';
77
78 public const SUBSCRIPTION_METHOD_MANUAL = 'manual';
79 public const SUBSCRIPTION_METHOD_AUTOMATIC = 'automatic';
80 public const SUBSCRIPTION_METHOD_SYSTEM = 'system';
81
82 // billing interval
83 public const BILLING_YEARLY = 'yearly';
84 public const BILLING_HALF_YEARLY = 'half_yearly';
85 public const BILLING_QUARTERLY = 'quarterly';
86 public const BILLING_MONTHLY = 'monthly';
87 public const BILLING_WEEKLY = 'weekly';
88 public const BILLING_DAILY = 'daily';
89
90 // Shipping Statuses
91 public const SHIPPING_UNSHIPPED = 'unshipped';
92 public const SHIPPING_SHIPPED = 'shipped';
93 public const SHIPPING_DELIVERED = 'delivered';
94 public const SHIPPING_UNSHIPPABLE = 'unshippable';
95
96 // Customer Statuses
97 public const CUSTOMER_ACTIVE = 'active';
98 public const CUSTOMER_INACTIVE = 'inactive';
99
100 // Stock Statuses
101 public const STOCK_INSTOCK = 'instock';
102 public const STOCK_OUTOFSTOCK = 'outofstock';
103 public const STOCK_ONBACKORDER = 'onbackorder';
104
105
106 public const SCHEDULE_PENDING = 'pending';
107 public const SCHEDULE_COMPLETED = 'completed';
108 public const SCHEDULE_FAILED = 'failed';
109
110 public const SCHEDULE_PROCESSING = 'processing';
111
112 public const LICENSE_ACTIVE = 'active';
113 public const LICENSE_DISABLED = 'disabled';
114 public const LICENSE_EXPIRED = 'expired';
115
116 public const FULFILLMENT_TYPE_PHYSICAL = 'physical';
117 public const FULFILLMENT_TYPE_DIGITAL = 'digital';
118
119 public const ORDER_TYPE_PAYMENT = 'payment';
120 public const ORDER_TYPE_SUBSCRIPTION = 'subscription';
121 public const ORDER_TYPE_RENEWAL = 'renewal';
122
123
124 public static function getProductStatuses($withLabel = true)
125 {
126 return apply_filters('fluent_cart/product_statuses', [
127 self::PRODUCT_PUBLISH => __('Publish', 'fluent-cart'),
128 self::PRODUCT_DRAFT => __('Draft', 'fluent-cart'),
129 self::PRODUCT_PRIVATE => __('Private', 'fluent-cart'),
130 self::PRODUCT_FUTURE => __('Scheduled', 'fluent-cart'),
131 self::PRODUCT_TRASH => __('Trashed', 'fluent-cart'),
132 ], []);
133
134 if ($withLabel) {
135 return $statues;
136 }
137
138 return array_keys($statues);
139 }
140
141 public static function getScheduleStatus($status): string
142 {
143 $statuses = [
144 'pending' => Status::SCHEDULE_PENDING,
145 'processing' => Status::SCHEDULE_PROCESSING,
146 'completed' => Status::SCHEDULE_COMPLETED,
147 'failed' => Status::SCHEDULE_FAILED,
148 ];
149
150 return $statuses[$status] ?? Status::SCHEDULE_PENDING;
151 }
152
153 public static function getLicenseStatus($status): string
154 {
155 $statuses = [
156 'active' => Status::LICENSE_ACTIVE,
157 'disabled' => Status::LICENSE_DISABLED,
158 'expired' => Status::LICENSE_EXPIRED,
159 ];
160
161 return $statuses[$status] ?? Status::LICENSE_ACTIVE;
162 }
163
164 public static function productAdminAllStatuses()
165 {
166 $statuses = self::getProductStatuses();
167 unset($statuses[self::PRODUCT_TRASH]);
168 return array_keys($statuses);
169 }
170
171
172 // Order statuses
173 public static function getOrderStatuses()
174 {
175 return apply_filters('fluent_cart/order_statuses', [
176 self::ORDER_PROCESSING => __('Processing', 'fluent-cart'),
177 self::ORDER_COMPLETED => __('Completed', 'fluent-cart'),
178 self::ORDER_ON_HOLD => __('On Hold', 'fluent-cart'),
179 self::ORDER_CANCELED => __('Canceled', 'fluent-cart'),
180 self::ORDER_FAILED => __('Failed', 'fluent-cart'),
181 ], []);
182 }
183
184 public static function getEditableOrderStatuses()
185 {
186 $statuses = [
187 self::ORDER_ON_HOLD => __('On Hold', 'fluent-cart'),
188 self::ORDER_PROCESSING => __('Processing', 'fluent-cart'),
189 self::ORDER_COMPLETED => __('Completed', 'fluent-cart'),
190 // 'archived' => __('Archived', 'fluent-cart'),
191 self::ORDER_CANCELED => __('Canceled', 'fluent-cart')
192 ];
193
194 return apply_filters('fluent_cart/editable_order_statuses', $statuses, []);
195 }
196
197
198 // Payment statuses
199 public static function getPaymentStatuses()
200 {
201 return apply_filters('fluent_cart/payment_statuses', [
202 self::PAYMENT_PENDING => __('Pending', 'fluent-cart'),
203 self::PAYMENT_PAID => __('Paid', 'fluent-cart'),
204 self::PAYMENT_PARTIALLY_PAID => __('Partially Paid', 'fluent-cart'),
205 self::PAYMENT_FAILED => __('Failed', 'fluent-cart'),
206 self::PAYMENT_REFUNDED => __('Refunded', 'fluent-cart'),
207 self::PAYMENT_PARTIALLY_REFUNDED => __('Partially Refunded', 'fluent-cart'),
208 self::PAYMENT_AUTHORIZED => __('Authorized', 'fluent-cart'),
209 self::PAYMENT_SCHEDULED => __('Payment Scheduled', 'fluent-cart'),
210 ], []);
211 }
212
213 // Transaction statuses
214 public static function getTransactionStatuses($withLabel = true)
215 {
216 return apply_filters('fluent_cart/transaction_statuses', [
217 self::TRANSACTION_PENDING => __('Pending', 'fluent-cart'),
218 self::TRANSACTION_SUCCEEDED => __('Succeeded', 'fluent-cart'),
219 self::TRANSACTION_AUTHORIZED => __('Authorized', 'fluent-cart'),
220 self::TRANSACTION_FAILED => __('Failed', 'fluent-cart'),
221 self::TRANSACTION_REFUNDED => __('Refunded', 'fluent-cart'),
222 ], []);
223
224 if ($withLabel) {
225 return $statuses;
226 }
227
228 return array_keys($statuses);
229 }
230
231 public static function getEditableTransactionStatuses($withLabel = true)
232 {
233 $statuses = [
234 self::TRANSACTION_PENDING => __('Pending', 'fluent-cart'),
235 self::TRANSACTION_SUCCEEDED => __('Succeeded', 'fluent-cart'),
236 self::TRANSACTION_AUTHORIZED => __('Authorized', 'fluent-cart'),
237 self::TRANSACTION_FAILED => __('Failed', 'fluent-cart'),
238 self::TRANSACTION_REFUNDED => __('Refunded', 'fluent-cart'),
239 ];
240
241 $statuses = apply_filters('fluent_cart/editable_transaction_statuses', $statuses, []);
242
243 if ($withLabel) {
244 return $statuses;
245 }
246
247 return array_keys($statuses);
248 }
249
250 // Shipping statuses
251 public static function getShippingStatuses()
252 {
253 return apply_filters('fluent_cart/shipping_statuses', [
254 self::SHIPPING_UNSHIPPED => __('Unshipped', 'fluent-cart'),
255 self::SHIPPING_SHIPPED => __('Shipped', 'fluent-cart'),
256 self::SHIPPING_DELIVERED => __('Delivered', 'fluent-cart'),
257 self::SHIPPING_UNSHIPPABLE => __('Unshippable', 'fluent-cart'),
258 ], []);
259 }
260
261 public static function getEditableShippingStatuses()
262 {
263 $statuses = [
264 self::SHIPPING_UNSHIPPED => __('Unshipped', 'fluent-cart'),
265 self::SHIPPING_SHIPPED => __('Shipped', 'fluent-cart'),
266 self::SHIPPING_DELIVERED => __('Delivered', 'fluent-cart'),
267 self::SHIPPING_UNSHIPPABLE => __('Unshippable', 'fluent-cart'),
268 ];
269
270 return apply_filters('fluent_cart/editable_shipping_statuses', $statuses, []);
271 }
272
273 // Subscription statuses
274 public static function getSubscriptionStatuses()
275 {
276 return apply_filters('fluent_cart/subscription_statuses', [
277 self::SUBSCRIPTION_PENDING => __('Pending', 'fluent-cart'),
278 self::SUBSCRIPTION_ACTIVE => __('Active', 'fluent-cart'),
279 self::SUBSCRIPTION_FAILING => __('Failing', 'fluent-cart'),
280 self::SUBSCRIPTION_PAUSED => __('Paused', 'fluent-cart'),
281 self::SUBSCRIPTION_EXPIRED => __('Expired', 'fluent-cart'),
282 self::SUBSCRIPTION_EXPIRING => __('Expiring', 'fluent-cart'),
283 self::SUBSCRIPTION_CANCELED => __('Canceled', 'fluent-cart'),
284 self::SUBSCRIPTION_TRIALING => __('Trialing', 'fluent-cart'),
285 self::SUBSCRIPTION_INTENDED => __('Intended', 'fluent-cart'),
286 self::SUBSCRIPTION_PAST_DUE => __('Past Due', 'fluent-cart'),
287 self::SUBSCRIPTION_COMPLETED => __('Completed', 'fluent-cart'),
288 ], []);
289 }
290
291 // Get Validable Subscription Statuses
292 public static function getValidableSubscriptionStatuses()
293 {
294 return apply_filters('fluent_cart/validable_subscription_statuses', [
295 self::SUBSCRIPTION_ACTIVE,
296 self::SUBSCRIPTION_TRIALING,
297 ], []);
298 }
299
300
301 // Stock statuses
302 public static function getStockStatuses($withLabel = true)
303 {
304 $statues = [
305 self::STOCK_INSTOCK => __('In Stock', 'fluent-cart'),
306 self::STOCK_OUTOFSTOCK => __('Out Of Stock', 'fluent-cart'),
307 ];
308
309 if ($withLabel) {
310 return $statues;
311 }
312
313 return array_keys($statues);
314 }
315
316 public static function getOrderSuccessStatuses()
317 {
318 return [
319 self::ORDER_COMPLETED,
320 self::ORDER_PROCESSING,
321 ];
322 }
323
324 public static function getOrderFailedStatuses()
325 {
326 return [
327 self::ORDER_FAILED,
328 //'refunded',
329 self::ORDER_CANCELED,
330 ];
331 }
332
333 public static function getOrderPaymentSuccessStatuses()
334 {
335 return [
336 self::PAYMENT_PAID,
337 self::PAYMENT_PARTIALLY_REFUNDED,
338 self::PAYMENT_PARTIALLY_PAID,
339 ];
340 }
341
342 public static function getPaymentRetryableStatuses()
343 {
344 return [
345 self::PAYMENT_PENDING,
346 self::PAYMENT_FAILED
347 ];
348 }
349
350 public static function getReportStatuses()
351 {
352 return [
353 self::PAYMENT_PAID,
354 self::PAYMENT_REFUNDED,
355 self::PAYMENT_PARTIALLY_PAID,
356 self::PAYMENT_PARTIALLY_REFUNDED,
357 ];
358 }
359
360 public static function getTransactionSuccessStatuses()
361 {
362 return apply_filters('fluent_cart/transaction_success_statuses', [self::TRANSACTION_SUCCEEDED, self::TRANSACTION_AUTHORIZED], []);
363 }
364
365 /**
366 * All product review statuses (fct_product_reviews.status values).
367 */
368 public static function getReviewStatuses(): array
369 {
370 return [
371 self::REVIEW_APPROVED,
372 self::REVIEW_PENDING,
373 self::REVIEW_SPAM,
374 self::REVIEW_TRASH,
375 ];
376 }
377
378 /**
379 * Review statuses that count as an existing review for duplicate
380 * detection. Spam and trash are deliberately excluded — a review the
381 * store rejected does not block the customer from submitting a fresh
382 * one. Every surface that projects "can this user review?" must use
383 * this set so it never contradicts the
384 * ProductReviewService::canSubmitReview() write-path guard.
385 */
386 public static function getReviewDuplicateStatuses(): array
387 {
388 return apply_filters('fluent_cart/review_duplicate_statuses', [
389 self::REVIEW_APPROVED,
390 self::REVIEW_PENDING,
391 ]);
392 }
393
394 /**
395 * Review statuses the author may see in their own history: everything
396 * except spam and trash.
397 *
398 * Derived by exclusion, not by listing, so a status added later is
399 * visible to its author by default — only the two that mean "this is not
400 * really a review" are held back, and a customer who has been silently
401 * spammed or trashed is not shown that judgement.
402 *
403 * Deliberately NOT getReviewDuplicateStatuses(). The two sets happen to
404 * hold the same values today, but they answer different questions, and
405 * that one is filterable: a site narrowing its duplicate rules would
406 * otherwise hide customers' pending reviews from them as a side effect.
407 *
408 * @return array
409 */
410 public static function getReviewAuthorVisibleStatuses(): array
411 {
412 return array_values(array_diff(
413 static::getReviewStatuses(),
414 [self::REVIEW_SPAM, self::REVIEW_TRASH]
415 ));
416 }
417
418 // Get all statuses (optional utility)
419 public static function all()
420 {
421 return [
422 'product' => self::getProductStatuses(),
423 'order' => self::getOrderStatuses(),
424 'payment' => self::getPaymentStatuses(),
425 'transaction' => self::getTransactionStatuses(),
426 'shipping' => self::getShippingStatuses(),
427 'customer' => self::getEditableCustomerStatuses(),
428 'subscription' => self::getSubscriptionStatuses(),
429 ];
430 }
431
432 public static function getEditableCustomerStatuses()
433 {
434 $statuses = [
435 self::CUSTOMER_ACTIVE => __('Active', 'fluent-cart'),
436 self::CUSTOMER_INACTIVE => __('Inactive', 'fluent-cart'),
437 ];
438
439 return apply_filters('fluent_cart/editable_customer_statuses', $statuses, []);
440 }
441
442 // call when syncing status from external services, ex:
443 public static function syncPaymentStatus($status)
444 {
445 $status = strtolower($status);
446 $statuses = self::getPaymentStatuses();
447
448 if (isset($statuses[$status])) {
449 return $status;
450 }
451
452 if ('completed' === $status) {
453 return self::PAYMENT_PAID;
454 }
455
456 if ('succeeded' === $status) {
457 return self::PAYMENT_PAID;
458 }
459
460 return $status;
461 }
462
463 public static function syncTransactionStatus($status)
464 {
465 $status = strtolower($status);
466 $statuses = self::getTransactionStatuses();
467
468 if (isset($statuses[$status])) {
469 return $status;
470 }
471
472 if ('paid' === $status) {
473 return self::TRANSACTION_SUCCEEDED;
474 } else if ('succeeded' === $status) {
475 return self::TRANSACTION_SUCCEEDED;
476 }
477
478 return $status;
479 }
480
481 public static function syncSubscriptionStatus($status)
482 {
483 if ('cancelled' === $status || 'canceled' === $status) {
484 return self::SUBSCRIPTION_CANCELED;
485 }
486
487 return $status;
488 }
489
490 public static function eventTriggers(): array
491 {
492 return [
493 'require_list' => false,
494 'required' => true,
495 'key' => 'event_trigger',
496 'options' => [
497 'order' => [
498 'label' => __('Orders', 'fluent-cart'),
499 'options' => [
500 [
501 'value' => 'order_paid_done',
502 'label' => __('Order Paid (Payment / Subscription)', 'fluent-cart')
503 ],
504 [
505 'value' => 'order_status_changed_to_canceled',
506 'label' => __('Order Canceled', 'fluent-cart')
507 ],
508 [
509 'value' => 'order_fully_refunded',
510 'label' => __('Order Refunded (Full)', 'fluent-cart')
511 ]
512 ]
513 ],
514 'subscription' => [
515 'label' => __('Subscriptions', 'fluent-cart'),
516 'options' => [
517 [
518 'value' => 'subscription_activated',
519 'label' => __('Subscription Activated', 'fluent-cart')
520 ],
521 [
522 'value' => 'subscription_reactivated',
523 'label' => __('Subscription Reactivated', 'fluent-cart')
524 ],
525 [
526 'value' => 'subscription_canceled',
527 'label' => __('Subscription Canceled', 'fluent-cart')
528 ],
529 [
530 'value' => 'subscription_renewed',
531 'label' => __('Subscription Renewed', 'fluent-cart')
532 ],
533 [
534 'value' => 'subscription_eot',
535 'label' => __('Subscription End of Term (Completed)', 'fluent-cart')
536 ],
537 [
538 'value' => 'subscription_expired_validity',
539 'label' => __('Subscription Expired / End of Access Validity', 'fluent-cart')
540 ]
541 ]
542 ],
543 'product' => [
544 'label' => __('Shipping', 'fluent-cart'),
545 'options' => [
546 [
547 'value' => 'shipping_status_changed_to_shipped',
548 'label' => __('Order Shipped', 'fluent-cart')
549 ],
550 [
551 'value' => 'shipping_status_changed_to_delivered',
552 'label' => __('Order Delivered', 'fluent-cart')
553 ]
554 ]
555 ]
556 ],
557 'inline_tip' => __('Select in which event you want to trigger this feed', 'fluent-cart'),
558 'label' => __('Event Trigger', 'fluent-cart'),
559 'placeholder' => __('Select Event', 'fluent-cart'),
560 'component' => 'selection_group',
561 'checkbox_label' => __('Event Trigger For This Feed', 'fluent-cart'),
562 ];
563 }
564
565 // Additional statuses can be added here as needed
566 }
567