Skip to content

Commit b65677a

Browse files
committed
refactor: rename subscription canceled_at column to cancels_at across models, services, and tests
1 parent 724a937 commit b65677a

52 files changed

Lines changed: 199 additions & 165 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

database/factories/SubscriptionFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function canceled(): static
9797
return $this->state([
9898
'status' => SubscriptionStatus::CANCELED,
9999
'expires_at' => now(),
100-
'canceled_at' => now(),
100+
'cancels_at' => now(),
101101
]);
102102
}
103103

database/migrations/2019_05_03_000002_create_subscriptions_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function up(): void
3838
$table->timestamp('starts_at')->nullable()->index();
3939
$table->dateTime('expires_at')->nullable();
4040
$table->timestamp('ends_at')->nullable();
41-
$table->timestamp('canceled_at')->nullable()->index();
41+
$table->timestamp('cancels_at')->nullable()->index();
4242
$table->timestamp('frozen_at')->nullable()->comment('When the subscription was frozen (paused)');
4343
$table->timestamp('release_at')->nullable()->comment('When the subscription should automatically unfreeze');
4444
$table->timestamps();

docs/reports/contract-progress.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Track fixed-term contract subscription progress. See how many cycles completed,
5151
### Active Contracts
5252
**Type:** Number
5353
**Description:** Active subscriptions on this plan (not canceled)
54-
**How it's calculated:** Count of subscriptions where status = "active" and canceled_at is null
54+
**How it's calculated:** Count of subscriptions where status = "active" and cancels_at is null
5555

5656
### Average Current Cycle
5757
**Type:** Number

docs/reports/subscription-lifecycle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Track subscription states and movements over time. See counts of new, active, tr
7070
### Grace Period
7171
**Type:** Number
7272
**Description:** Canceled but not yet expired at period end
73-
**How it's calculated:** COUNT(canceled_at IS NOT NULL AND expires_at > period end)
73+
**How it's calculated:** COUNT(cancels_at IS NOT NULL AND expires_at > period end)
7474

7575
### Reactivations
7676
**Type:** Number

src/Actions/Subscription/CancelSubscription.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function execute($subscription)
1919
$subscription->expires_at = $subscription->trial_ends_at;
2020
}
2121

22-
$subscription->canceled_at = now();
22+
$subscription->cancels_at = $subscription->expires_at ?? now();
2323
$subscription->save();
2424

2525
return $subscription;
@@ -34,11 +34,9 @@ public function execute($subscription)
3434
public function cancelAt($subscription, ?\DateTimeInterface $endsAt)
3535
{
3636
if ($endsAt instanceof \DateTimeInterface) {
37-
$subscription->expires_at = $endsAt->getTimestamp();
37+
$subscription->cancels_at = $endsAt;
3838
}
3939

40-
$subscription->status = SubscriptionStatus::CANCELED;
41-
$subscription->canceled_at = now();
4240
$subscription->save();
4341

4442
return $subscription;
@@ -54,8 +52,7 @@ public function cancelNow($subscription)
5452
{
5553
$subscription->fill([
5654
'status' => SubscriptionStatus::CANCELED,
57-
'expires_at' => now(),
58-
'canceled_at' => now(),
55+
'cancels_at' => now(),
5956
])->save();
6057

6158
return $subscription;

src/Actions/Subscription/RenewSubscription.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ protected function executeNoCharge($subscription)
175175
'expires_at' => $period->getEndDate(),
176176
'ends_at' => null,
177177
'trial_ends_at' => null,
178-
'canceled_at' => null,
178+
'cancels_at' => null,
179179
])->save();
180180

