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

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

503 lines 17.7 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 public const TRANSACTION_SUCCEEDED = 'succeeded';
36 public const TRANSACTION_AUTHORIZED = 'authorized';
37 public const TRANSACTION_PENDING = 'pending';
38 public const TRANSACTION_REFUNDED = 'refunded';
39 public const TRANSACTION_FAILED = 'failed';
40 public const TRANSACTION_DISPUTE_LOST = 'dispute_lost';
41
42
43 // Transaction table transaction_type status
44 public const TRANSACTION_TYPE_CHARGE = 'charge';
45 public const TRANSACTION_TYPE_REFUND = 'refund';
46 public const TRANSACTION_TYPE_DISPUTE = 'dispute';
47
48 // todo: will remove after some necessary test
49 public const TRANSACTION_TYPE_SIGNUP = 'signup_fee';
50
51 // Subscription Statuses
52 public const SUBSCRIPTION_PENDING = 'pending';
53 public const SUBSCRIPTION_INTENDED = 'intended';
54 public const SUBSCRIPTION_TRIALING = 'trialing';
55 public const SUBSCRIPTION_ACTIVE = 'active';
56
57 public const SUBSCRIPTION_CANCELED = 'canceled';
58 public const SUBSCRIPTION_PAUSED = 'paused';
59 public const SUBSCRIPTION_PAST_DUE = 'past_due';
60 public const SUBSCRIPTION_EXPIRED = 'expired';
61 public const SUBSCRIPTION_FAILING = 'failing';
62 public const SUBSCRIPTION_EXPIRING = 'expiring';
63 public const SUBSCRIPTION_COMPLETED = 'completed';
64 public const SUBSCRIPTION_AUTHENTICATED = 'authenticated';
65 public const SUBSCRIPTION_CREATED = 'created';
66
67 public const SUBSCRIPTION_METHOD_MANUAL = 'manual';
68 public const SUBSCRIPTION_METHOD_AUTOMATIC = 'automatic';
69 public const SUBSCRIPTION_METHOD_SYSTEM = 'system';
70
71 // billing interval
72 public const BILLING_YEARLY = 'yearly';
73 public const BILLING_HALF_YEARLY = 'half_yearly';
74 public const BILLING_QUARTERLY = 'quarterly';
75 public const BILLING_MONTHLY = 'monthly';
76 public const BILLING_WEEKLY = 'weekly';
77 public const BILLING_DAILY = 'daily';
78
79 // Shipping Statuses
80 public const SHIPPING_UNSHIPPED = 'unshipped';
81 public const SHIPPING_SHIPPED = 'shipped';
82 public const SHIPPING_DELIVERED = 'delivered';
83 public const SHIPPING_UNSHIPPABLE = 'unshippable';
84
85 // Customer Statuses
86 public const CUSTOMER_ACTIVE = 'active';
87 public const CUSTOMER_INACTIVE = 'inactive';
88
89 // Stock Statuses
90 public const STOCK_INSTOCK = 'instock';
91 public const STOCK_OUTOFSTOCK = 'outofstock';
92 public const STOCK_ONBACKORDER = 'onbackorder';
93
94
95 public const SCHEDULE_PENDING = 'pending';
96 public const SCHEDULE_COMPLETED = 'completed';
97 public const SCHEDULE_FAILED = 'failed';
98
99 public const SCHEDULE_PROCESSING = 'processing';
100
101 public const LICENSE_ACTIVE = 'active';
102 public const LICENSE_DISABLED = 'disabled';
103 public const LICENSE_EXPIRED = 'expired';
104
105 public const FULFILLMENT_TYPE_PHYSICAL = 'physical';
106 public const FULFILLMENT_TYPE_DIGITAL = 'digital';
107
108 public const ORDER_TYPE_PAYMENT = 'payment';
109 public const ORDER_TYPE_SUBSCRIPTION = 'subscription';
110 public const ORDER_TYPE_RENEWAL = 'renewal';
111
112
113 public static function getProductStatuses($withLabel = true)
114 {
115 return apply_filters('fluent_cart/product_statuses', [
116 self::PRODUCT_PUBLISH => __('Publish', 'fluent-cart'),
117 self::PRODUCT_DRAFT => __('Draft', 'fluent-cart'),
118 self::PRODUCT_PRIVATE => __('Private', 'fluent-cart'),
119 self::PRODUCT_FUTURE => __('Scheduled', 'fluent-cart'),
120 self::PRODUCT_TRASH => __('Trashed', 'fluent-cart'),
121 ], []);
122
123 if ($withLabel) {
124 return $statues;
125 }
126
127 return array_keys($statues);
128 }
129
130 public static function getScheduleStatus($status): string
131 {
132 $statuses = [
133 'pending' => Status::SCHEDULE_PENDING,
134 'processing' => Status::SCHEDULE_PROCESSING,
135 'completed' => Status::SCHEDULE_COMPLETED,
136 'failed' => Status::SCHEDULE_FAILED,
137 ];
138
139 return $statuses[$status] ?? Status::SCHEDULE_PENDING;
140 }
141
142 public static function getLicenseStatus($status): string
143 {
144 $statuses = [
145 'active' => Status::LICENSE_ACTIVE,
146 'disabled' => Status::LICENSE_DISABLED,
147 'expired' => Status::LICENSE_EXPIRED,
148 ];
149
150 return $statuses[$status] ?? Status::LICENSE_ACTIVE;
151 }
152
153 public static function productAdminAllStatuses()
154 {
155 $statuses = self::getProductStatuses();
156 unset($statuses[self::PRODUCT_TRASH]);
157 return array_keys($statuses);
158 }
159
160
161 // Order statuses
162 public static function getOrderStatuses()
163 {
164 return apply_filters('fluent_cart/order_statuses', [
165 self::ORDER_PROCESSING => __('Processing', 'fluent-cart'),
166 self::ORDER_COMPLETED => __('Completed', 'fluent-cart'),
167 self::ORDER_ON_HOLD => __('On Hold', 'fluent-cart'),
168 self::ORDER_CANCELED => __('Canceled', 'fluent-cart'),
169 self::ORDER_FAILED => __('Failed', 'fluent-cart'),
170 ], []);
171 }
172
173 public static function getEditableOrderStatuses()
174 {
175 $statuses = [
176 self::ORDER_ON_HOLD => __('On Hold', 'fluent-cart'),
177 self::ORDER_PROCESSING => __('Processing', 'fluent-cart'),
178 self::ORDER_COMPLETED => __('Completed', 'fluent-cart'),
179 // 'archived' => __('Archived', 'fluent-cart'),
180 self::ORDER_CANCELED => __('Canceled', 'fluent-cart')
181 ];
182
183 return apply_filters('fluent_cart/editable_order_statuses', $statuses, []);
184 }
185
186
187 // Payment statuses
188 public static function getPaymentStatuses()
189 {
190 return apply_filters('fluent_cart/payment_statuses', [
191 self::PAYMENT_PENDING => __('Pending', 'fluent-cart'),
192 self::PAYMENT_PAID => __('Paid', 'fluent-cart'),
193 self::PAYMENT_PARTIALLY_PAID => __('Partially Paid', 'fluent-cart'),
194 self::PAYMENT_FAILED => __('Failed', 'fluent-cart'),
195 self::PAYMENT_REFUNDED => __('Refunded', 'fluent-cart'),
196 self::PAYMENT_PARTIALLY_REFUNDED => __('Partially Refunded', 'fluent-cart'),
197 self::PAYMENT_AUTHORIZED => __('Authorized', 'fluent-cart'),
198 self::PAYMENT_SCHEDULED => __('Payment Scheduled', 'fluent-cart'),
199 ], []);
200 }
201
202 // Transaction statuses
203 public static function getTransactionStatuses($withLabel = true)
204 {
205 return apply_filters('fluent_cart/transaction_statuses', [
206 self::TRANSACTION_PENDING => __('Pending', 'fluent-cart'),
207 self::TRANSACTION_SUCCEEDED => __('Succeeded', 'fluent-cart'),
208 self::TRANSACTION_AUTHORIZED => __('Authorized', 'fluent-cart'),
209 self::TRANSACTION_FAILED => __('Failed', 'fluent-cart'),
210 self::TRANSACTION_REFUNDED => __('Refunded', 'fluent-cart'),
211 ], []);
212
213 if ($withLabel) {
214 return $statuses;
215 }
216
217 return array_keys($statuses);
218 }
219
220 public static function getEditableTransactionStatuses($withLabel = true)
221 {
222 $statuses = [
223 self::TRANSACTION_PENDING => __('Pending', 'fluent-cart'),
224 self::TRANSACTION_SUCCEEDED => __('Succeeded', 'fluent-cart'),
225 self::TRANSACTION_AUTHORIZED => __('Authorized', 'fluent-cart'),
226 self::TRANSACTION_FAILED => __('Failed', 'fluent-cart'),
227 self::TRANSACTION_REFUNDED => __('Refunded', 'fluent-cart'),
228 ];
229
230 $statuses = apply_filters('fluent_cart/editable_transaction_statuses', $statuses, []);
231
232 if ($withLabel) {
233 return $statuses;
234 }
235
236 return array_keys($statuses);
237 }
238
239 // Shipping statuses
240 public static function getShippingStatuses()
241 {
242 return apply_filters('fluent_cart/shipping_statuses', [
243 self::SHIPPING_UNSHIPPED => __('Unshipped', 'fluent-cart'),
244 self::SHIPPING_SHIPPED => __('Shipped', 'fluent-cart'),
245 self::SHIPPING_DELIVERED => __('Delivered', 'fluent-cart'),
246 self::SHIPPING_UNSHIPPABLE => __('Unshippable', 'fluent-cart'),
247 ], []);
248 }
249
250 public static function getEditableShippingStatuses()
251 {
252 $statuses = [
253 self::SHIPPING_UNSHIPPED => __('Unshipped', 'fluent-cart'),
254 self::SHIPPING_SHIPPED => __('Shipped', 'fluent-cart'),
255 self::SHIPPING_DELIVERED => __('Delivered', 'fluent-cart'),
256 self::SHIPPING_UNSHIPPABLE => __('Unshippable', 'fluent-cart'),
257 ];
258
259 return apply_filters('fluent_cart/editable_shipping_statuses', $statuses, []);
260 }
261
262 // Subscription statuses
263 public static function getSubscriptionStatuses()
264 {
265 return apply_filters('fluent_cart/subscription_statuses', [
266 self::SUBSCRIPTION_PENDING => __('Pending', 'fluent-cart'),
267 self::SUBSCRIPTION_ACTIVE => __('Active', 'fluent-cart'),
268 self::SUBSCRIPTION_FAILING => __('Failing', 'fluent-cart'),
269 self::SUBSCRIPTION_PAUSED => __('Paused', 'fluent-cart'),
270 self::SUBSCRIPTION_EXPIRED => __('Expired', 'fluent-cart'),
271 self::SUBSCRIPTION_EXPIRING => __('Expiring', 'fluent-cart'),
272 self::SUBSCRIPTION_CANCELED => __('Canceled', 'fluent-cart'),
273 self::SUBSCRIPTION_TRIALING => __('Trialing', 'fluent-cart'),
274 self::SUBSCRIPTION_INTENDED => __('Intended', 'fluent-cart'),
275 self::SUBSCRIPTION_PAST_DUE => __('Past Due', 'fluent-cart'),
276 self::SUBSCRIPTION_COMPLETED => __('Completed', 'fluent-cart'),
277 ], []);
278 }
279
280 // Get Validable Subscription Statuses
281 public static function getValidableSubscriptionStatuses()
282 {
283 return apply_filters('fluent_cart/validable_subscription_statuses', [
284 self::SUBSCRIPTION_ACTIVE,
285 self::SUBSCRIPTION_TRIALING,
286 ], []);
287 }
288
289
290 // Stock statuses
291 public static function getStockStatuses($withLabel = true)
292 {
293 $statues = [
294 self::STOCK_INSTOCK => __('In Stock', 'fluent-cart'),
295 self::STOCK_OUTOFSTOCK => __('Out Of Stock', 'fluent-cart'),
296 ];
297
298 if ($withLabel) {
299 return $statues;
300 }
301
302 return array_keys($statues);
303 }
304
305 public static function getOrderSuccessStatuses()
306 {
307 return [
308 self::ORDER_COMPLETED,
309 self::ORDER_PROCESSING,
310 ];
311 }
312
313 public static function getOrderFailedStatuses()
314 {
315 return [
316 self::ORDER_FAILED,
317 //'refunded',
318 self::ORDER_CANCELED,
319 ];
320 }
321
322 public static function getOrderPaymentSuccessStatuses()
323 {
324 return [
325 self::PAYMENT_PAID,
326 self::PAYMENT_PARTIALLY_REFUNDED,
327 self::PAYMENT_PARTIALLY_PAID,
328 ];
329 }
330
331 public static function getPaymentRetryableStatuses()
332 {
333 return [
334 self::PAYMENT_PENDING,
335 self::PAYMENT_FAILED
336 ];
337 }
338
339 public static function getReportStatuses()
340 {
341 return [
342 self::PAYMENT_PAID,
343 self::PAYMENT_REFUNDED,
344 self::PAYMENT_PARTIALLY_PAID,
345 self::PAYMENT_PARTIALLY_REFUNDED,
346 ];
347 }
348
349 public static function getTransactionSuccessStatuses()
350 {
351 return apply_filters('fluent_cart/transaction_success_statuses', [self::TRANSACTION_SUCCEEDED, self::TRANSACTION_AUTHORIZED], []);
352 }
353
354 // Get all statuses (optional utility)
355 public static function all()
356 {
357 return [
358 'product' => self::getProductStatuses(),
359 'order' => self::getOrderStatuses(),
360 'payment' => self::getPaymentStatuses(),
361 'transaction' => self::getTransactionStatuses(),
362 'shipping' => self::getShippingStatuses(),
363 'customer' => self::getEditableCustomerStatuses(),
364 'subscription' => self::getSubscriptionStatuses(),
365 ];
366 }
367
368 public static function getEditableCustomerStatuses()
369 {
370 $statuses = [
371 self::CUSTOMER_ACTIVE => __('Active', 'fluent-cart'),
372 self::CUSTOMER_INACTIVE => __('Inactive', 'fluent-cart'),
373 ];
374
375 return apply_filters('fluent_cart/editable_customer_statuses', $statuses, []);
376 }
377
378 // call when syncing status from external services, ex:
379 public static function syncPaymentStatus($status)
380 {
381 $status = strtolower($status);
382 $statuses = self::getPaymentStatuses();
383
384 if (isset($statuses[$status])) {
385 return $status;
386 }
387
388 if ('completed' === $status) {
389 return self::PAYMENT_PAID;
390 }
391
392 if ('succeeded' === $status) {
393 return self::PAYMENT_PAID;
394 }
395
396 return $status;
397 }
398
399 public static function syncTransactionStatus($status)
400 {
401 $status = strtolower($status);
402 $statuses = self::getTransactionStatuses();
403
404 if (isset($statuses[$status])) {
405 return $status;
406 }
407
408 if ('paid' === $status) {
409 return self::TRANSACTION_SUCCEEDED;
410 } else if ('succeeded' === $status) {
411 return self::TRANSACTION_SUCCEEDED;
412 }
413
414 return $status;
415 }
416
417 public static function syncSubscriptionStatus($status)
418 {
419 if ('cancelled' === $status || 'canceled' === $status) {
420 return self::SUBSCRIPTION_CANCELED;
421 }
422
423 return $status;
424 }
425
426 public static function eventTriggers(): array
427 {
428 return [
429 'require_list' => false,
430 'required' => true,
431 'key' => 'event_trigger',
432 'options' => [
433 'order' => [
434 'label' => __('Orders', 'fluent-cart'),
435 'options' => [
436 [
437 'value' => 'order_paid_done',
438 'label' => __('Order Paid (Payment / Subscription)', 'fluent-cart')
439 ],
440 [
441 'value' => 'order_status_changed_to_canceled',
442 'label' => __('Order Canceled', 'fluent-cart')
443 ],
444 [
445 'value' => 'order_fully_refunded',
446 'label' => __('Order Refunded (Full)', 'fluent-cart')
447 ]
448 ]
449 ],
450 'subscription' => [
451 'label' => __('Subscriptions', 'fluent-cart'),
452 'options' => [
453 [
454 'value' => 'subscription_activated',
455 'label' => __('Subscription Activated', 'fluent-cart')
456 ],
457 [
458 'value' => 'subscription_reactivated',
459 'label' => __('Subscription Reactivated', 'fluent-cart')
460 ],
461 [
462 'value' => 'subscription_canceled',
463 'label' => __('Subscription Canceled', 'fluent-cart')
464 ],
465 [
466 'value' => 'subscription_renewed',
467 'label' => __('Subscription Renewed', 'fluent-cart')
468 ],
469 [
470 'value' => 'subscription_eot',
471 'label' => __('Subscription End of Term (Completed)', 'fluent-cart')
472 ],
473 [
474 'value' => 'subscription_expired_validity',
475 'label' => __('Subscription Expired / End of Access Validity', 'fluent-cart')
476 ]
477 ]
478 ],
479 'product' => [
480 'label' => __('Shipping', 'fluent-cart'),
481 'options' => [
482 [
483 'value' => 'shipping_status_changed_to_shipped',
484 'label' => __('Order Shipped', 'fluent-cart')
485 ],
486 [
487 'value' => 'shipping_status_changed_to_delivered',
488 'label' => __('Order Delivered', 'fluent-cart')
489 ]
490 ]
491 ]
492 ],
493 'inline_tip' => __('Select in which event you want to trigger this feed', 'fluent-cart'),
494 'label' => __('Event Trigger', 'fluent-cart'),
495 'placeholder' => __('Select Event', 'fluent-cart'),
496 'component' => 'selection_group',
497 'checkbox_label' => __('Event Trigger For This Feed', 'fluent-cart'),
498 ];
499 }
500
501 // Additional statuses can be added here as needed
502 }
503