Skip to content

Commit

Permalink
Fix Enom transfer() logic to only return success upon transfer comple…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
uphlewis committed May 24, 2023
1 parent 215d580 commit 2e7f573
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Enom/Helper/EnomApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ public function getDomainTransferOrders(string $sld, string $tld): ?array
'orderId' => (int) $childData->transferorderid,
'status' => (string) $childData->orderstatus,
'statusId' => (int) $childData->statusid,
'date' => Utils::formatDate((string) $childData->orderdate)
'date' => Utils::formatDate((string) $childData->orderdate, null, (string)$result->TimeDifference)
];
}
}
Expand Down
39 changes: 19 additions & 20 deletions src/Enom/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,35 +206,34 @@ public function transfer(TransferParams $params): DomainResult
$sld = $params->sld;
$tld = $params->tld;

$domain = Utils::getDomain($sld, $tld);
// TODO: `renew_years` (period) is not needed here.
//$period = Arr::get($params, 'renew_years', 1);
// TODO: In development, `epp_code` is not needed as well, but required when sending the requests, so we may just send a random string
$eppCode = $params->epp_code ?: '1234';

try {
return $this->_getInfo($sld, $tld, 'Domain is active in registrar account');
} catch (\Throwable $e) {
// Domain not active in account: proceed to initiate or check transfer order below
}

try {
// Check for previous order first
$prevOrder = $this->api()->getDomainTransferOrders($sld, $tld);

if (is_null($prevOrder)) {
// Attempt to create a new transfer order.
$transfer = $this->api()->initiateTransfer($sld, $tld, $eppCode);

// Transfer is most probably still pending, so we'll return just a basic info with the transfer order id, the domain and the order creation date
return DomainResult::create([
'id' => (string) $transfer['orderId'],
'domain' => $domain,
'ns' => [],
'statuses' => [],
'created_at' => Utils::formatDate($transfer['date']),
'updated_at' => Utils::formatDate($transfer['date']),
'expires_at' => Utils::formatDate($transfer['date'])
]);
} else {
$this->errorResult(sprintf('Transfer order(s) for %s already exists!', $domain), $prevOrder, $params);
if ($prevOrders = $this->api()->getDomainTransferOrders($sld, $tld)) {
$prevOrder = collect($prevOrders)->sortByDesc('date')->first();
throw $this->errorResult(
sprintf('Transfer order in progress since %s', $prevOrder['date']),
$prevOrders,
$params
);
}

// Attempt to create a new transfer order.
$this->api()->initiateTransfer($sld, $tld, $eppCode);

throw $this->errorResult('Domain transfer order initiated');
} catch (\Throwable $e) {
$this->handleException($e, $params);
throw $this->handleException($e, $params);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/Helper/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ class Utils
* @param string|null $format
* @return string|null Formatted date, or null
*/
public static function formatDate(?string $date, ?string $format = null): ?string
public static function formatDate(?string $date, ?string $format = null, ?string $adjustHours = null): ?string
{
if (empty($date)) {
return null;
}

$dateObject = Carbon::parse($date);

if ($adjustHours) {
$dateObject->addHours($adjustHours);
}

if (!is_null($format)) {
return $dateObject->format($format);
}
Expand Down

0 comments on commit 2e7f573

Please sign in to comment.