Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Thai pay module, still need some help...


Guest

Recommended Posts

Hi again....

 

Well I got so far that it actually acepts the transaction! :D but I get the same end result when it uses the backURL and I cant figure it out how to set the values on the error / success messages and get it to report that the payment is not made if some thing goes wrong in the payment...

 

Is their any one that could help me out? I am sure you guys know how to set this, so please help me a bit....

 

<?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');
   }
 }
?>

 

This is what I have done. Now what I need is the following responces on the backURL:

 

backURL: the bank ads responce=approved (or different errors)

 

following responce values is it:

 

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

 

responce=error (SIPS application error)

 

responce=inprocess (Transaction in process, waiting for creditcard approval result.?)

 

responce=approved (Creditcard authorization approved)

 

responce=declined (Creditcard autorization declined)

 

responce=outofservice (SIPS temporary out of service)

 

Hope some one can help me with this, also interested in getting my customer_id working, dont seem to show up on the payment email.

 

I also would like to ad the order number but can figure that out...

 

Sincerely

Johan

Link to comment
Share on other sites

  • 6 years later...
  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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...