简体   繁体   中英

snapscan & cs-cart integration

I have been asked to help integrate snapscan into cs-cart as there is no api for cs-cart as yet. I wrote this code in order to do the outside_CC type style

 <?php

if(!defined('BOOTSTRAP')) die('Direct Access Denied');

if(!defined('PAYMENT_NOTIFICATION')) {
    $mode = $processor_data['processor_params']['mode'];
    if($mode) {
        $form['id'] = $processor_data['processor_params']['id'];
        $form['key'] = $processor_data['processor_params']['key'];
    } else {
        $form['id'] = 'shopalot';
        $form['key'] = 'secret';
    }
    $form['reference'] = 'Order_'.$order_id;
    $form['amount'] = number_format($order_info['total']*1, 2,'','');
    $form['currency'] = 'ZAR';
    $form['url'] = fn_url('payment_notification.notify?payment=snapscan&order_id='.$order_id,AREA,'current');
    $form['date'] = date('d-m-Y H:i');
    $form['email'] = $order_info['email'];
    $checksum = $form['id'].'|'.$form['reference'].'|'.$form['amount'].'|'.$form['currency'].'|'.$form['url'].'|'.$form['date'].'|'.$form['email'].'|'.$form['key'];
    $form['checksum'] = md5($checksum);
echo <<<s
<html>

<body >

        <form action="https://pos.snapscan.io/qr/$form[id]?id=$order_id&amount=$form[amount]&strict=true" method="POST" >
        <input name="MERCHANT_ID" type="hidden" value="$form[id]">
        <input name="REFERENCE" type="hidden" value="$form[reference]">
        <input name="AMOUNT" type="hidden" value="$form[amount]">
        <input name="CURRENCY" type="hidden" value="ZAR">
        <input name="RETURN_URL" type="hidden" value="$form[url]">
        <input name="TRANSACTION_DATE" type="hidden" value="$form[date]">
        <input name="EMAIL" type="hidden" value="$form[email]">
        <input name="CHECKSUM" type="hidden" value="$form[checksum]">
    </form>
    <script>document.forms[0].submit();</script>


</body>
</html>
s;
    die;
}else{
    $order_id = $_REQUEST['order_id'];
    $order_info = fn_get_order_info($order_id);
    $payment_id = db_get_field("SELECT payment_id FROM ?:orders WHERE order_id = ?i",$order_id);
    $processor_data = fn_get_payment_method_data($payment_id);
    $status = $_POST['TRANSACTION_STATUS'];
    if($status == 1 && fn_check_payment_script('snapscan.php',$order_id)) {
        $pp_response['order_status'] = 'P';
        $pp_response['reason_text'] = 'The User Completed Payment with SnapScan';
        fn_update_order_payment_info($order_id,$pp_response);
        fn_change_order_status($order_id,$pp_response['order_status'],'',false);
    } else {
        $pp_response['order_status'] = 'F';
        $pp_response['reason_text'] = 'Your Payment was Unsuccessful';
        fn_finish_payment($order_id,$pp_response,false);
    }
    fn_order_placement_routines('route',$order_id);
}

?>

This kind of works, it does say page not found, but on refresh it works fine, pulling order number and amount across. My question or help I require is how do I get the customer back to cs-cart after payment is made in order to place the order? its not like a credit card where it processes via your browser, as this requires a mobile cell phone.

here is the information from snapscan

http://developer.getsnapscan.com/#overview

I have also tried various options like popup windows that work great, but also pop up if you have paid by credit card.

the other other option I thought of doing was try and identify a particular payment method like this,

 {if '$SnapScan'}
<script language="javascript">
timer=setTimeout("window.open('https://pos.snapscan.io/qr/J0v26eBZ?id={$order_info.order_id}&amount={$order_info.total*100}&strict=true','','width=800,height=600')",5000)
</script>
{else}
DO NOTHING
{/if}

Please could someone offer a possible solution to my dilema

As per documentation, I can only affirm this: Webhooks.

"We recommend that you make use of a webhook to be notified of payment completing due to the real-time nature of the system."

Try this code to post the form automatically:

<html>
<body onLoad="javascript:document.process.submit();">
<form action="https://pos.snapscan.io/qr/$form[id]?id=$order_id&amount=$form[amount]&strict=true" method="POST" name="process">
        <input name="MERCHANT_ID" type="hidden" value="$form[id]">
        <input name="REFERENCE" type="hidden" value="$form[reference]">
        <input name="AMOUNT" type="hidden" value="$form[amount]">
        <input name="CURRENCY" type="hidden" value="ZAR">
        <input name="RETURN_URL" type="hidden" value="$form[url]">
        <input name="TRANSACTION_DATE" type="hidden" value="$form[date]">
        <input name="EMAIL" type="hidden" value="$form[email]">
        <input name="CHECKSUM" type="hidden" value="$form[checksum]">
</form>
</body>
</html>

To receive response from SnapScan, please use Webhook:

http://developer.getsnapscan.com/#webhook

Unfortunately their documentation regarding webhook is very poor. Please contact support team for more details. For example, if the payment script is located in the app/payments directory, webhook URL should refer to:

http://your_domain.com/app/payments/your_snapscan_script.php

The code which processes the response should start from:

if (!defined('BOOTSTRAP')) {
    require './init_payment.php';
    .... YOUR CUSTOM CODE HERE ....
}

Do not forget to remove the following line from the beginning of the file:

if (!defined('BOOTSTRAP') ) { die('Access denied'); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM