Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

New thai payment modul


Guest

Recommended Posts

Hi all,

 

I have tested before to get help, no success so I try once more... I need some help with a payment script to SCB bank in Thailand. It is talking to the bank and all the only problem I got now is the error / success handling up on the return from the bank.

 

I know their is a number of lines in the module I have modified but I can understand how to change them. I am a begginer with PHP and got totaly stuck!

 

I hope some one here can help me out to change these lines... This is what I have done...

 

<?php
/*
 $Id: secpay.php,v 1.31 2003/01/29 19:57:15 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/
 class scbpaythai {
   var $code, $title, $description, $enabled;

// class constructor
   function scbpaythai() {
     global $order;

     $this->code = 'scbpaythai';
     $this->title = MODULE_PAYMENT_SCBPAYTHAI_TEXT_TITLE;
     $this->description = MODULE_PAYMENT_SCBPAYTHAI_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_PAYMENT_SCBPAYTHAI_SORT_ORDER;
     $this->enabled = ((MODULE_PAYMENT_SCBPAYTHAI_STATUS == 'True') ? true : false);

     if ((int)MODULE_PAYMENT_SCBPAYTHAI_ORDER_STATUS_ID > 0) {
       $this->order_status = MODULE_PAYMENT_SCBPAYTHAI_ORDER_STATUS_ID;
     }

     if (is_object($order)) $this->update_status();

     $this->form_action_url = 'https://sips-test.scb.co.th/cc/webcredit/web_credit_payment.phtml';
   }

// class methods
   function update_status() {
     global $order;

     if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_SCBPAYTHAI_ZONE > 0) ) {
       $check_flag = false;
       $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_SCBPAYTHAI_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
       while ($check = tep_db_fetch_array($check_query)) {
         if ($check['zone_id'] < 1) {
           $check_flag = true;
           break;
         } elseif ($check['zone_id'] == $order->billing['zone_id']) {
           $check_flag = true;
           break;
         }
       }

       if ($check_flag == false) {
         $this->enabled = false;
       }
     }
   }

   function javascript_validation() {
     return false;
   }

   function selection() {
     return array('id' => $this->code,
                  'module' => $this->title);
   }

   function pre_confirmation_check() {
     return false;
   }

   function confirmation() {
     return false;
   }

   function process_button() {
     global $order, $currencies, $currency;

     switch (MODULE_PAYMENT_SCBPAYTHAI_CURRENCY) {
       case 'Default Currency':
         $sec_currency = DEFAULT_CURRENCY;
         break;
       case 'Any Currency':
       default:
         $sec_currency = $currency;
         break;
     }

     switch (MODULE_PAYMENT_SCBPAYTHAI_TEST_STATUS) {
       case 'Always Fail':
         $test_status = 'false';
         break;
       case 'Production':
         $test_status = 'live';
         break;
       case 'Always Successful':
       default:
         $test_status = 'true';
         break;
     }
  
// This is an example of the basic unit of currency in the other country
// Please defind a value of currency vary by oscommerce configuration.
//Currency US Dollar
if ( $sec_currency == "USD" )
{
$cc = "USD";
$tepaylang = "EN";
}
//Currency Baht
elseif ( $sec_currency == "Baht" )
{
$cc = "BHT";
$tepaylang = "EN";
}	
//Currency British Pound
elseif ( $sec_currency == "GBP" )
{
$cc = "GBP";
$tepaylang = "EN";
}
//Currency Euro Dollar
elseif ( $sec_currency == "EUR" )
{
$cc = "EUR";
$tepaylang = "EN";
}
function process_button() {
     global $HTTP_SERVER_VARS, $order, $customer_id;
  }

   $process_button_string = tep_draw_hidden_field('mid', MODULE_PAYMENT_SCBPAYTHAI_MERCHANT_ID) .
tep_draw_hidden_field('terminal', MODULE_PAYMENT_SCBPAYTHAI_TERMINAL_ID) .
tep_draw_hidden_field('version', '2_5_1') .
tep_draw_hidden_field('command', 'CRAUTH') .
tep_draw_hidden_field('ref_no', date('YmdHis')) .
tep_draw_hidden_field('ref_date', date('YmdHis')) .
tep_draw_hidden_field('service_id', '1') .
tep_draw_hidden_field('cust_id', $customer_id) .
tep_draw_hidden_field('cur_abbr', $cc) .
tep_draw_hidden_field('amount', number_format($order->info['total'] * $currencies->get_value($sec_currency), $currencies->currencies[$sec_currency]['decimal_places'], '.', '')) .
tep_draw_hidden_field('cust_lname', $order->billing['lastname']) .
tep_draw_hidden_field('cust_fname', $order->billing['firstname']) .
tep_draw_hidden_field('cust_email', $order->customer['email_address']) .
tep_draw_hidden_field('cust_country', $order->billing['iso_code_2']) .
tep_draw_hidden_field('cust_address1', $order->billing['street_address']) .
tep_draw_hidden_field('cust_address2', $order->billing['suburb']) .
tep_draw_hidden_field('cust_city', $order->billing['city']) .
tep_draw_hidden_field('cust_province', $order->billing['state']) .
tep_draw_hidden_field('cust_zip', $order->billing['postcode']) .
tep_draw_hidden_field('cust_phone', $order->customer['telephone']) .
tep_draw_hidden_field('ship_lname', $order->delivery['lastname']) .
tep_draw_hidden_field('ship_fname', $order->delivery['firstname']) .
tep_draw_hidden_field('ship_country', $order->delivery['iso_code_2']) .
tep_draw_hidden_field('ship_address1', $order->delivery['street_address']) .
tep_draw_hidden_field('ship_address2', $order->delivery['suburb']) .
tep_draw_hidden_field('ship_city', $order->delivery['city']) .
tep_draw_hidden_field('ship_province', $order->delivery['state']) .
tep_draw_hidden_field('ship_zip', $order->delivery['postcode']) .
tep_draw_hidden_field('description', STORE_NAME . date('Ymdhis')) .
tep_draw_hidden_field('backURL', tep_href_link(FILENAME_CHECKOUT_PROCESS , '', 'SSL', true)) .
tep_draw_hidden_field('settlement_flag', MODULE_PAYMENT_SCBPAYTHAI_SETTLEMENT) .

   tep_draw_hidden_field('callback', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', false) . ';' . tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code, 'SSL', false)) .
   tep_draw_hidden_field(tep_session_name(), tep_session_id()) .
   tep_draw_hidden_field('options', 'test_status=' . $test_status . ',dups=false,cb_post=true,cb_flds=' . tep_session_name());

     return $process_button_string;
   }

   function before_process() {
     global $HTTP_POST_VARS;

     if ($HTTP_POST_VARS['valid'] == 'true') {
       if ($remote_host = getenv('REMOTE_HOST')) {
         if ($remote_host != 'phuketmuaythai.com') {
           $remote_host = gethostbyaddr($remote_host);
         }
         if ($remote_host != 'phuketmuaythai.com') {
           tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, tep_session_name() . '=' . $HTTP_POST_VARS[tep_session_name()] . '&payment_error=' . $this->code, 'SSL', false, false));
         }
       } else {
         tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, tep_session_name() . '=' . $HTTP_POST_VARS[tep_session_name()] . '&payment_error=' . $this->code, 'SSL', false, false));
       }
     }
   }

   function after_process() {
     return false;
   }

   function get_error() {
     global $HTTP_GET_VARS;

     if (isset($HTTP_GET_VARS['message']) && (strlen($HTTP_GET_VARS['message']) > 0)) {
       $error = stripslashes(urldecode($HTTP_GET_VARS['message']));
     } else {
       $error = MODULE_PAYMENT_SCBPAYTHAI_TEXT_ERROR_MESSAGE;
     }

     return array('title' => MODULE_PAYMENT_SCBPAYTHAI_TEXT_ERROR,
                  'error' => $error);
   }

   function check() {
     if (!isset($this->_check)) {
       $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_SCBPAYTHAI_STATUS'");
       $this->_check = tep_db_num_rows($check_query);
     }
     return $this->_check;
   }

   function install() {
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable SCB Payment Module', 'MODULE_PAYMENT_SCBPAYTHAI_STATUS', 'True', 'Do you want to accept SCBPAYTHAI payments?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Merchant ID', 'MODULE_PAYMENT_SCBPAYTHAI_MERCHANT_ID', 'scbpaythai', 'Merchant ID to use for SIPS service', '6', '2', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Terminal ID', 'MODULE_PAYMENT_SCBPAYTHAI_TERMINAL_ID', 'scbpaythai', 'Terminal ID to use for SIPS service', '6', '2', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Currency', 'MODULE_PAYMENT_SCBPAYTHAI_CURRENCY', 'Any Currency', 'The currency to use for credit card transactions', '6', '3', 'tep_cfg_select_option(array(\'Any Currency\', \'Default Currency\'), ', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Mode', 'MODULE_PAYMENT_SCBPAYTHAI_TEST_STATUS', 'Always Successful', 'Transaction mode to use for the SCBPAYTHAI service', '6', '4', 'tep_cfg_select_option(array(\'Always Successful\', \'Always Fail\', \'Production\'), ', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Settlement Decision For The Transaction', 'MODULE_PAYMENT_SCBPAYTHAI_SETTLEMENT', '0', '0 Auto Settlement is Default.  1 Settlement upon request. If a transaction is not settled within 4 days, the transaction would automatically cancelled', '6', '2', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_SCBPAYTHAI_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_SCBPAYTHAI_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_SCBPAYTHAI_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
   }

   function remove() {
     tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
   }

   function keys() {
     return array('MODULE_PAYMENT_SCBPAYTHAI_STATUS', 'MODULE_PAYMENT_SCBPAYTHAI_MERCHANT_ID', 'MODULE_PAYMENT_SCBPAYTHAI_TERMINAL_ID', 'MODULE_PAYMENT_SCBPAYTHAI_CURRENCY', 'MODULE_PAYMENT_SCBPAYTHAI_TEST_STATUS', 'MODULE_PAYMENT_SCBPAYTHAI_SETTLEMENT', 'MODULE_PAYMENT_SCBPAYTHAI_ZONE', 'MODULE_PAYMENT_SCBPAYTHAI_ORDER_STATUS_ID', 'MODULE_PAYMENT_SCBPAYTHAI_SORT_ORDER');
   }
 }
?>

 

Now the responce from SCB in Thailand will look like this:

 

Authorization Request Response

 

Command CreditResponse ? response from SIPS Authorization request can be sent by 2 channels. (SIPS responds via both channels):

 

3.1 "backURL" : field 45 from Authorization Request format

 

After the payment process was done, SIPS would return the webpage address to the backURL using the same authorization request format and together with the backurl, SIPS will include a response parameter advising of the result of the process.

 

Example:

 

If "backURL=http://www.test.com/return.asp?return=1"

 

SIPS would return to the backURL page and also add the response to the backURL.

 

http://www.test.com/return.asp?return=1&response=approved

 

Or if "backURL=http://www.test.com/return.asp"

 

SIPS would return to the backURL page and also add the response to the backURL.

 

http://www.test.com/return.asp?response=approved

 

response=canceled (Customer canceled from SIPS Payment, No payment has been done.)

 

response=error (Transaction in process, waiting for creditcard approval result.)

 

response=approved (Creditcard authorization approved)

 

response=declined (Creditcard authorization declined)

 

response=outofservice (SIPS temporary out of service)

 

Hope some one can help me out...

 

 

Sincerely

Johan

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...