<?php
/**
 * EXAMPLE: payment-return.php - the customer is redirected here after payment.
 * Never trust URL params — always verify the status from the server.
 */
require __DIR__ . '/../php/MiplPay.php';
$pg = new MiplPay('mipl_live_xxxxxxxx', 'sk_xxxxxxxxxxxxxxxx', 'https://pay.moldable.in');

$orderId = preg_replace('/[^A-Za-z0-9_\-]/', '', $_GET['order_id'] ?? '');
$status = $pg->orderStatus(['order_id' => $orderId]);

if ($status['status'] === 'success') {
    echo '<h2>✅ Payment Successful</h2><p>₹' . number_format($status['amount'], 2) . ' has been added to your wallet.</p>';
} elseif ($status['status'] === 'pending_verify') {
    echo '<h2>⏳ Verification pending</h2><p>Your UTR is being verified. Your wallet will be updated shortly.</p>';
} else {
    echo '<h2>Payment ' . htmlspecialchars($status['status']) . '</h2>';
}
