Return Url For Custom Payment Gateway

I am implementing a new Payment Gateway on CS-Cart. Using the instructions in [url=“CS-Cart Documentation — CS-Cart 4.15.x documentation”]CS-Cart Documentation — CS-Cart 4.15.x documentation I have been able to create a payment script and update the MySQL cscart_payment_processors table. The application now connects successfully to the Gateway with the correct order total, merchant ID etc. The problem now is getting the response back. It’s not clear which script should be specified as the Return URL when sending the request to the Gateway (GTPay in this case). I have written the script to handle the response in the same app/payments/ gtpay_payment_script.php file and specified the same file as the return URL but it always comes up with “Access Denied” whenever control is returned from the Gateway. Here’s the script in the gtpay_payment_script.php file (I came up with this script after looking at the other payment scripts in app/payments, CS-Cart has no detailed guide on exactly what this script should do other than “send data to your payment processor server)”):


```php

if (!defined('BOOTSTRAP')) { die('Access denied'); }
//this is supposed to handle the response from the Gateway - still working on this part
if (defined('PAYMENT_NOTIFICATION')) {
if ($mode == 'process') {
$pp_response["order_status"] = (($_REQUEST['gtpay_tranx_status_code'] == "00") ? 'P' : 'F');

if ($_REQUEST['gtpay_tranx_status_code'] == 'Z6') {
$pp_response["order_status"] = 'I';
$pp_response["reason_text"] = "Cancelled";
} elseif ($_REQUEST['gtpay_tranx_status_code'] != '00') {
$pp_response["reason_text"] = "Error";
}
if (isset($_REQUEST['gtpay_tranx_status_msg'])) {
$pp_response["reason_text"].= ": " . $_REQUEST['gtpay_tranx_status_msg'];
}
if (isset($_REQUEST['gtpay_tranx_id'])) {
$pp_response["transaction_id"] = $_REQUEST['gtpay_tranx_id'];
}
$order_id = $_REQUEST['gtpay_echo_data'];
if (fn_check_payment_script('gtpay_payment_script.php', $order_id)) {
fn_finish_payment($order_id, $pp_response, false);
fn_order_placement_routines('route', $order_id);
}
}
} else { //send payment to gateway
//get payment total amount
$amount = $order_info["total"]; //str_replace('.', ',', $order_info["total"]);
// transaction id
$_order_id = $order_id.'_'.mt_rand(11111,99999);
//specify the url
$submit_url = 'GATEWAY URL GOES HERE';
//build parameters
$post_data = array(
'gtpay_cust_id' =>'X',
'gtpay_mert_id' =>'XXX',
'gtpay_tranx_id' => $_order_id, //gtpay tranx id
'gtpay_item_name_1' => 'Numartng: Goods Purchased',
'gtpay_tranx_amt' =>$amount*100, // amount converted to gtpay kobo format
'gtpay_tranx_noti_url' => 'MY-SITE-URL/app/payments/gtpay_payment_script.php', //THIS IS REALLY WHERE THE ISSUE IS, THIS IS WHERE CONTROL SHOULD BE RETURNED TO FROM THE GATEWAY
'gtpay_no_show_cust_id' => 'no',
'gtpay_tranx_memo' => 'Numartng: Goods Purchased',
'gtpay_gway_first' => 'yes',
'gtpay_gway_name' =>'webpay',
'gtpay_echo_data' => $order_id //order id again, included as echo data to be used when control is returned
);

//print_r($post_data); die;
fn_create_payment_form($submit_url, $post_data, 'GTPay Server');
exit;
}
```

Obviously from the code, CS-Cart needs to have defined the constant BOOTSTRAP, which means this script probably shouldn’t be run directly, maybe it’s supposed to be included somewhere else, meaning my Return URL should be different. I’m sure someone must have implemented something similar so please I will appreciate your help on this. Thank you very much!

Try the following URL instead of the “yourdomain.com”:



http://yourdomain.com/index.php?dispatch=payment_notification.process&payment=gtpay_payment_script&order_id=YOUR_ORDER_ID




Note: not all payment systems support arguments in the return URLs, but you should try

Thank you very much @eComLabs this worked for me!

I also need some help. I have the same problem, the script conects to payment gateway send data and is fine.

The problem is in cs cart to have order confirmed. I get this message transaction was canceled by customer





I have 3 scripts for a new payment gateway

in /app/payments/

one is

newpay.php that send the data from cs cart to gateway



#below is where mobilPay will send the payment result. This URL will always be called first; mandatory
$objPmReqCard->confirmUrl = 'http://mydommain.com/lucru/app/payments/newpayConfirm.php';
#below is where newPay redirects the client once the payment process is finished. Not to be mistaken for a "successURL" nor "cancelURL"; mandatory
$objPmReqCard->returnUrl = 'http://mydommain.com/lucru/app/payments/newpayReturn.php';




