205 lines
9.5 KiB
PHP
205 lines
9.5 KiB
PHP
<?php
|
|
// Prevent direct access to file
|
|
defined(security_key) or exit;
|
|
|
|
// Get order ID and payment status
|
|
$order_id = $_SESSION['pending_order_id'] ?? $_GET['order_id'] ?? null;
|
|
$payment_status = $_GET['payment'] ?? 'processing';
|
|
|
|
$view = template_header(($place_order_header ?? 'Order Status'),'');
|
|
|
|
// Check payment status if we have an order ID
|
|
// Only check API if payment status is not already set to 'failed' from retry timeout
|
|
if ($order_id && $payment_status !== 'failed') {
|
|
$transaction_data = ioAPIv2('/v2/transactions/txn_id='.$order_id,'',$clientsecret);
|
|
$transaction = json_decode($transaction_data, true);
|
|
|
|
if ($transaction && isset($transaction[0])) {
|
|
$payment_status_code = $transaction[0]['payment_status'] ?? 0;
|
|
|
|
// Map payment status codes: 1 = Paid, 101 = Pending, 102 = Failed, 103 = Expired, 999 = Cancelled
|
|
if ($payment_status_code == 1) {
|
|
$payment_status = 'success';
|
|
} elseif ($payment_status_code == 101) {
|
|
$payment_status = 'pending';
|
|
} elseif (in_array($payment_status_code, [102, 103, 999])) {
|
|
$payment_status = 'failed';
|
|
}
|
|
}
|
|
}
|
|
|
|
// Display appropriate message based on payment status
|
|
if ($payment_status === 'success') {
|
|
// Payment successful - clear cart and show success
|
|
if (isset($_SESSION['cart'])) {
|
|
unset($_SESSION['cart']);
|
|
}
|
|
if (isset($_SESSION['discount'])) {
|
|
unset($_SESSION['discount']);
|
|
}
|
|
if (isset($_SESSION['pending_order_id'])) {
|
|
unset($_SESSION['pending_order_id']);
|
|
}
|
|
|
|
$view .= '
|
|
<div class="status-container">
|
|
<div class="status-card success">
|
|
<div class="status-icon success-icon">
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="80" height="80">
|
|
<circle cx="12" cy="12" r="11" fill="#10b981" stroke="" stroke-width="2"/>
|
|
<path d="M7 12l3.5 3.5L17 8" stroke="white" stroke-width="3" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
|
|
</svg>
|
|
</div>
|
|
<h1 class="status-title success-title">'.($payment_success_title ?? 'Payment Successful!').'</h1>
|
|
<p class="status-message">'.($payment_success_message ?? 'Your order has been confirmed and an email confirmation has been sent to your email address.').'</p>
|
|
'.($order_id ? '<div class="order-number">'.($order_number_label ?? 'Order number').': <strong>#'.$order_id.'</strong></div>' : '').'
|
|
<div class="status-actions">
|
|
<a href="'.url('index.php').'" class="btn btn-primary">
|
|
<svg width="20" height="20" viewBox="0 0 20 20" fill="none">
|
|
<path d="M7.5 15L2.5 10L7.5 5M3 10H17.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
</svg>
|
|
'.($continue_shopping_btn ?? 'Continue Shopping').'
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>';
|
|
|
|
} elseif ($payment_status === 'pending') {
|
|
// Payment pending
|
|
$view .= '
|
|
<div class="status-container">
|
|
<div class="status-card pending">
|
|
<div class="status-icon pending-icon">
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="80" height="80">
|
|
<circle cx="12" cy="12" r="11" fill="#f59e0b" stroke="" stroke-width="2"/>
|
|
<circle cx="12" cy="12" r="3" fill="white"/>
|
|
<path d="M12 6v6l4 2" stroke="white" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
|
|
</svg>
|
|
</div>
|
|
<h1 class="status-title pending-title">'.($payment_pending_title ?? 'Payment Pending').'</h1>
|
|
<p class="status-message">'.($payment_pending_message ?? 'Your order has been received and is awaiting payment confirmation. You will receive an email once the payment is confirmed.').'</p>
|
|
'.($order_id ? '<div class="order-number">'.($order_number_label ?? 'Order number').': <strong>#'.$order_id.'</strong></div>' : '').'
|
|
<div class="status-actions">
|
|
<a href="'.url('index.php').'" class="btn btn-primary">
|
|
<svg width="20" height="20" viewBox="0 0 20 20" fill="none">
|
|
<path d="M7.5 15L2.5 10L7.5 5M3 10H17.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
</svg>
|
|
'.($continue_shopping_btn ?? 'Continue Shopping').'
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
let checkInterval;
|
|
let checkCount = 0;
|
|
const maxChecks = 5;
|
|
|
|
function checkPaymentStatus() {
|
|
if (checkCount >= maxChecks) {
|
|
clearInterval(checkInterval);
|
|
window.location.href = "'.url('placeorder/'.$order_id).'?payment=failed";
|
|
return;
|
|
}
|
|
|
|
checkCount++;
|
|
|
|
fetch("'.base_url.'api_check_payment_status.php?order_id='.$order_id.'")
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.status !== "pending") {
|
|
clearInterval(checkInterval);
|
|
window.location.href = "'.url('placeorder/'.$order_id).'?payment=" + data.status;
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error("Error checking payment status:", error);
|
|
});
|
|
}
|
|
|
|
// Check immediately, then every 3 seconds
|
|
checkPaymentStatus();
|
|
checkInterval = setInterval(checkPaymentStatus, 3000);
|
|
</script>';
|
|
|
|
} elseif ($payment_status === 'processing') {
|
|
// Payment is being processed
|
|
$view .= '
|
|
<div class="status-container">
|
|
<div class="status-card processing">
|
|
<div class="status-icon processing-icon">
|
|
<svg class="spinner" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="80" height="80">
|
|
<circle cx="12" cy="12" r="10" stroke="#3b82f6" stroke-width="4" fill="none" stroke-dasharray="60" stroke-linecap="round">
|
|
<animateTransform attributeName="transform" type="rotate" from="0 12 12" to="360 12 12" dur="1s" repeatCount="indefinite"/>
|
|
</circle>
|
|
</svg>
|
|
</div>
|
|
<h1 class="status-title processing-title">'.($payment_processing_title ?? 'Processing Payment...').'</h1>
|
|
<p class="status-message">'.($payment_processing_message ?? 'Please wait while we confirm your payment. This may take a few moments.').'</p>
|
|
<div class="progress-bar">
|
|
<div class="progress-fill"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
let checkInterval;
|
|
let checkCount = 0;
|
|
const maxChecks = 5;
|
|
|
|
function checkPaymentStatus() {
|
|
if (checkCount >= maxChecks) {
|
|
clearInterval(checkInterval);
|
|
window.location.href = "'.url('placeorder/'.$order_id).'?payment=failed";
|
|
return;
|
|
}
|
|
|
|
checkCount++;
|
|
|
|
fetch("'.base_url.'api_check_payment_status.php?order_id='.$order_id.'")
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.status !== "processing") {
|
|
clearInterval(checkInterval);
|
|
window.location.href = "'.url('placeorder/'.$order_id).'?payment=" + data.status;
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error("Error checking payment status:", error);
|
|
});
|
|
}
|
|
|
|
// Check immediately, then every 3 seconds
|
|
checkPaymentStatus();
|
|
checkInterval = setInterval(checkPaymentStatus, 3000);
|
|
</script>';
|
|
|
|
} else {
|
|
// Payment failed
|
|
$view .= '
|
|
<div class="status-container">
|
|
<div class="status-card failed">
|
|
<div class="status-icon failed-icon">
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="80" height="80">
|
|
<circle cx="12" cy="12" r="11" fill="#ef4444" stroke="" stroke-width="2"/>
|
|
<path d="M8 8l8 8M16 8l-8 8" stroke="white" stroke-width="3" stroke-linecap="round"/>
|
|
</svg>
|
|
</div>
|
|
<h1 class="status-title failed-title">'.($payment_failed_title ?? 'Payment Not Successful').'</h1>
|
|
<p class="status-message">'.($payment_failed_message ?? 'Unfortunately, your payment could not be processed. Please try again or choose a different payment method.').'</p>
|
|
'.($order_id ? '<div class="order-number">'.($order_number_label ?? 'Order reference').': <strong>#'.$order_id.'</strong></div>' : '').'
|
|
<div class="status-actions">
|
|
<a href="'.url('index.php?page=checkout').'" class="btn btn-primary">
|
|
<svg width="20" height="20" viewBox="0 0 20 20" fill="none">
|
|
<path d="M7.5 15L2.5 10L7.5 5M3 10H17.5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
</svg>
|
|
'.($return_to_checkout_btn ?? 'Return to Checkout').'
|
|
</a>
|
|
<a href="'.url('index.php?page=cart').'" class="btn btn-secondary">'.($view_cart_btn ?? 'View Cart').'</a>
|
|
</div>
|
|
</div>
|
|
</div>';
|
|
}
|
|
|
|
$view .= template_footer();
|
|
|
|
echo $view;
|
|
?>
|