api('POST', '/v2/checkout/orders/' . urlencode($orderId) . '/capture'); if ($resp['status'] < 200 || $resp['status'] >= 300) { http_response_code(500); echo 'Capture failed: ' . htmlspecialchars(json_encode($resp)); exit; } $capture = $resp['body']; // Update local order store $orders = $storage->get('orders', []); if (isset($orders[$orderId])) { $orders[$orderId]['status'] = $capture['status'] ?? 'CAPTURED'; $storage->set('orders', $orders); } // Redirect back to home with a status indicator $baseUrl = rtrim($config['base_url'], '/'); $status = isset($capture['status']) ? $capture['status'] : 'CAPTURED'; header('Location: ' . $baseUrl . '/index.php?captured=1&order=' . urlencode($orderId) . '&status=' . urlencode($status)); exit;