in newpayConfirm.php looks like this I didn t put all code



$errorCode = $objPmReq->objPmNotify->errorCode;
// action = status only if the associated error code is zero
if ($errorCode == "0") {
switch($objPmReq->objPmNotify->action)
{
#orice action este insotit de un cod de eroare si de un mesaj de eroare. Acestea pot fi citite folosind $cod_eroare = $objPmReq->objPmNotify->errorCode; respectiv $mesaj_eroare = $objPmReq->objPmNotify->errorMessage;
#pentru a identifica ID-ul comenzii pentru care primim rezultatul platii folosim $id_comanda = $objPmReq->orderId;
case 'confirmed':
#cand action este confirmed avem certitudinea ca banii au plecat din contul posesorului de card si facem update al starii comenzii si livrarea produsului
//update DB, SET status = "confirmed/captured"
//$pp_response['order_status'] = 'P'; ##########Stare comanda##############
$errorMessage = $objPmReq->objPmNotify->errorMessage;
break;
case 'confirmed_pending':
#cand action este confirmed_pending inseamna ca tranzactia este in curs de verificare antifrauda. Nu facem livrare/expediere. In urma trecerii de aceasta verificare se va primi o noua notificare pentru o actiune de confirmare sau anulare.
//update DB, SET status = "pending"
$errorMessage = $objPmReq->objPmNotify->errorMessage;
// $pp_response['order_status'] = 'P'; ##########Stare comanda##############
break;
case 'paid_pending':
#cand action este paid_pending inseamna ca tranzactia este in curs de verificare. Nu facem livrare/expediere. In urma trecerii de aceasta verificare se va primi o noua notificare pentru o actiune de confirmare sau anulare.
//update DB, SET status = "pending"
// $pp_response['order_status'] = 'P'; ##########Stare comanda##############






I was wondering where should I put the code for order order/payment confirmation in cs cart

I didn in newpayReturn.php



but I get a message transaction was canceled by customer



require '../../init.php';
$order_id = $_GET['orderId'];
fn_change_order_status($order_id, 'P', '', false); //schimba statusul comenzii in deschisa
fn_finish_payment($order_id, $pp_response, false);
fn_order_placement_routines('route', $order_id);




I will be grateful for An help, indication

Try to check one of the built in gateway. For example, app/payments/deltapay.php

do you know how can be used fn_order_placement_routines function without doing any redirect



The thing is that the payment details are sent to payment gateway well without problem



the problem is that if I don t use the above function



but the order doesn 't show in cs cart





if I use fn_order_placement_routines('route', $order_id); function the order is shwon in cs cart



but is an error at payment gateway a redirection or something

Did you check the example in the app/payments/deltapay.php file? It is quite clear.



Use fn_finish_payment to change order status and save additional transaction information



Use fn_order_placement_routines to clear cart, send notifications and redirect customer to the order landing page



Incomplete orders can be found on the Orders → View orders → Gear icon on the top → Incomplete orders page

I did examine the app/payments/deltapay.php



but the payment gateway is different.



What I did breifly:

  • the details are sent to the payment gateway correctly
  • I need somhow the order to show in admin of cs cart and also not to redirect



    in case of fn_order_placement_routines function is not good to redirect customer to the order landing page

    as

    the payment gateway impose to specify here the link that redirect customer to the order landing page



    $objPmReqCard->returnUrl = 'http://mydommain.com/lucru/app/payments/newpayReturn.php';



    Please let me know if you can implement for me on the payment gateway I know how it works what to do.



    How much would cost me eComLabs implementation

[quote name='gurdji' timestamp='1435648381' post='220962']

I did examine the app/payments/deltapay.php



but the payment gateway is different.



What I did breifly:

  • the details are sent to the payment gateway correctly
  • I need somhow the order to show in admin of cs cart and also not to redirect



    in case of fn_order_placement_routines function is not good to redirect customer to the order landing page

    as

    the payment gateway impose to specify here the link that redirect customer to the order landing page



    $objPmReqCard->returnUrl = 'http://mydommain.com/lucru/app/payments/newpayReturn.php';



    Please let me know if you can implement for me on the payment gateway I know how it works what to do.



    How much would cost me eComLabs implementation

    [/quote]



    Please send integration manual for developers to contact[at]ecom-labs.com. Our specialists will examine it and back to you soon

I am implementing a new Payment Gateway on CS-Cart. Using the instructions in http://kb.cs-cart.com/new-payment I have been able to create a payment script and update the MySQL cscart_payment_processors table. The application now connects successfully to the Gateway with the correct order total, merchant ID etc. The problem now is getting the response back. It’s not clear which script should be specified as the Return URL when sending the request to the Gateway (GTPay in this case). I have written the script to handle the response in the same [b]app/payments/[/b] [b]gtpay_payment_script.php[/b] file and specified the same file as the return URL but it always comes up with “Access Denied” whenever control is returned from the Gateway. Here’s the script in the [b]gtpay_payment_script.php[/b] file (I came up with this script after looking at the other payment scripts in [b]app/payments[/b], CS-Cart has no detailed guide on exactly what this script should do other than “send data to your payment processor server)”):

    if ($_REQUEST['gtpay_tranx_status_code'] == 'Z6') {
	    $pp_response["order_status"] = 'I';
	    $pp_response["reason_text"] = "Cancelled";
    } elseif ($_REQUEST['gtpay_tranx_status_code'] != '00') {
	    $pp_response["reason_text"] = "Error";
    }
    if (isset($_REQUEST['gtpay_tranx_status_msg'])) {
	    $pp_response["reason_text"].= ": " . $_REQUEST['gtpay_tranx_status_msg'];
    }
    if (isset($_REQUEST['gtpay_tranx_id'])) {
	    $pp_response["transaction_id"] = $_REQUEST['gtpay_tranx_id'];
    }
    $order_id = $_REQUEST['gtpay_echo_data'];
    if (fn_check_payment_script('gtpay_payment_script.php', $order_id)) {
	    fn_finish_payment($order_id, $pp_response, false);
	    fn_order_placement_routines('route', $order_id);
    }
}

} else { //send payment to gateway
//get payment total amount
$amount = $order_info[“total”]; //str_replace(‘.’, ‘,’, $order_info[“total”]);
// transaction id
$order_id = $order_id.''.mt_rand(11111,99999);
//specify the url
$submit_url = ‘GATEWAY URL GOES HERE’;
//build parameters
$post_data = array(
‘gtpay_cust_id’ =>‘X’,
‘gtpay_mert_id’ =>‘XXX’,
‘gtpay_tranx_id’ => $_order_id, //gtpay tranx id
‘gtpay_item_name_1’ => ‘Numartng: Goods Purchased’,
‘gtpay_tranx_amt’ =>$amount*100, // amount converted to gtpay kobo format
‘gtpay_tranx_noti_url’ => ‘MY-SITE-URL/app/payments/gtpay_payment_script.php’, //THIS IS REALLY WHERE THE ISSUE IS, THIS IS WHERE CONTROL SHOULD BE RETURNED TO FROM THE GATEWAY
‘gtpay_no_show_cust_id’ => ‘no’,
‘gtpay_tranx_memo’ => ‘Numartng: Goods Purchased’,
‘gtpay_gway_first’ => ‘yes’,
‘gtpay_gway_name’ =>‘webpay’,
‘gtpay_echo_data’ => $order_id //order id again, included as echo data to be used when control is returned
);

//print_r($post_data); die;
fn_create_payment_form($submit_url, $post_data, ‘GTPay Server’);
exit;
}


