mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-04 22:24:42 +09:00
Fix duplicate domain activation from stale order object during checkout (#3948)
* Fix duplicate domain activation caused by stale order object Cart checkout can activate an order that was already activated synchronously via an invoice paid with account credit, since the in-memory order held by the checkout loop is never refreshed after the credit-payment path activates it through its own freshly-loaded copy. activateOrder() now re-fetches the order before checking its status, closing the gap that let EPP domain registration run twice and fail with "Domain is not available: In use". * Treat already-active orders as a no-op in activateOrder The reload alone turned the stale-order race into a thrown exception for orders that were already correctly activated by another code path in the same request. Cart::checkoutCart()'s catch block then tried to record an 'error' order status, which isn't a valid status and threw a second exception that broke the whole checkout. An already-active order (without force) should just be a no-op success. * Update src/modules/Order/Service.php Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
81ae63c820
commit
60ef50108d
2 files changed
+83
-4
No files matched your search
@@ -879,14 +879,25 @@ class Service implements InjectionAwareInterface
|
||||
|
||||
public function activateOrder(\Model_ClientOrder $order, $data = []): bool
|
||||
{
|
||||
// re-fetch in case the caller's order object is stale (e.g. already activated by another code path)
|
||||
$orderId = $order->id;
|
||||
$order = $this->di['db']->load('ClientOrder', $orderId);
|
||||
if (!$order instanceof \Model_ClientOrder) {
|
||||
throw new \FOSSBilling\Exception('Order :id not found', [':id' => $orderId]);
|
||||
}
|
||||
$force = !empty($data['force']);
|
||||
|
||||
// Already active and not a forced re-activation: nothing to do.
|
||||
if ($order->status === \Model_ClientOrder::STATUS_ACTIVE && !$force) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$statues = [
|
||||
\Model_ClientOrder::STATUS_PENDING_SETUP,
|
||||
\Model_ClientOrder::STATUS_FAILED_SETUP,
|
||||
];
|
||||
if (!in_array($order->status, $statues)) {
|
||||
if (!isset($data['force']) || !$data['force']) {
|
||||
throw new \FOSSBilling\Exception('Only pending setup or failed orders can be activated');
|
||||
}
|
||||
if (!in_array($order->status, $statues) && !$force) {
|
||||
throw new \FOSSBilling\Exception('Only pending setup or failed orders can be activated');
|
||||
}
|
||||
|
||||
$event_params = ['id' => $order->id];
|
||||
|
||||
Reference in new issue
Block a user