Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
46 changes: 46 additions & 0 deletions bundle/src/Comms/Event/ToCore/Billing/CreateSubscription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Hyvor\Internal\Bundle\Comms\Event\ToCore\Billing;

use Hyvor\Internal\Bundle\Comms\Event\AbstractEvent;
use Hyvor\Internal\Component\Component;

/**
* @extends AbstractEvent<CreateSubscriptionResponse>
*/
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];
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Hyvor\Internal\Bundle\Comms\Event\ToCore\Billing;

readonly class CreateSubscriptionResponse
{

public function __construct(
private int $subscriptionId,
) {
}

public function getSubscriptionId(): int
{
return $this->subscriptionId;
}
}
18 changes: 18 additions & 0 deletions src/Auth/Dto/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* created_user?: AuthUserArray|AuthUser,
* billing_email?: string,
* billing_address?: BillingAddress|null,
* has_payment_method?: bool,
* }
*
* @phpstan-type OrganizationArrayPartial array{
Expand All @@ -24,6 +25,7 @@
* created_user?: AuthUserArray,
* billing_email?: string,
* billing_address?: BillingAddress|null,
* has_payment_method?: bool,
* }
*
* @phpstan-type BillingAddress array{
Expand All @@ -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,
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}
}
33 changes: 30 additions & 3 deletions src/Billing/License/Plan/RelayPlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,41 @@

namespace Hyvor\Internal\Billing\License\Plan;

use Hyvor\Internal\Billing\License\RelayLicense;

/**
* @extends PlanAbstract<RelayLicense>
*/
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
);
});
}
}
37 changes: 35 additions & 2 deletions src/Billing/License/RelayLicense.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
Loading