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
← All changes | app/Models/Subscription.php +34 -4 1.6.6 → 1.7.0 View file →
@@ -999,9 +999,13 @@
999 999 Status::SUBSCRIPTION_FAILING,
1000 1000 Status::SUBSCRIPTION_EXPIRED,
1001 1001 Status::SUBSCRIPTION_EXPIRING,
1002 1002 Status::SUBSCRIPTION_PAST_DUE,
1003 - ]);
1003 + ]) || (
1004 + in_array($this->status, [Status::SUBSCRIPTION_PENDING, Status::SUBSCRIPTION_INTENDED], true)
1005 + && $this->hasReactivationAttempt()
1006 + && ((int) $this->bill_times === 0 || (int) $this->bill_count < (int) $this->bill_times)
1007 + );
1004 1008
1005 1009 return (bool) apply_filters('fluent_cart/subscription/can_reactivate', $canReactivate, [
1006 1010 'subscription' => $this
1007 1011 ]);
@@ -1007,8 +1011,34 @@
1007 1011 ]);
1008 1012 }
1009 1013
1010 1014 /**
1015 + * Pro records `reactivation_order_id` before a reactivation checkout is paid. A first
1016 + * purchase awaiting gateway activation is also pending/intended and can already be
1017 + * billed, so only this marker separates a retryable reactivation from it.
1018 + */
1019 + public function hasReactivationAttempt(): bool
1020 + {
1021 + return (int) Arr::get($this->config, 'reactivation_order_id', 0) > 0;
1022 + }
1023 +
1024 + public function isVisibleToCustomer(): bool
1025 + {
1026 + return !in_array($this->status, [Status::SUBSCRIPTION_PENDING, Status::SUBSCRIPTION_INTENDED], true)
1027 + || (int) $this->bill_count > 0
1028 + || $this->hasReactivationAttempt();
1029 + }
1030 +
1031 + public function scopeVisibleToCustomer($query)
1032 + {
1033 + return $query->where(function ($query) {
1034 + $query->whereNotIn('status', [Status::SUBSCRIPTION_PENDING, Status::SUBSCRIPTION_INTENDED])
1035 + ->orWhere('bill_count', '>', 0)
1036 + ->orWhere('config', 'LIKE', '%"reactivation_order_id":%');
1037 + });
1038 + }
1039 +
1040 + /**
1011 1041 * @deprecated Use canReactivate(). Kept as a backward-compatible alias.
1012 1042 * @return bool
1013 1043 */
1014 1044 public function canReactive()
@@ -1413,13 +1443,13 @@
1413 1443 // lookup either way.
1414 1444
1415 1445 $invalidStatuses = [
1416 1446 Status::SUBSCRIPTION_EXPIRED,
1417 - Status::SUBSCRIPTION_INTENDED,
1418 - Status::SUBSCRIPTION_PENDING
1419 1447 ];
1420 1448
1421 - if (in_array($this->status, $invalidStatuses)) {
1449 + if (in_array($this->status, $invalidStatuses)
1450 + || (in_array($this->status, [Status::SUBSCRIPTION_PENDING, Status::SUBSCRIPTION_INTENDED], true)
1451 + && !$this->hasReactivationAttempt())) {
1422 1452 return false;
1423 1453 }
1424 1454
1425 1455 $nextBillingDate = $this->next_billing_date;