Obviously from the code, CS-Cart needs to have defined the constant BOOTSTRAP, which means this script probably shouldn’t be run directly, maybe it’s supposed to be included somewhere else, meaning my Return URL should be different. I’m sure someone must have implemented something similar so please I will appreciate your help on this. Thank you very much!

how can i send response back to my payment processor ?

(The application now connects successfully to the Gateway with the correct order total, merchant ID etc. The problem now is getting the response back) am facing the same problem,,,, i wnat to know how to get the response back from the gateway ??? help please

Thank you very much @eComLabs this worked for me!

how can i send the response from the gateway to my processor.php ?

For example, use the following callback URL

https://yourdomain.com/index.php?dispatch=payment_notification.process&payment=processor

and catch callback in the processor.php

if (defined('PAYMENT_NOTIFICATION')) {
    ... process callback here....
}

For example, use the following callback URL

https://yourdomain.com/index.php?dispatch=payment_notification.process&payment=processor

and catch callback in the processor.php

if (defined('PAYMENT_NOTIFICATION')) {
    ... process callback here....
}

it worked ,,, but the order status is still incomplete !!! it supposed to change it as paid Successfully??

how can i do that???

Use

$pp_response = [
    'order_status' => 'P'
];

fn_finish_payment($order_id, $pp_response);

Of course, P status should be specified only for successful transactions

For example, use the following callback URL

https://yourdomain.com/index.php?dispatch=payment_notification.process&payment=processor

and catch callback in the processor.php

if (defined('PAYMENT_NOTIFICATION')) {
    ... process callback here....
}

As mentioned in cs-cart Documentation (Adding a Payment Processor via an Add-on ) the gateway should send two mandatory parameters which are ( Payment and mode ) in as you listed above in the callback url you are only passing the payment parameter!!!!

