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
12 changes: 6 additions & 6 deletions src/Domains/Registrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Utopia\Domains\Registrar\Domain;
use Utopia\Domains\Registrar\Renewal;
use Utopia\Domains\Registrar\Contact;
use Utopia\Domains\Registrar\Price;
use Utopia\Domains\Registrar\TransferStatus;
use Utopia\Domains\Registrar\UpdateDetails;

Expand Down Expand Up @@ -154,9 +155,9 @@ public function updateNameservers(string $domain, array $nameservers): array
* @param int $periodYears
* @param string $regType
* @param int $ttl
* @return float
* @return Price
*/
public function getPrice(string $domain, int $periodYears = 1, string $regType = self::REG_TYPE_NEW, int $ttl = 3600): float
public function getPrice(string $domain, int $periodYears = 1, string $regType = self::REG_TYPE_NEW, int $ttl = 3600): Price
{
return $this->adapter->getPrice($domain, $periodYears, $regType, $ttl);
}
Expand All @@ -178,13 +179,12 @@ public function renew(string $domain, int $periodYears): Renewal
*
* @param string $domain
* @param string $authCode
* @param array|Contact $contacts
* @param array $nameservers
* @param float|null $purchasePrice Required if domain is premium
* @return string Order ID
*/
public function transfer(string $domain, string $authCode, array|Contact $contacts, int $periodYears = 1, array $nameservers = []): string
public function transfer(string $domain, string $authCode, ?float $purchasePrice = null): string
{
return $this->adapter->transfer($domain, $authCode, $contacts, $periodYears, $nameservers);
return $this->adapter->transfer($domain, $authCode, $purchasePrice);
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/Domains/Registrar/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ public function updateNameservers(string $domain, array $nameservers): array
* @param int $periodYears
* @param string $regType
* @param int $ttl
* @return float
* @return Price
*/
abstract public function getPrice(string $domain, int $periodYears = 1, string $regType = Registrar::REG_TYPE_NEW, int $ttl = 3600): float;
abstract public function getPrice(string $domain, int $periodYears = 1, string $regType = Registrar::REG_TYPE_NEW, int $ttl = 3600): Price;

/**
* Renew a domain
Expand All @@ -173,12 +173,10 @@ abstract public function renew(string $domain, int $periodYears): Renewal;
*
* @param string $domain
* @param string $authCode
* @param array|Contact $contacts
* @param int $periodYears
* @param array $nameservers
* @param float|null $purchasePrice Required if domain is premium
* @return string Order ID
*/
abstract public function transfer(string $domain, string $authCode, array|Contact $contacts, int $periodYears = 1, array $nameservers = []): string;
abstract public function transfer(string $domain, string $authCode, ?float $purchasePrice = null): string;

/**
* Get the authorization code for an EPP domain
Expand Down
36 changes: 16 additions & 20 deletions src/Domains/Registrar/Adapter/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Utopia\Domains\Registrar\Adapter;
use Utopia\Domains\Registrar\TransferStatusEnum;
use Utopia\Domains\Registrar;
use Utopia\Domains\Registrar\Price;
use Utopia\Domains\Registrar\UpdateDetails;

class Mock extends Adapter
Expand Down Expand Up @@ -254,24 +255,25 @@ public function getDomain(string $domain): Domain
* @param int $periodYears
* @param string $regType
* @param int $ttl Time to live for the cache (if set) in seconds
* @return float
* @return Price
* @throws PriceNotFoundException
*/
public function getPrice(string $domain, int $periodYears = 1, string $regType = Registrar::REG_TYPE_NEW, int $ttl = 3600): float
public function getPrice(string $domain, int $periodYears = 1, string $regType = Registrar::REG_TYPE_NEW, int $ttl = 3600): Price
{
if ($this->cache) {
$cached = $this->cache->load($domain, $ttl);
if ($cached !== null && is_array($cached)) {
return $cached['price'];
if (is_array($cached) && isset($cached['price'])) {
return new Price($cached['price'], $cached['premium'] ?? false);
}
}

if (isset($this->premiumDomains[$domain])) {
$result = $this->premiumDomains[$domain] * $periodYears;
$isPremium = isset($this->premiumDomains[$domain]);

if ($isPremium) {
$price = $this->premiumDomains[$domain] * $periodYears;
$result = new Price($price, true);
if ($this->cache) {
$this->cache->save($domain, [
'price' => $result,
]);
$this->cache->save($domain, ['price' => $result->price, 'premium' => $result->premium]);
}

return $result;
Expand All @@ -296,11 +298,10 @@ public function getPrice(string $domain, int $periodYears = 1, string $regType =
default => 1.0,
};

$result = $basePrice * $periodYears * $multiplier;
$price = $basePrice * $periodYears * $multiplier;
$result = new Price($price, false);
if ($this->cache) {
$this->cache->save($domain, [
'price' => $result,
]);
$this->cache->save($domain, ['price' => $result->price, 'premium' => $result->premium]);
}

return $result;
Expand Down Expand Up @@ -356,21 +357,16 @@ public function updateDomain(string $domain, UpdateDetails $details): bool
*
* @param string $domain
* @param string $authCode
* @param array|Contact $contacts
* @param int $periodYears
* @param array $nameservers
* @param float|null $purchasePrice Required if domain is premium
* @return string Order ID
* @throws DomainTakenException
* @throws InvalidContactException
*/
public function transfer(string $domain, string $authCode, array|Contact $contacts, int $periodYears = 1, array $nameservers = []): string
public function transfer(string $domain, string $authCode, ?float $purchasePrice = null): string
{
if (in_array($domain, $this->purchasedDomains)) {
throw new DomainTakenException("Domain {$domain} is already in this account", self::RESPONSE_CODE_DOMAIN_TAKEN);
}

$this->validateContacts($contacts);

$this->transferredDomains[] = $domain;
$this->purchasedDomains[] = $domain;

Expand Down
Loading