181181
if ($isExpired) {

src/Actions/Subscription/ResumeSubscription.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function execute($subscription)
3232
$subscription->fill([
3333
'status' => SubscriptionStatus::ACTIVE,
3434
'expires_at' => $period->getEndDate(),
35-
'canceled_at' => null,
35+
'cancels_at' => null,
3636
])->save();
3737

3838
return $subscription;

src/Actions/Subscription/SwapSubscriptionPlan.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function execute($subscription, $planId, $billing = 'monthly', bool $invo
5656
);
5757

5858
$subscription->fill([
59-
'canceled_at' => null,
59+
'cancels_at' => null,
6060
'billing_interval' => $billingInterval,
6161
'billing_interval_count' => $billingIntervalCount,
6262
'total_cycles' => $newPlan->contract_cycles,

src/Models/Subscription.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Subscription extends Model implements ManagesSubscriptions, SubscriptionSt
4242
'expires_at',
4343
'ends_at',
4444
'starts_at',
45-
'canceled_at',
45+
'cancels_at',
4646
'frozen_at',
4747
'release_at',
4848
'provider',
@@ -70,7 +70,7 @@ class Subscription extends Model implements ManagesSubscriptions, SubscriptionSt
7070
'expires_at' => 'datetime',
7171
'ends_at' => 'datetime',
7272
'starts_at' => 'datetime',
73-
'canceled_at' => 'datetime',
73+
'cancels_at' => 'datetime',
7474
'frozen_at' => 'datetime',
7575
'release_at' => 'datetime',
7676
'metadata' => 'json',
@@ -603,7 +603,7 @@ public function active(): bool
603603
public function scopeActive($query)
604604
{
605605
$query->where(function ($query) {
606-
$query->whereNull('canceled_at')
606+
$query->whereNull('cancels_at')
607607
->orWhere(function ($query) {
608608
$query->canceledOnGracePeriod();
609609
});
@@ -629,17 +629,17 @@ public function scopeRecurring($query)
629629

630630
public function canceled(): bool
631631
{
632-
return ! is_null($this->canceled_at);
632+
return ! is_null($this->cancels_at);
633633
}
634634

635635
public function scopeCanceled($query)
636636
{
637-
$query->whereNotNull('canceled_at');
637+
$query->whereNotNull('cancels_at');
638638
}
639639

640640
public function scopeNotCanceled($query)
641641
{
642-
$query->whereNull('canceled_at');
642+
$query->whereNull('cancels_at');
643643
}
644644

645645
public function ended()
@@ -684,21 +684,19 @@ public function scopeNotOnTrial($query)
684684

685685
public function canceledOnGracePeriod(): bool
686686
{
687-
return $this->canceled_at && $this->expires_at && $this->expires_at->isFuture();
687+
return $this->cancels_at && $this->cancels_at->isFuture();
688688
}
689689

690690
public function scopeCanceledOnGracePeriod($query)
691691
{
692-
$query->whereNotNull('canceled_at')
693-
->whereNotNull('expires_at')
694-
->where('expires_at', '>', Carbon::now());
692+
$query->whereNotNull('cancels_at')
693+
->where('cancels_at', '>', Carbon::now());
695694
}
696695

697696
public function scopeCanceledNotOnGracePeriod($query)
698697
{
699-
$query->whereNotNull('canceled_at')
700-
->whereNotNull('expires_at')
701-
->where('expires_at', '<=', Carbon::now());
698+
$query->whereNotNull('cancels_at')
699+
->where('cancels_at', '<=', Carbon::now());
702700
}
703701

704702
public function onGracePeriod(): bool
@@ -766,7 +764,7 @@ public function toResponse(array $extends = []): array
766764
'expires_at' => $this->serializeDate($this->expires_at),
767765
'ends_at' => $this->serializeDate($this->ends_at),
768766
'starts_at' => $this->serializeDate($this->starts_at),
769-
'canceled_at' => $this->serializeDate($this->canceled_at),
767+
'cancels_at' => $this->serializeDate($this->cancels_at),
770768
'frozen_at' => $this->serializeDate($this->frozen_at),
771769
'release_at' => $this->serializeDate($this->release_at),
772770
'provider' => $this->provider,

src/Models/User.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function scopeOnlyPlan($query, string $type = 'month'): Builder
239239
{
240240
return $query->whereHas('subscriptions', function ($q) use ($type) {
241241
$q->active()
242-
->whereNull('canceled_at')
242+
->whereNull('cancels_at')
243243
->whereHas('plan', function ($q) use ($type) {
244244
$q->whereInterval($type)
245245
->where('price', '<>', 0);
@@ -253,7 +253,7 @@ public function scopeOnlyPlan($query, string $type = 'month'): Builder
253253
public function scopeOnlyRolling($query): Builder
254254
{
255255
return $query->whereHas('subscriptions', function ($q) {
256-
$q->active()->whereNull('canceled_at');
256+
$q->active()->whereNull('cancels_at');
257257
});
258258
}
259259

@@ -263,7 +263,7 @@ public function scopeOnlyRolling($query): Builder
263263
public function scopeOnlyEnds($query): Builder
264264
{
265265
return $query->whereHas('subscriptions', function ($q) {
266-
$q->active()->whereNotNull('canceled_at');
266+
$q->active()->whereNotNull('cancels_at');
267267
});
268268
}
269269

0 commit comments

Comments
 (0)