Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2006
    Posts
    25
    Plugin Contributions
    0

    red flag Having a decimal problem witha a payment module

    Hi everyone,

    upgraded from 1.3.8 to 1.3.9 some time ago and got a problem with one of our payment modules.

    Basically, the payment module is giving out too many numbers after decimal point. It gives out six when only acceptable is only two decimals. What should I do with this:

    Code:
    class sppopmaksu {
        var $code, $title, $description, $enabled, $sort_order;
    
    //Custom variables
        var $refer, $refer_check, $total, $ifversion, $bid, $refid_counter, $tempid;
    
    // class constructor
        function sppopmaksu() {
            
              $this->code = 'sppopmaksu';
              $this->title = MODULE_PAYMENT_SPPOP_TEXT_TITLE;
              $this->description = MODULE_PAYMENT_SPPOP_TEXT_DESCRIPTION;
              $this->enabled = ((MODULE_PAYMENT_SPPOP_STATUS == 'True') ? true : false);
              $this->sort_order = MODULE_PAYMENT_SPPOP_SORT_ORDER;
    
                // Some configuration stuff
                $this->ifversion = "001"; // the version used by the interface. only '001' is valid at the moment
                $this->bid = 4;
    
              if ((int)MODULE_PAYMENT_SPPOP_ORDER_STATUS_ID > 0) {
                $this->order_status = MODULE_PAYMENT_SPPOP_ORDER_STATUS_ID;
              }
    
            if (is_object($order)) $this->update_status();
            $this->form_action_url = 'https://verkkomaksu.inetpankki.samlink.fi/vm/login.html';
        }
    
    // Sp/Pop-Maksu module internal methods
        function total() {
            global $order;
            $ec = explode('.', $order->info['total']);
            $this->total = $ec[0] . ',' . str_pad($ec[1], 2, '0');
            return $this->total;
        }
    
        // make_mac() Calculates the MAC code
        function make_mac() {
            $mac =     $this->ifversion . "&" .
                        $this->refer . "&" .
                        MODULE_PAYMENT_SPPOP_NET_SELLER_ID . "&" .
                        $this->total . '&' .
                        $this->mkref_check() .
                        "&EXPRESS&EUR&" .
                        MODULE_PAYMENT_SPPOP_VERIFY_KEY . "&";
    
            $this->mac_key = strtoupper(md5($mac)); // MAC string has to be upper case
            return $this->mac_key;        
        }
    
       // Reserves an ID form the DB
       function reserve_db_id() {
          global $db;
          if (empty($this->refid_counter)) {
             $refid = $db->Execute('SELECT id FROM MOD_FI_BANK_ID WHERE referid="0" AND session_id="' . session_id() . '"'); // Check if we already have an ID field
                if (empty($refid->fields['id'])) {  // If not, we create a new one
                 $db->Execute("INSERT INTO MOD_FI_BANK_ID (session_id) VALUES ('" . session_id() . "')"); // Make the reservation
                 $refid = $db->Execute('SELECT id FROM MOD_FI_BANK_ID WHERE session_id="' . session_id() . '"'); // Get the ID for the reservation
                }
             $this->refid_counter = substr($refid->fields['id'], -5); // We can use only the 5 last numbers ... this way the counter starts from zero when we hit 100000
          }
    
          return $this->refid_counter;
       }
    
       // this function creates the banks refer ID
       function make_ref() {
          if (empty($this->refer)) {
             $this->reserve_db_id();
             $this->refer = $this->bid . date("ymd") . $this->refid_counter;
          }
          return $this->refer;
       }
       
        // prior to PHP5 we don't have str_split() so for compatibility we use our own str_split() instead
        function str_split($string, $chunksize=1) {
            preg_match_all('/('.str_repeat('.', $chunksize).')/Uims', $string, $matches);
            return $matches[1];
        }
    
        // Counts a check number for the referer
        function mkref_check() {
            if ( empty($this->refer)) $this->make_ref();
            $timer = array('1','3','7');
            $refer = $this->str_split($this->refer);
            $c = 0;
            $calc = array();
    
            foreach ( $refer as $i ) {
                if ($c == 0) { $calc[] = $timer[$c] * $i; $c = 1; }
                elseif ($c == 1) { $calc[] = $timer[$c] * $i; $c = 2; }
                elseif ($c == 2) { $calc[] = $timer[$c] * $i; $c = 0; }
            }
      
            foreach ( $calc as $add ) {
                   $total += $add;
            }
    
            $next_ten = round($total, -1);
            if ($next_ten < $total) $next_ten += 10; // If the last number in $total was 5, round() returns the previous 10 so we have to set it manually to the next 10... by adding 10 :)
            return $this->refer . ($next_ten - $total);
        }
    
    // class methods
        function update_status() {
            global $order, $db;
            if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_SPPOP_ZONE > 0) ) {
                $check_flag = false;
                $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_SPPOP_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
                while (!$check->EOF) {
                    if ($check->fields['zone_id'] < 1) {
                        $check_flag = true;
                        break;
                    } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
                        $check_flag = true;
                        break;
                    }
                    $check->MoveNext();
                }
                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() {
        $this->make_ref();
          $process_button_string = zen_draw_hidden_field('NET_VERSION', $this->ifversion) .
                                   zen_draw_hidden_field('NET_STAMP', $this->refer) .
                                   zen_draw_hidden_field('NET_SELLER_ID', MODULE_PAYMENT_SPPOP_NET_SELLER_ID) .
                                   zen_draw_hidden_field('NET_AMOUNT', $this->total()) .
                                   zen_draw_hidden_field('NET_CUR', 'EUR') .
                                   zen_draw_hidden_field('NET_REF', $this->mkref_check()) .
                                   zen_draw_hidden_field('NET_DATE', 'EXPRESS') .
                                   zen_draw_hidden_field('NET_MSG', MODULE_PAYMENT_SPPOP_NET_MSG) .
                                   zen_draw_hidden_field('NET_CONFIRM', 'YES') .
                                   zen_draw_hidden_field('NET_RETURN', zen_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL') .  "&fcID=" . $this->mkref_check()) .
                                   zen_draw_hidden_field('NET_CANCEL', zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')) .
                                   zen_draw_hidden_field('NET_REJECT', zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')) . 
                                   zen_draw_hidden_field('NET_MAC', $this->make_mac());
    
            return $process_button_string;
        }
    
        // Copied from iPayment module
        function before_process() {
          $script_path = $_SERVER['HTTP_REFERER'];
          $me = explode('main_page=', $script_path);
          $result = explode('&', $me[0]);
          if ($result[0] == 'checkout_confirmation') zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
          return false;
        }
    
        function after_process() {
            global $db, $insert_id;
            $refid =  zen_db_input($_GET['fcID']);
            $db->Execute('UPDATE MOD_FI_BANK_ID SET orders_id="' . $insert_id . '", referid="' . $refid . '", session_id="" WHERE session_id="' . session_id() . '"');
            return 0;
        }
    
        function get_error() {
          global $_GET;
          $error = array('title' => MODULE_PAYMENT_SPPOP_HEADER_ERROR,
                                 'error' => MODULE_PAYMENT_SPPOP_TEXT_ERROR);
          return $error;
        }
    
        function check() {
            global $db;
    
            if (!isset($this->_check)) {
                $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_SPPOP_STATUS'");
                $this->_check = $check_query->RecordCount();
            }
                return $this->_check;
            }
    
        function install() {
            global $db;
            $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Ota Sp/Pop-maksu moduli käyttöön', 'MODULE_PAYMENT_SPPOP_STATUS', 'True', 'Hyväksytäänkö Sp/Pop-maksut?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
            $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Asiakastunnus', 'MODULE_PAYMENT_SPPOP_NET_SELLER_ID', '0000000000', 'Sp/Pop-maksu tunnuksesi', '6', '1', now())");
            $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Lajittelujärjestys.', 'MODULE_PAYMENT_SPPOP_SORT_ORDER', '0', 'Järjestysnumero maksutapa valikossa.', '6', '0', now())");
            $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Turvatarkiste', 'MODULE_PAYMENT_SPPOP_VERIFY_KEY', '11111111111111111111', 'Pankista saatu varmisteavain','6', '7', now())");
            $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Aseta tilauksen tila', 'MODULE_PAYMENT_SPPOP_ORDER_STATUS_ID', '0', 'Kun maksu on hyväksytty, aseta tilauksen tila seuraavasti', '6', '9', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
            $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Maksualue', 'MODULE_PAYMENT_SPPOP_ZONE', '0', 'Jos alue on valittu, on tämä maksutapa näkyvissä vain sillä alueella.', '6', '11', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
            $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Viesti Kuitille', 'MODULE_PAYMENT_SPPOP_NET_MSG', '', 'Vakio viesti maksajan kuitille.', '6', '10', now())");
        }
    
        function remove() {
            global $db;
            $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
        }
    
        function keys() {
            return array('MODULE_PAYMENT_SPPOP_STATUS', 'MODULE_PAYMENT_SPPOP_NET_SELLER_ID', 'MODULE_PAYMENT_SPPOP_VERIFY_KEY', 'MODULE_PAYMENT_SPPOP_NET_MSG', 'MODULE_PAYMENT_SPPOP_SORT_ORDER', 'MODULE_PAYMENT_SPPOP_ORDER_STATUS_ID', 'MODULE_PAYMENT_SPPOP_ZONE', 'MODULE_PAYMENT_SPPOP_NET_MSG');
        }
    }
    ?>
    To be more exact, it is this piece of code:
    Code:
    zen_draw_hidden_field('NET_AMOUNT', $this->total()) .
    where NET_AMOUNT should be like XX,XX$ not like XX,XXXXXX$.

    Help appreciated very much!

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Having a decimal problem witha a payment module

    You may wish to look at the existing payment modules and see how they manage the total that is sent ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

 

 

Similar Threads

  1. Payment module problem
    By metoo in forum General Questions
    Replies: 1
    Last Post: 7 Oct 2008, 05:34 AM
  2. decimal point problem
    By rajeev83 in forum General Questions
    Replies: 4
    Last Post: 26 Sep 2006, 05:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR