Download src/Billing/Application/CommandHandlers/EndSubscriptionCommandHandler.php from pnacorp/AIKEEDO: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/pnacorp/AIKEEDO/resolve/main/src/Billing/Application/CommandHandlers/EndSubscriptionCommandHandler.php
- Command line
-
hf download hf://pnacorp/AIKEEDO/src/Billing/Application/CommandHandlers/EndSubscriptionCommandHandler.php
-
curl -L -o EndSubscriptionCommandHandler.php https://huggingface.co/pnacorp/AIKEEDO/resolve/main/src/Billing/Application/CommandHandlers/EndSubscriptionCommandHandler.php
1.7 kB
| declare(strict_types=1); | |
| namespace Billing\Application\CommandHandlers; | |
| use Billing\Application\Commands\EndSubscriptionCommand; | |
| use Billing\Domain\Entities\SubscriptionEntity; | |
| use Billing\Domain\Exceptions\SubscriptionNotFoundException; | |
| use Billing\Domain\Exceptions\PlanNotFoundException; | |
| use Billing\Domain\Repositories\PlanRepositoryInterface; | |
| use Billing\Domain\Repositories\SubscriptionRepositoryInterface; | |
| use Easy\Container\Attributes\Inject; | |
| use Shared\Domain\ValueObjects\Id; | |
| class EndSubscriptionCommandHandler | |
| { | |
| public function __construct( | |
| private SubscriptionRepositoryInterface $repo, | |
| private PlanRepositoryInterface $prepo, | |
| #[Inject('option.billing.fallback_plan')] | |
| private ?string $defaultPlanId = null, | |
| ) { | |
| } | |
| /** | |
| * @throws SubscriptionNotFoundException | |
| * @throws PlanNotFoundException | |
| */ | |
| public function handle(EndSubscriptionCommand $cmd): void | |
| { | |
| $sub = $cmd->subscription instanceof Id | |
| ? $this->repo->ofId($cmd->subscription) | |
| : $cmd->subscription; | |
| $ws = $sub->getWorkspace(); | |
| $sub->end(); | |
| $activeSub = $ws->getSubscription(); | |
| if ( | |
| !$activeSub | |
| || (string) $activeSub->getId()->getValue() !== (string) $sub->getId()->getValue() | |
| ) { | |
| return; | |
| } | |
| if ($this->defaultPlanId) { | |
| $plan = $this->prepo->ofId(new Id($this->defaultPlanId)); | |
| $sub = new SubscriptionEntity( | |
| $ws, | |
| $plan->getSnapshot() | |
| ); | |
| $ws->subscribe($sub); | |
| } else { | |
| $ws->removeSubscription(); | |
| } | |
| } | |
| } | |