I am implementing a new Payment Gateway on CS-Cart. Using the instructions in http://kb.cs-cart.com/new-payment I have been able to create a payment script and update the MySQL cscart_payment_processors table. The application now connects successfully to the Gateway with the correct order total, merchant ID etc. The problem now is getting the response back. It’s not clear which script should be specified as the Return URL when sending the request to the Gateway (GTPay in this case). I have written the script to handle the response in the same [b]app/payments/[/b] [b]gtpay_payment_script.php[/b] file and specified the same file as the return URL but it always comes up with “Access Denied” whenever control is returned from the Gateway. Here’s the script in the [b]gtpay_payment_script.php[/b] file (I came up with this script after looking at the other payment scripts in [b]app/payments[/b], CS-Cart has no detailed guide on exactly what this script should do other than “send data to your payment processor server)”):

    if ($_REQUEST['gtpay_tranx_status_code'] == 'Z6') {
	    $pp_response["order_status"] = 'I';
	    $pp_response["reason_text"] = "Cancelled";
    } elseif ($_REQUEST['gtpay_tranx_status_code'] != '00') {
	    $pp_response["reason_text"] = "Error";
    }
    if (isset($_REQUEST['gtpay_tranx_status_msg'])) {
	    $pp_response["reason_text"].= ": " . $_REQUEST['gtpay_tranx_status_msg'];
    }
    if (isset($_REQUEST['gtpay_tranx_id'])) {
	    $pp_response["transaction_id"] = $_REQUEST['gtpay_tranx_id'];
    }
    $order_id = $_REQUEST['gtpay_echo_data'];
    if (fn_check_payment_script('gtpay_payment_script.php', $order_id)) {
	    fn_finish_payment($order_id, $pp_response, false);
	    fn_order_placement_routines('route', $order_id);
    }
}

} else { //send payment to gateway
//get payment total amount
$amount = $order_info[“total”]; //str_replace(‘.’, ‘,’, $order_info[“total”]);
// transaction id
$order_id = $order_id.''.mt_rand(11111,99999);
//specify the url
$submit_url = ‘GATEWAY URL GOES HERE’;
//build parameters
$post_data = array(
‘gtpay_cust_id’ =>‘X’,
‘gtpay_mert_id’ =>‘XXX’,
‘gtpay_tranx_id’ => $_order_id, //gtpay tranx id
‘gtpay_item_name_1’ => ‘Numartng: Goods Purchased’,
‘gtpay_tranx_amt’ =>$amount*100, // amount converted to gtpay kobo format
‘gtpay_tranx_noti_url’ => ‘MY-SITE-URL/app/payments/gtpay_payment_script.php’, //THIS IS REALLY WHERE THE ISSUE IS, THIS IS WHERE CONTROL SHOULD BE RETURNED TO FROM THE GATEWAY
‘gtpay_no_show_cust_id’ => ‘no’,
‘gtpay_tranx_memo’ => ‘Numartng: Goods Purchased’,
‘gtpay_gway_first’ => ‘yes’,
‘gtpay_gway_name’ =>‘webpay’,
‘gtpay_echo_data’ => $order_id //order id again, included as echo data to be used when control is returned
);

//print_r($post_data); die;
fn_create_payment_form($submit_url, $post_data, ‘GTPay Server’);
exit;
}


Obviously from the code, CS-Cart needs to have defined the constant BOOTSTRAP, which means this script probably shouldn’t be run directly, maybe it’s supposed to be included somewhere else, meaning my Return URL should be different. I’m sure someone must have implemented something similar so please I will appreciate your help on this. Thank you very much!

Hello ,,,

could you please tell me what should i sent back from payment gateway ? and how can i send it??

i tried to send callback url with payment and mode

[https://yourdomain.com/index.php?dispatch=payment_notification.process&payment=processor&mode=successful]

but the transaction does not complete well

i found that the order id is null and also transaction id !!! do i need to send it form the gateway

can you please help me !!!!

As mentioned in cs-cart Documentation (Adding a Payment Processor via an Add-on ) the gateway should send two mandatory parameters which are ( Payment and mode ) in as you listed above in the callback url you are only passing the payment parameter!!!!

In my example, parameters will be parse by CS-Cart core. The controller will be payment_notification and the mode will be process

Hello ,,,

could you please tell me what should i sent back from payment gateway ? and how can i send it??

i tried to send callback url with payment and mode

[https://yourdomain.com/index.php?dispatch=payment_notification.process&payment=processor&mode=successful]

but the transaction does not complete well

i found that the order id is null and also transaction id !!! do i need to send it form the gateway

can you please help me !!!!

The data should be sent by payment provider from their side. Available parameters should be described in their documentation for developers

In my example, parameters will be parse by CS-Cart core. The controller will be payment_notification and the mode will be process

it worked thank you :)