Skip to content
Closed
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
14 changes: 14 additions & 0 deletions src/Api/Interfaces/PackagesApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

namespace SandwaveIo\BaseKit\Api\Interfaces;

use SandwaveIo\BaseKit\Domain\AccountPackage;

interface PackagesApiInterface
{
public function addUserPackage(
int $userRef,
int $packageRef,
int $billingFrequency
): void;

/**
* @return AccountPackage[]
*/
public function listUserPackages(
int $userRef
): array;

public function deleteUserPackage(
int $userRef,
int $accountPackageRef
): void;
}
25 changes: 25 additions & 0 deletions src/Api/PackageApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace SandwaveIo\BaseKit\Api;

use SandwaveIo\BaseKit\Api\Interfaces\PackagesApiInterface;
use SandwaveIo\BaseKit\Domain\AccountPackage;
use SandwaveIo\BaseKit\Exceptions\UnexpectedValueException;

final class PackageApi extends AbstractApi implements PackagesApiInterface
{
Expand All @@ -23,4 +25,27 @@ public function addUserPackage(

$this->client->post("users/{$userRef}/account-packages", $payload);
}

/**
* @param int $userRef
*
* @return AccountPackage[]
*/
public function listUserPackages(int $userRef): array
{
$response = $this->client->get("users/{$userRef}/account-packages")->json();
if (! array_key_exists('accountPackages', $response)) {
throw new UnexpectedValueException('No account packages was provided by BaseKit.');
}
return AccountPackage::fromArray($response['accountPackages']); // @phpstan-ignore-line
}

/**
* @param int $userRef
* @param int $accountPackageRef
*/
public function deleteUserPackage(int $userRef, int $accountPackageRef): void
{
$this->client->delete("users/{$userRef}/account-packages/{$accountPackageRef}");
}
}
72 changes: 72 additions & 0 deletions src/Domain/AccountPackage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php declare(strict_types = 1);

namespace SandwaveIo\BaseKit\Domain;

final class AccountPackage implements DomainObjectInterface
{
/**
* @param array<mixed> $startDateTime
* @param array<mixed> $endDateTime
* @param array<mixed> $update
*/
public function __construct(
public int $ref,
public array $startDateTime,
public array $endDateTime,
public array $update,
public int $deleteOnExpiry,
public bool $isFree,
public int $billingPeriodMonths,
public bool $isActive,
public Package $package,
public ?int $templateGroupRef,
public ?int $displayOrder,
) {
}

/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'ref' => $this->ref,
'startDateTime' => $this->startDateTime,
'endDateTime' => $this->endDateTime,
'update' => $this->update,
'deleteOnExpiry' => $this->deleteOnExpiry,
'isFree' => $this->isFree,
'billingPeriodMonths' => $this->billingPeriodMonths,
'isActive' => $this->isActive,
'package' => $this->package->toArray(),
'templateGroupRef' => $this->templateGroupRef,
'displayOrder' => $this->displayOrder,
];
}

/**
* @inheritDoc
*/
public static function fromArray(array $json)
{
$sitePackages = [];

foreach ($json as $sitePackage) {
$sitePackages[] = new AccountPackage(
ref: $sitePackage['ref'],
startDateTime: $sitePackage['startDateTime'],
endDateTime: $sitePackage['endDateTime'],
update: $sitePackage['update'],
deleteOnExpiry: $sitePackage['deleteOnExpiry'],
isFree: $sitePackage['isFree'],
billingPeriodMonths: $sitePackage['billingPeriodMonths'],
isActive: $sitePackage['isActive'],
package: Package::fromArray($sitePackage['package']),
templateGroupRef: $sitePackage['templateGroupRef'],
displayOrder: $sitePackage['displayOrder'],
);
}

return $sitePackages; // @phpstan-ignore-line
}
}
49 changes: 49 additions & 0 deletions src/Domain/Currency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php declare(strict_types = 1);

namespace SandwaveIo\BaseKit\Domain;

final class Currency implements DomainObjectInterface
{
public function __construct(
public int $ref,
public string $name,
public string $alphaCode,
public string $numCode,
public string $htmlCode,
public int $currencyRate,
public int $paypal,
) {
}

/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'ref' => $this->ref,
'name' => $this->name,
'alphaCode' => $this->alphaCode,
'numCode' => $this->numCode,
'htmlCode' => $this->htmlCode,
'currencyRate' => $this->currencyRate,
'paypal' => $this->paypal,
];
}

/**
* @inheritDoc
*/
public static function fromArray(array $json)
{
return new Currency(
ref: $json['ref'],
name: $json['name'],
alphaCode: $json['alphaCode'],
numCode: $json['numCode'],
htmlCode: $json['htmlCode'],
currencyRate: $json['currencyRate'],
paypal: $json['paypal'],
);
}
}
58 changes: 58 additions & 0 deletions src/Domain/DomainProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php declare(strict_types = 1);

namespace SandwaveIo\BaseKit\Domain;

final class DomainProduct implements DomainObjectInterface
{
public function __construct(
public string $domainSuffix,
public string $name,
public string $description,
public int $frequencyMonths,
public int $active,
public int $availableAsFreeDomain,
public bool $requireCustomContactDetails,
public int $renewalActive,
public int $ref,
public ?ProductSupplier $productSupplier,
) {
}

/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'domainSuffix' => $this->domainSuffix,
'name' => $this->name,
'description' => $this->description,
'frequencyMonths' => $this->frequencyMonths,
'active' => $this->active,
'availableAsFreeDomain' => $this->availableAsFreeDomain,
'requireCustomContactDetails' => $this->requireCustomContactDetails,
'renewalActive' => $this->renewalActive,
'ref' => $this->ref,
'productSupplier' => $this->productSupplier !== null ? $this->productSupplier->toArray() : [],
];
}

