Thank you for your reply.
use Tygh\Http;
use Tygh\Registry;
if (!defined('BOOTSTRAP')) { die('Access denied'); }
require_once(Registry::get('config.dir.payments') . 'ipay/ipay_func.php');
if( defined('PAYMENT_NOTIFICATION') )
{
$payment_id = db_get_field("SELECT payment_id FROM ?:orders WHERE order_id = ?i", $_REQUEST['order_id']);
$processor_data = fn_get_payment_method_data($payment_id);
$order_info = fn_get_order_info( $_REQUEST['order_id'] );
$debug = (bool)$processor_data['processor_params']['debug'];
if (fn_check_payment_script('ipay.php', $_REQUEST['order_id'], $processor_data))
{
ipay_logging('Payment Notification Mode:: ' . $mode, false, $debug);
$pp_response = array();
$data = ipay_get_itn_notification_data();
ipay_logging('ITN Notication Data::' . print_r( $data, true ), false, $debug);
$itn_result = ipay_process_payment_itn( $data, $processor_data, $order_info);
$transaction_id = $data['TransactionId'];
$order_status = '';
switch( $data['Status'] )
{
case IPAY_ORDER_STATUS_COMPLETE:
ipay_logging(sprintf( 'Payment complete::%s', $itn_result ), false, $debug);
$order_status = 'O';
break;
case IPAY_ORDER_STATUS_PENDING_INVESTIGATION:
case IPAY_ORDER_STATUS_PENDING:
ipay_logging(sprintf( 'Payment pending::%s', $itn_result ), false, $debug);
$order_status = 'F';
break;
default:
ipay_logging(sprintf( 'Payment error::%s', $itn_result ), false, $debug);
$order_status = 'F';
break;
break;
}
$pp_response['order_status'] = $order_status;
$pp_response['reason_text'] = $itn_result;
$pp_response['transaction_id'] = $transaction_id;
fn_change_order_status($_REQUEST['order_id'], $order_status, '', false);
fn_finish_payment($_REQUEST['order_id'], $pp_response);
fn_order_placement_routines('route', $_REQUEST['order_id']);
}
}
else
{
$debug = (bool)$processor_data['processor_params']['debug'];
ipay_logging('Payment Notification Mode:: ' . $mode, false, $debug);
$ipay_url = ipay_get_payment_url();
$site_code = $processor_data['processor_params']['site_code'];
$country_code = $processor_data['processor_params']['country_code'];
$currency_code = $processor_data['processor_params']['currency_code'];
$private_key = $processor_data['processor_params']['private_key'];
$test_mode = $processor_data['processor_params']['mode'] == 'test' ? 'true' : 'false';
$amount = fn_format_price( $order_info['total'] , $currency_code );
$order_id = $order_info['order_id'];
$return_url = fn_url("payment_notification.return?payment=ipay&order_id=$order_id", AREA, 'current');
$cancel_url = fn_url("payment_notification.cancel?payment=ipay&order_id=$order_id", AREA, 'current');
$notify_url = fn_url("payment_notification.notify?payment=ipay&order_id=$order_id", AREA, 'current');
$post_data = array(
'SiteCode' => $site_code,
'CountryCode' => $country_code,
'CurrencyCode' => $currency_code,
'Amount' => $amount,
'TransactionReference' => $order_id,
'BankReference' => $order_id,
'Optional1' => '',
'Optional5' => 'CS-Cart 4.x',
'Customer' => $order_info['firstname'] . ' ' . $order_info['lastname'],
'CancelUrl' => $cancel_url,
'SuccessUrl' => $return_url,
'NotifyUrl' => $notify_url,
'IsTest' => $test_mode
);
$hash_check = ipay_get_hash($post_data, $private_key);
$post_data['HashCheck'] = $hash_check;
ipay_logging('Payment Post Data::' . print_r( $post_data, true ), false, $debug);
fn_create_payment_form($ipay_url, $post_data, 'i-Pay Server');
}
exit;