diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d72101..1c78f29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +- `Hyvor\Internal\Auth\Dto\Organization` gained `has_payment_method` (bool), populated by + `ToCore\Organization\GetOrganizations` when `includeBillingInfo` is true +- New Comms event: ToCore\Billing\CreateSubscription + ## 4.0.0 - 2026-02-01 - Organization support diff --git a/bundle/src/Comms/Event/ToCore/Billing/CreateSubscription.php b/bundle/src/Comms/Event/ToCore/Billing/CreateSubscription.php new file mode 100644 index 0000000..3e182a1 --- /dev/null +++ b/bundle/src/Comms/Event/ToCore/Billing/CreateSubscription.php @@ -0,0 +1,46 @@ + + */ +class CreateSubscription extends AbstractEvent +{ + + public function __construct( + private int $organizationId, + private Component $component, + private string $plan, + ) { + } + + public function getOrganizationId(): int + { + return $this->organizationId; + } + + public function getComponent(): Component + { + return $this->component; + } + + public function getPlan(): string + { + return $this->plan; + } + + public function from(): array + { + return []; + } + + public function to(): array + { + return [Component::CORE]; + } + +} diff --git a/bundle/src/Comms/Event/ToCore/Billing/CreateSubscriptionResponse.php b/bundle/src/Comms/Event/ToCore/Billing/CreateSubscriptionResponse.php new file mode 100644 index 0000000..15c67c2 --- /dev/null +++ b/bundle/src/Comms/Event/ToCore/Billing/CreateSubscriptionResponse.php @@ -0,0 +1,17 @@ +subscriptionId; + } +} diff --git a/src/Auth/Dto/Organization.php b/src/Auth/Dto/Organization.php index e22e450..d71dc9c 100644 --- a/src/Auth/Dto/Organization.php +++ b/src/Auth/Dto/Organization.php @@ -15,6 +15,7 @@ * created_user?: AuthUserArray|AuthUser, * billing_email?: string, * billing_address?: BillingAddress|null, + * has_payment_method?: bool, * } * * @phpstan-type OrganizationArrayPartial array{ @@ -24,6 +25,7 @@ * created_user?: AuthUserArray, * billing_email?: string, * billing_address?: BillingAddress|null, + * has_payment_method?: bool, * } * * @phpstan-type BillingAddress array{ @@ -44,6 +46,8 @@ final class Organization { */ private ?array $billing_address = null; + private bool $has_payment_method = false; + public function __construct( private int $id, private string $name, @@ -102,6 +106,16 @@ public function setBillingAddress(?array $billing_address): void $this->billing_address = $billing_address; } + public function hasPaymentMethod(): bool + { + return $this->has_payment_method; + } + + public function setHasPaymentMethod(bool $has_payment_method): void + { + $this->has_payment_method = $has_payment_method; + } + /** * @param OrganizationArray $data */ @@ -129,6 +143,10 @@ public static function fromArray(array $data): self $org->setBillingAddress($data['billing_address']); } + if (isset($data['has_payment_method'])) { + $org->setHasPaymentMethod($data['has_payment_method']); + } + return $org; } } diff --git a/src/Billing/License/Plan/RelayPlan.php b/src/Billing/License/Plan/RelayPlan.php index f274086..829f8f4 100644 --- a/src/Billing/License/Plan/RelayPlan.php +++ b/src/Billing/License/Plan/RelayPlan.php @@ -2,14 +2,41 @@ namespace Hyvor\Internal\Billing\License\Plan; +use Hyvor\Internal\Billing\License\RelayLicense; + +/** + * @extends PlanAbstract + */ class RelayPlan extends PlanAbstract { - /** - * @codeCoverageIgnore - */ protected function config(): void { $this->version(1, function () { + $this->plan( + 'starter', + 30, + new RelayLicense( + emails:200_000, + projects: 3, + domains: 10, + dedicatedIps: false + ), + nameReadable: 'Starter', + monthlyOnly: true + ); + + $this->plan( + 'pro', + 80, + new RelayLicense( + emails: 800_000, + projects: 20, + domains: 1_000, + dedicatedIps: true + ), + nameReadable: 'Pro', + monthlyOnly: true + ); }); } } \ No newline at end of file diff --git a/src/Billing/License/RelayLicense.php b/src/Billing/License/RelayLicense.php index 944fe1e..67dda31 100644 --- a/src/Billing/License/RelayLicense.php +++ b/src/Billing/License/RelayLicense.php @@ -2,12 +2,45 @@ namespace Hyvor\Internal\Billing\License; +use Hyvor\Internal\Billing\License\Property\LicenseProperty; + final class RelayLicense extends License { + public function __construct( + public int $emails, + public int $projects, + public int $domains, + public bool $dedicatedIps, + ) {} - public static function trial(): static + public static function properties(): array { - return new self(); + return [ + LicenseProperty::int('emails') + ->name('Emails') + ->description('The number of emails allowed to be sent per month'), + + LicenseProperty::int('projects') + ->name('Projects') + ->description('The number of projects allowed to create'), + + LicenseProperty::int('domains') + ->name('Domains') + ->description('The number of domains allowed to send emails from'), + + LicenseProperty::bool('dedicatedIps') + ->name('Dedicated IPs') + ->description('Whether user is allowed to purchase dedicated IPs'), + ]; } + public static function trial(): static + { + return new self( + emails: 50, + projects: 1, + domains: 1, + dedicatedIps: false, + ); + } }