/**
* @inheritDoc
*/
public static function fromArray(array $json)
{
return new DomainProduct(
domainSuffix: $json['domainSuffix'],
name: $json['name'],
description: $json['description'],
frequencyMonths: $json['frequencyMonths'],
active: $json['active'],
availableAsFreeDomain: $json['availableAsFreeDomain'],
requireCustomContactDetails: $json['requireCustomContactDetails'],
renewalActive: $json['renewalActive'],
ref: $json['ref'],
productSupplier: ProductSupplier::fromArray($json['productSupplier']),
);
}
}
139 changes: 139 additions & 0 deletions src/Domain/Package.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php declare(strict_types = 1);

namespace SandwaveIo\BaseKit\Domain;

final class Package implements DomainObjectInterface
{
/**
* @param string[]|null $metadata
* @param string[] $capabilities
* @param string[] $templateGroup
* @param PackagePrice[] $prices
* @param int[] $plugins
*/
public function __construct(
public int $ref,
public string $name,
public int $active,
public int $global,
public ?string $urlID,
public string $notifyMarketing,
public string $productType,
public string $type,
public string $contentType,
public int $offerRebillMonths,
public int $offerRebillActive,
public int $trialDays,
public ?string $imageURL,
public bool $requirePurchasedDomain,
public bool $allowMultiplePurchase,
public bool $showInStore,
public bool $showInTemplatePicker,
public ?string $bannerHTML,
public string $affiliateLink,
public ?string $flowName,
public ?array $metadata,
public int $brandRef,
public string $brandName,
public int $defaultCurrencyRef,
public string $currencyCode,
public string $currencyName,
public string $currencyTitle,
public ?int $defaultCampaignRef,
public array $capabilities,
public ?int $templateGroupRef,
public ?array $templateGroup,
public ?int $displayOrder,
public ?DomainProduct $domainProduct,
public array $prices,
public array $plugins,
) {
}

/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'ref' => $this->ref,
'name' => $this->name,
'active' => $this->active,
'global' => $this->global,
'urlID' => $this->urlID,
'notifyMarketing' => $this->notifyMarketing,
'productType' => $this->productType,
'type' => $this->type,
'contentType' => $this->contentType,
'offerRebillMonths' => $this->offerRebillMonths,
'offerRebillActive' => $this->offerRebillActive,
'trialDays' => $this->trialDays,
'requirePurchasedDomain' => $this->requirePurchasedDomain,
'allowMultiplePurchase' => $this->allowMultiplePurchase,
'showInStore' => $this->showInStore,
'showInTemplatePicker' => $this->showInTemplatePicker,
'bannerHTML' => $this->bannerHTML,
'affiliateLink' => $this->affiliateLink,
'flowName' => $this->flowName,
'metadata' => $this->metadata,
'brandRef' => $this->brandRef,
'brandName' => $this->brandName,
'defaultCurrencyRef' => $this->defaultCurrencyRef,
'currencyCode' => $this->currencyCode,
'currencyName' => $this->currencyName,
'currencyTitle' => $this->currencyTitle,
'defaultCampaignRef' => $this->defaultCampaignRef,
'capabilities' => $this->capabilities,
'templateGroupRef' => $this->templateGroupRef,
'templateGroup' => $this->templateGroup,
'displayOrder' => $this->displayOrder,
'domainProduct' => $this->domainProduct !== null ? $this->domainProduct->toArray() : [],
'prices' => $this->prices,
'plugins' => $this->plugins,
];
}

/**
* @inheritDoc
*/
public static function fromArray(array $json)
{
return new Package(
ref: $json['ref'],
name: $json['name'],
active: $json['active'],
global: $json['global'],
urlID: $json['urlID'],
notifyMarketing: $json['notifyMarketing'],
productType: $json['productType'],
type: $json['type'],
contentType: $json['contentType'],
offerRebillMonths: $json['offerRebillMonths'],
offerRebillActive: $json['offerRebillActive'],
trialDays: $json['trialDays'],
imageURL: $json['imageURL'],
requirePurchasedDomain: $json['requirePurchasedDomain'],
allowMultiplePurchase: $json['allowMultiplePurchase'],
showInStore: $json['showInStore'],
showInTemplatePicker: $json['showInTemplatePicker'],
bannerHTML: $json['bannerHTML'],
affiliateLink: $json['affiliateLink'],
flowName: $json['flowName'],
metadata: $json['metadata'],
brandRef: $json['brandRef'],
brandName: $json['brandName'],
defaultCurrencyRef: $json['defaultCurrencyRef'],
currencyCode: $json['currencyCode'],
currencyName: $json['currencyName'],
currencyTitle: $json['currencyTitle'],
defaultCampaignRef: $json['defaultCampaignRef'],
capabilities: $json['capabilities'],
templateGroupRef: $json['templateGroupRef'],
templateGroup: $json['templateGroup'],
displayOrder: $json['displayOrder'],
domainProduct: DomainProduct::fromArray($json['domainProduct']),
prices: PackagePrice::fromArray($json['prices']), // @phpstan-ignore-line
plugins: $json['plugins'],
);
}
}
Loading