Skip to content

Commit d11b955

Browse files
authored
Merge pull request #30 from artisan-build/till-default-driver
Added ledgers to Till and a bunch of other stuff.
2 parents e8c2306 + 5bd9cbf commit d11b955

Some content is hidden

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

41 files changed

+700
-93
lines changed

composer.lock

+29-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hallway-core/src/Calendar/Events/GatheringCreated.php

-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
use ArtisanBuild\VerbsFlux\Attributes\EventInput;
1717
use ArtisanBuild\VerbsFlux\Enums\InputTypes;
1818
use Carbon\Carbon;
19-
use Thunk\Verbs\Attributes\Autodiscovery\AppliesToSingletonState;
2019
use Thunk\Verbs\Attributes\Autodiscovery\StateId;
2120
use Thunk\Verbs\Event;
2221

23-
#[AppliesToSingletonState(CalendarRangeState::class)]
2422
#[EventForm(
2523
submit_text: 'Create New Gathering',
2624
has_time_machine: true,

packages/hallway-core/src/Calendar/States/CalendarRangeState.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace ArtisanBuild\Hallway\Calendar\States;
66

77
use Carbon\Carbon;
8-
use Thunk\Verbs\State;
8+
use Thunk\Verbs\SingletonState;
99

10-
class CalendarRangeState extends State
10+
class CalendarRangeState extends SingletonState
1111
{
1212
public ?Carbon $first_gathering_start = null;
1313

packages/till/config/till.php

+7
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,12 @@
1919
'pricing_section_template' => 'till::livewire.pricing_section',
2020
'active_feature_icon' => null,
2121
'inactive_feature_icon' => null,
22+
'update_ledgers' => [
23+
'hourly' => true,
24+
'daily' => true,
25+
'weekly' => true,
26+
'monthly' => true,
27+
'yearly' => true,
28+
],
2229

2330
];
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace ArtisanBuild\Till\Actions;
4+
5+
use Illuminate\Support\Facades\Cache;
6+
7+
class CacheAbility
8+
{
9+
public function __invoke(string $key, bool $value): bool
10+
{
11+
$keys = Cache::get('abilities_keys', []);
12+
$keys[] = $key;
13+
Cache::rememberForever('ability_keys', fn () => array_unique($keys));
14+
15+
Cache::rememberForever($key, fn () => $value);
16+
17+
return $value;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace ArtisanBuild\Till\Actions;
4+
5+
use Illuminate\Support\Facades\Cache;
6+
7+
class ClearAbilitiesCache
8+
{
9+
public function __invoke(): void
10+
{
11+
$keys = Cache::get('abilities_keys', []);
12+
13+
foreach ($keys as $key) {
14+
Cache::forget($key);
15+
}
16+
}
17+
}

packages/till/src/Actions/GetActivePlans.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ArtisanBuild\Till\Actions;
44

5-
use ArtisanBuild\Till\Attributes\UnavailablePlan;
5+
use ArtisanBuild\Till\Attributes\ArchivedPlan;
66
use ReflectionClass;
77

88
class GetActivePlans
@@ -14,7 +14,7 @@ public function __invoke()
1414
return ($this->plans)()->filter(function ($plan) {
1515
$reflection = new ReflectionClass($plan);
1616

17-
return empty($reflection->getAttributes(UnavailablePlan::class));
17+
return empty($reflection->getAttributes(ArchivedPlan::class));
1818
});
1919

2020
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace ArtisanBuild\Till\Actions;
4+
5+
use ArtisanBuild\Till\States\SubscriberState;
6+
use Carbon\CarbonInterface;
7+
use Illuminate\Foundation\Auth\User;
8+
use Illuminate\Support\Facades\Cache;
9+
10+
class RefreshSubscriptionCache
11+
{
12+
public function __construct(protected SubscriberState $state) {}
13+
14+
public function __invoke(?User $user = null, ?CarbonInterface $expiration = null): array
15+
{
16+
$abilities = [];
17+
foreach (data_get(app(GetPlanById::class)($this->state->plan_id), 'can') as $ability) {
18+
$abilities[last(explode('\\', (string) $ability[0]))] = app($ability[0])(...$ability[1]);
19+
}
20+
21+
Cache::put('subscription-'.$this->state->id, $abilities, $expiration ?? $this->getCacheExpiration());
22+
23+
return $abilities;
24+
}
25+
26+
protected function getCacheExpiration(): ?CarbonInterface
27+
{
28+
if ($this->state->expires_at && $this->state->renews_at) {
29+
return $this->state->expires_at->lt($this->state->renews_at) ? $this->state->expires_at : $this->state->renews_at;
30+
}
31+
32+
return $this->state->expires_at ?? $this->state->renews_at;
33+
}
34+
}

packages/till/src/Attributes/UnavailablePlan.php packages/till/src/Attributes/ArchivedPlan.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Attribute;
66

77
#[Attribute(Attribute::TARGET_CLASS)]
8-
class UnavailablePlan
8+
class ArchivedPlan
99
{
1010
public function __construct() {}
1111
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace ArtisanBuild\Till\Attributes;
4+
5+
use ArtisanBuild\Till\SubscriptionPlans\Ledgers;
6+
use Attribute;
7+
8+
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
9+
class Costs
10+
{
11+
public function __construct(public Ledgers $ledger, public int $amount = 1) {}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace ArtisanBuild\Till\Attributes;
4+
5+
use Attribute;
6+
7+
#[Attribute(Attribute::TARGET_CLASS)]
8+
class ImpactsAbilities {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace ArtisanBuild\Till\Contracts;
4+
5+
interface LedgerInterface {}

packages/till/src/Contracts/StartsSubscription.php

-11
This file was deleted.

0 commit comments

Comments
 (0)