{
    // $url_for_redirect = fn_url ( "orders" );
    // $url_for_redirect =  "../../../orders";
    $url_for_redirect = "../../../index.php?dispatch=orders.search";
    return $url_for_redirect;
}
// Load System
pn_load_system();
// Load PayNow
pn_load_paynow();
// Redirect URL for users using EFT/Retail payments to notify them the order's pending
$url_for_redirect = pn_get_redirect_url();
pnlog(__FILE__ . " POST: " . print_r($_REQUEST, true));
$pn_callback = $mode == 'notify' || isset($_POST['TransactionAccepted']) && $_POST['TransactionAccepted'] == true;
// CC notification or EFT or none?
if (isset($_POST) && !empty($_POST)) {
    // This is the notification coming in!
    // Act as an IPN request and forward request to Credit Card method.
    // Logic is exactly the same
    pn_do_transaction(pn_order_id_from_ref($_POST['Reference']));
    die;
} else {
    // Probably calling the "redirect" URL
    pnlog(__FILE__ . ' Probably calling the "redirect" URL');
    if ($url_for_redirect) {
        header("Location: {$url_for_redirect}");
    } else {
        die("No 'redirect' URL set.");
    }
}
die(PN_ERR_BAD_ACCESS);
    $m_payment_id = $m_payment_id . "_" . date("Ymds");
    $return_url = fn_url("payment_notification.return?payment=sagepaynow&order_id={$order_info['order_id']}", AREA, 'current');
    $cancel_url = fn_url("payment_notification.cancel?payment=sagepaynow&order_id={$order_info['order_id']}", AREA, 'current');
    $notify_url = fn_url("payment_notification.notify?payment=sagepaynow&order_id={$order_info['order_id']}", AREA, 'current');
    $callback_url = "dispatch=payment_notification.notify&payment=sagepaynow&order_id={$order_info['order_id']}";
    $customerName = "{$order_info['b_firstname']} {$order_info['b_lastname']}";
    $orderID = $order_info['order_id'];
    $customerID = $order_info['user_id'];
    // TODO: Not sure if this customer ID is correct..
    $sageGUID = "88950107-bea8-4e83-b54a-edbfff19e49a";
    $payArray = array('m1' => $sagepaynow_service_key, 'm2' => $sageGUID, 'm5' => $return_url, 'first_name' => $order_info['b_firstname'], 'last_name' => $order_info['b_lastname'], 'email_address' => $order_info['email'], 'p2' => $m_payment_id, 'p4' => $total, 'm6' => __('text_sagepaynow_item_name') . ' (' . $order_info['b_firstname'] . ' ' . $order_info['b_lastname'] . ' - Order #' . $order_info['order_id'] . ')', 'description' => __('total_product_cost'), 'p3' => "{$customerName} | {$orderID}", 'm4' => "{$customerID}");
    $inputs = '';
    foreach ($payArray as $k => $v) {
        $inputs .= "<input type='hidden' name='{$k}' value='{$v}' />\n";
    }
    $msg = fn_get_lang_var('text_cc_processor_connection');
    $msg = str_replace('[processor]', 'Sage Pay Now', $msg);
    pnlog("payArray: " . print_r($payArray, true));
    echo <<<EOT
    <html>
    <body onLoad="document.sagepaynow_form.submit();">
    <form action="https://paynow.sagepay.co.za/site/paynow.aspx" method="post" name="sagepaynow_form">
    {$inputs}

    </form>
    <div align=center>{$msg}</div>
    </body>
    </html>
EOT;
}
exit;