Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Shipping and Taxes added twice on Order Confirmation


scubes13

Recommended Posts

Hey guys,

 

We are about to go live with our site, BUT we have one problem.

 

When a customer checks out, the order confirmation page shows:

 

Sub Total: 10.00

Tax: (6%) 0.60

Shipping: 5.00 (flat rate)

Total: 15.60

 

OK, this much is right so far.

 

Now, upon confirmation, the user gets an email confirming -

Sub Total: 10.00

Tax: (6%) 0.60

Shipping: 5.00 (flat rate)

Total: 15.60

 

Then, when I go into Surepay to verify the order, I am shown the following on the order -

Sub Total: 15.60

Tax: 0.94

Shipping: 5.00

Total: 21.54

 

Once I get it from Surepay, it is adding the tax a second time.

 

I was thinking this might be a bug in SurePay itself, but then I realized that my OSCommerce had told it to charge that ammount.

 

Now I am assuming the problem is within the actual SUREPAY module that I am using.

 

Anyone had these problems before? Any solutions?

 

Any and all help would be greatly appreciated!

 

Thanks,

Kevin Landers

Link to comment
Share on other sites

  • 1 month later...

I fixed this iast night and I am still a little excited. The surepay tech support is a one-man operation, so talking to that dept. is hit or miss. I hope nobody else has to go through what I had to go through just to get some info.

 

The short answer to the fix is that there are 2 lines that need to be commented out. The both have to do with shipping. There are in the file /catalog/includes/modules/payment/surepay.php

 

On or around lines 312-313, comment out these lines (the two regarding shipping cost):

$auth = $ssp->add_auth(

        array(

            'ordernumber'    => $order_number,

            'ecommerce'      => 'true',

            'ecommercecode'  => '07',

            'ipaddress'      => $REMOTE_ADDR,

##          'shippingcost'    => $shipping_cost,

##          'shippingcost2'  => "0.00USD",

            'taxamount'      => $HTTP_POST_VARS[ 'surepay_tax' ],

            'referringurl'    => $HTTP_REFERER,

            'browsertype'    => $HTTP_USER_AGENT

            )

        );

 

I will add a contrib to the surepay modules as well.

Link to comment
Share on other sites

By the way,

 

My problem with Surepay is that it was double adding the shipping. We are a distributor and dont charge sales tax. My guess is that the lines of code around 312-313 concerning sales tax are what needs to be commented out.

 

Try experimenting with this.

 

Our company has ~24 hours b/t when an order is authorized and when it is settled. Up until I fixed it, we'd login to the Surepay manager tool and alter the sales before they settled. This was our temp. solution until the problem was fixed.

Link to comment
Share on other sites

Commenting out the next line will stop the tax from doubling as well - see below. The shipping and tax amounts will not show individually in the SurePay Manager after these changes but are all totaled with the product costs. *** Thanks recaddy for your work! *** - Ken

 

File to modify: /catalog/includes/modules/payment/surepay.php

 

$auth = $ssp->add_auth(

array(

'ordernumber' => $order_number,

'ecommerce' => 'true',

'ecommercecode' => '07',

'ipaddress' => $REMOTE_ADDR,

## 'shippingcost' => $shipping_cost,

## 'shippingcost2' => "0.00USD",

## 'taxamount' => $HTTP_POST_VARS[ 'surepay_tax' ],

'referringurl' => $HTTP_REFERER,

'browsertype' => $HTTP_USER_AGENT

)

);

Link to comment
Share on other sites

Ok,

 

I am using just normal OSC 2.2 MS1

 

I did the changes that you guys mentioned, however, I still find the double shipping and tax ammounts added.

 

Anyone have any suggestions for further investigation?

 

I will post the three surepay files later tonight once I have access to them.

 

Thanks!

 

Kevin L.

Link to comment
Share on other sites

Ok, went ahead and got the code.

 

First, my /includes/languages/english/modules/payment/surepay.php file:

 

<?php
/*
 $Id: surepay.php,v 1.3 2003/04/02 23:22:30 stng Exp $

 The Exchange Project - Community Made Shopping!
 http://www.theexchangeproject.org

 Copyright (c) 2000,2001 The Exchange Project

 Released under the GNU General Public License
*/

   define( 'MODULE_PAYMENT_SUREPAY_TEXT_TITLE', 'SurePay' );
   define( 'MODULE_PAYMENT_SUREPAY_TEXT_DESCRIPTION', 'Credit Card Test Info:<br><br>CC#: 4012000033330026<br>Expiry: Any' );
   define( 'MODULE_PAYMENT_SUREPAY_TEXT_TYPE', 'Type:' );
   define( 'MODULE_PAYMENT_SUREPAY_TEXT_CREDIT_CARD_NUMBER', 'Credit Card Number:' );
   define( 'MODULE_PAYMENT_SUREPAY_TEXT_CREDIT_CARD_EXPIRES', 'Credit Card Expiry Date:' );
   define( 'MODULE_PAYMENT_SUREPAY_TEXT_CREDIT_CARD_CVV2', 'CVV2:' );
   define( 'MODULE_PAYMENT_SUREPAY_TEXT_JS_CC_NUMBER', '* The credit card number must be at least ' . CC_NUMBER_MIN_LENGTH . " characters." );
   define( 'MODULE_PAYMENT_SUREPAY_TEXT_ERROR', 'Credit Card Error!' ); 
   define( 'MODULE_PAYMENT_SUREPAY_TEXT_ERROR_DECLINED', 'There has been an error processing your credit card!  Please try again.  If this problem continues to occur, please contact your credit card company.' ); 
?>

 

Now, my /includes/modules/payment/surepay.php file:

 

<?php
/*=====================================================================
   SurePay Payment Module 0.1.0 for OS Commerce
 ---------------------------------------------------------------------
   File:
       includes/modules/payment/surepay.php
   Description:
       OS Commerce payment module class.  This class implements the 
       functionality used by OS Commerce for new payment modules
   Warning:
       Only supports transactions in US dollars.  Any numbers/prices 
       are assumed to be in USD!
 ---------------------------------------------------------------------
   Please contact Stanford Ng at [email protected] if you have any 
     problems, suggestions, or shiny offerings.  :)
   This module relies on Sauen PHP Surepay by J.T. Stokkeland, which
     is packaged along with this module.  For the latest version, try
     Sauen.Com.
   
   osCommerce, Open Source E-Commerce Solutions
   http://www.oscommerce.com
   
   Licensed under GNU General Public License (GPL) v2.0
   Copyright (C) 2002 Stanford Ng
   
   This code-collection is free software; you can redistribute it
   and/or modify it under the terms of the GNU General Public License 
   as published by the Free Software Foundation; either version 2 of 
   the License, or (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to: 
   Free Software Foundation, Inc.
   59 Temple Place, Suite 330
   Boston, MA  02111-1307  USA

 ===================================================================*/

define( TABLE_SUREPAY_TRANSACTIONS, "surepay_transactions" );


/*
Class implementing the OS Commerce Payment Module interface.
*/
class surepay
{
   var $enabled, $login, $password, $test_mode;
   var $code, $title, $description;
   var $cc_number, $cc_cvv2, $cc_expires_month, $cc_expires_year;
   var $cc_card_type;
   

// class constructor
   function surepay()
   {
       global $HTTP_POST_VARS;
       $this->code = 'surepay';
       $this->title = MODULE_PAYMENT_SUREPAY_TEXT_TITLE;
       $this->description = MODULE_PAYMENT_SUREPAY_TEXT_DESCRIPTION;
       $this->enabled = MODULE_PAYMENT_SUREPAY_STATUS;
       $this->test_mode = MODULE_PAYMENT_SUREPAY_TESTMODE;
       $this->login = MODULE_PAYMENT_SUREPAY_LOGIN;
       $this->password = MODULE_PAYMENT_SUREPAY_PASSWORD;
       $this->cc_number = tep_db_prepare_input( $HTTP_POST_VARS['surepay_cc_number'] );
       $this->cc_cvv2 = tep_db_prepare_input( $HTTP_POST_VARS['surepay_cc_cvv2'] );
       $this->cc_expires_month = tep_db_prepare_input( $HTTP_POST_VARS['surepay_cc_expires_month'] );
       $this->cc_expires_year = tep_db_prepare_input( $HTTP_POST_VARS['surepay_cc_expires_year'] );
   }

   
   /*
       Generates a javascript snippet that validates the credit card #. 
   */
   function javascript_validation()
   {
     $js = '  if (payment_value == "' . $this->code . '") {' . "\n" .
           '    var cc_number = document.checkout_payment.surepay_cc_number.value;' . "\n" .
           '    if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" .
           '      error_message = error_message + "' . MODULE_PAYMENT_SUREPAY_TEXT_JS_CC_NUMBER . '";' . "\n" .
           '      error = 1;' . "\n" .
           '    }' . "\n" .
           '  }' . "\n";

     return $js;
   }

   
   
   function selection()
   {
       global $order;

       // -- Generates an array containing the text names of each month of the year.
       for( $i=1; $i < 13; $i++ )
       {
           $expires_month[] = array( 'id' => sprintf( '%02d', $i ), 'text' => strftime( '%B', mktime( 0, 0, 0, $i, 1, 2000 ) ) );
       }
       
       // -- Generates an array containing this year and the next nine years.        
       $today = getdate(); 
       for( $i = $today['year']; $i < $today['year'] + 10; $i++)
       {
           $expires_year[] = array( 'id' => strftime( '%y', mktime( 0, 0, 0, 1, 1, $i ) ), 'text' => strftime( '%Y', mktime( 0, 0, 0, 1, 1, $i ) ) );
       }

       $selection = array( 
           'id' => $this->code,
           'module' => $this->title,
           'fields' => array( 
                           array( 'title' => MODULE_PAYMENT_SUREPAY_TEXT_CREDIT_CARD_NUMBER,
                                   'field' => tep_draw_input_field( 'surepay_cc_number' ) ),
                           array( 'title' => MODULE_PAYMENT_SUREPAY_TEXT_CREDIT_CARD_CVV2,
                                   'field' => tep_draw_input_field( 'surepay_cc_cvv2' ) ),
                           array( 'title' => MODULE_PAYMENT_SUREPAY_TEXT_CREDIT_CARD_EXPIRES,
                                   'field' => tep_draw_pull_down_menu( 'surepay_cc_expires_month', $expires_month ) . ' ' . tep_draw_pull_down_menu( 'surepay_cc_expires_year', $expires_year ) )
                       )
       );
       return $selection;
   }


   /*
       Runs some simple checks to see if the information entered is potentially valid.
       The pre_process methods does the real validation via SurePay's service.
   */
   function pre_confirmation_check() {
     global $HTTP_POST_VARS;

     include(DIR_WS_CLASSES . 'cc_validation.php');

     $cc_validation = new cc_validation();
     $result = $cc_validation->validate($HTTP_POST_VARS['surepay_cc_number'], $HTTP_POST_VARS['surepay_cc_expires_month'], $HTTP_POST_VARS['surepay_cc_expires_year']);

     $error = '';
     switch ($result) {
       case -1:
         $error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
         break;
       case -2:
       case -3:
       case -4:
         $error = TEXT_CCVAL_ERROR_INVALID_DATE;
         break;
       case false:
         $error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
         break;
     }

     if ( ($result == false) || ($result < 1) ) {
       $payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($error) . '&surepay_cc_expires_month=' . $HTTP_POST_VARS['surepay_cc_expires_month'] . '&surepay_cc_expires_year=' . $HTTP_POST_VARS['surepay_cc_expires_year'];
       tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));
     }

     $this->cc_card_type = $cc_validation->cc_type;
     $this->cc_card_number = $cc_validation->cc_number;
   }

   
   /*
       Generates the snippet of HTML that is displayed for confirmation from the user that all the
       credit card info was entered correctly.
   */
   function confirmation()
   {
       global $CardName, $CardNumber, $checkout_form_action;
     global $HTTP_POST_VARS;

     $confirmation = array('title' => $this->title,
                           'fields' => array(array('title' => MODULE_PAYMENT_SUREPAY_TEXT_TYPE,
                                                   'field' => $this->cc_card_type ),
                                             array('title' => MODULE_PAYMENT_SUREPAY_TEXT_CREDIT_CARD_NUMBER,
                                                   'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4) ),
                                             array('title' => MODULE_PAYMENT_SUREPAY_TEXT_CREDIT_CARD_CVV2,
                                                   'field' => $this->cc_cvv2 ),
                                             array('title' => MODULE_PAYMENT_SUREPAY_TEXT_CREDIT_CARD_EXPIRES,
                                                   'field' => strftime('%B, %Y', mktime(0,0,0,$HTTP_POST_VARS['surepay_cc_expires_month'], 1, '20' . $HTTP_POST_VARS['surepay_cc_expires_year'])))));
     return $confirmation;
   }

   
   /*
       Used to pass the credit card info via hidden fields to the process page.   
   */
   function process_button()
   {
       global $HTTP_POST_VARS, $CardName, $CardNumber, $order;
       
       // TODO: enter real tax rate.
       $process_button_string = tep_draw_hidden_field( 'surepay_cc_number', $this->cc_number ) .
                                tep_draw_hidden_field( 'surepay_cc_cvv2', $this->cc_cvv2 ) .
                                tep_draw_hidden_field( 'surepay_cc_expires_month', $this->cc_expires_month ) .
                                tep_draw_hidden_field( 'surepay_cc_expires_year', $this->cc_expires_year ) .
                                tep_draw_hidden_field( 'surepay_fullname', $order->customer['firstname'] . ' ' . $order->customer['lastname'] ) .
                                tep_draw_hidden_field( 'surepay_address', $order->customer['street_address'] ) .
                                tep_draw_hidden_field( 'surepay_city', $order->customer['city'] ) .
                                tep_draw_hidden_field( 'surepay_state', $order->customer['state'] ) .
                                tep_draw_hidden_field( 'surepay_postcode', $order->customer['postcode'] ) .
                                tep_draw_hidden_field( 'surepay_country',$order->customer['country']['title'] ) .
                                tep_draw_hidden_field( 'surepay_phone', $order->customer['telephone'] ) .
                                tep_draw_hidden_field( 'surepay_email', $order->customer['email_address'] ) .
                                tep_draw_hidden_field( 'surepay_delivery_fullname', $order->delivery[ 'firstname' ] . ' ' . $order->delivery[ 'lastname' ] ) .
                                tep_draw_hidden_field( 'surepay_delivery_address', $order->delivery['street_address'] ) .
                                tep_draw_hidden_field( 'surepay_delivery_city', $order->delivery['city'] ) .
                                tep_draw_hidden_field( 'surepay_delivery_state', $order->delivery['state'] ) .
                                tep_draw_hidden_field( 'surepay_delivery_postcode', $order->delivery['postcode'] ) .
                                tep_draw_hidden_field( 'surepay_delivery_country',$order->delivery['country']['title'] ) .
                                tep_draw_hidden_field( 'surepay_tax_rate', '0.00' ) .
                                tep_draw_hidden_field( 'surepay_shipping_cost', number_format( $order->info['shipping_cost'], 2 ) . 'USD' ) .
                                tep_draw_hidden_field( 'surepay_tax', number_format( $order->info[ 'tax' ], 2 ) . 'USD' ) .
                                tep_draw_hidden_field( 'surepay_total', number_format( $order->info[ 'total' ], 2 ) . 'USD' )
                               ;
       
       return $process_button_string;
   }
   
   
   /*
       This is where most of the legwork is done.  SurePay is contacted via a SSL connection
       and the credit card authorization is performed.  If it fails, the user is redirected
       to an error page.
   */
   function before_process()
   {
       global $HTTP_POST_VARS, $language;
       require( DIR_WS_LANGUAGES . $language . "/modules/payment/surepay.php" );
       require( DIR_WS_CLASSES . "sausurepay.php" );
       
       #  Creditcard test AUTH:
       #     cc number: 4012000033330026   any future exp date
       #     $11 = AUTH     $21 = "REF"   $31 = "DCL"   any other may give "ERR"
       #     This test request uses total $1 shipping, and 1x$5 + 1x$5 goods, 
       #     total $11. Just change the item quantities to try the other status.
       #  I have also found some bugs and weakneses in Surepays processing, here is a 
       #  couple of them:
       #
       #   - Do not add % as character data, best off staying away from it totally.
       #     This can cause surepays servlets to crash and gives a 500 server error.
       #
       #   - Do not convert < > & ' " to the correct XML entities, surepays parser or
       #     data collector rejects any characterdata like < and so on.
       #
       #   - Phone numbers in address are limited length (stay 11 digits or less), they
       #     claim to be "US domestic oriented" (?)
       #
       #   - What is the correct way to handle ref? Should the script handle and check
       #     avs and cvv2status responses to something automatically? If someone has 
       #     a guideline to this would be appreciated.. ([email protected])
       
       ## Syntax: 
       ##  vobject_identifier: sausp ( 
       ##     boolean: live?
       ##    ,string: merchant id
       ##    ,string: password
       ##   [,array: extra pp.request parameters ] 
       ##  )
       
       
       // --- Create the SurePay request object. ---

       // --- This is where you can change some of the settings. ---        
       $amount = $HTTP_POST_VARS[ 'surepay_total' ];
       $shipping_cost = $HTTP_POST_VARS[ 'surepay_shipping_cost' ];
       if( $this->test_mode == true )
       {
           // --- Fill in the info for the fake auth requests. ---
           $shipping_cost = '0.00USD';
           $amount = '11.00USD';   // Use this amount if you want to test: card okay.
           $amount = '31.00USD';   // Use this amount if you want to test: card referred to voice center.
           $amount = '44.00USD';   // Use this amount if you want to test: card declined.
           
           // -- Random valid generator.
           if( rand() % 2 == 1 )
           {
               $amount = '11.00USD';
           }
       }

       // -- Figure out whether to use xml.test.surepay.com (test) or xml.surepay.com (live). 
       $live = !($this->test_mode);

       $ssp = new sausp( $live, $this->login, $this->password );
       if( $ssp->err )
       {
           die( $ssp->err );
       }
       
       // --- Generate SurePay order id. ---
       // --   Note that this is not the same as the order_id in OS Commerce, which does
       // --   not exist until after a payment is approved.
       
       tep_db_perform( TABLE_SUREPAY_TRANSACTIONS, array( message => '' ) );
       $order_number = tep_db_insert_id();
       
       // --- Add miscellanous auth request info. ---
       // --   ecommercecode specifies the level of encryption( default is 07 - SSL, ) 
       // --   05 - secure w/ cardholder & merchant cert,
       // --   06 - secure w/ merchant cert
       // --   07 - SSL
       // --   08 - no security
       
       $auth = $ssp->add_auth( 
       array(
           'ordernumber'     => $order_number,
           'ecommerce'       => 'true',
           'ecommercecode'   => '07',
           'ipaddress'       => $REMOTE_ADDR,
        ## 'shippingcost' => $shipping_cost,
        ## 'shippingcost2' => "0.00USD",
        ## 'taxamount' => $HTTP_POST_VARS[ 'surepay_tax' ],
           'referringurl'    => $HTTP_REFERER,
           'browsertype'     => $HTTP_USER_AGENT
           )
       );
           
       if( $ssp->err )
       {
           die( $ssp->err );
       }

       
       // --- Add the shipping address using the order info. ---
       
       $ssp->add_shipping_address(
           $auth,
           array(
               'fullname' => $HTTP_POST_VARS[ 'surepay_delivery_fullname' ],
               'address1' => $HTTP_POST_VARS[ 'surepay_delivery_address' ],
               'address2' => '',
               'city'     => $HTTP_POST_VARS[ 'surepay_delivery_city' ],
               'state'    => $HTTP_POST_VARS[ 'surepay_delivery_state' ],
               'zip'      => $HTTP_POST_VARS[ 'surepay_delivery_postcode' ],
               'country'  => $HTTP_POST_VARS[ 'surepay_delivery_country' ],
               'phone'    => $HTTP_POST_VARS[ 'surepay_phone' ],
               'email'    => $HTTP_POST_VARS[ 'surepay_email' ]
           )
       );
       
       if( $ssp->err )
       {
           die( $ssp->err );
       }

       // --- Add the credit card info. ---
       ## Syntax:
       ##  object_identifier: add_creditcard (
       ##      object_identifier: parent object
       ##     ,string: card number
       ##     ,string: expiration (mm/yy)
       ##     ,int: cvv2 code from card
       ##    [,int: cvv2status (security mode) (0|1|9) default is 1 (In Use), 0 = off, 9 = no code available ]
       ##    [,array: billing address]
       ##  )

       $creditcard = $ssp->add_creditcard(
           $auth,
           $this->cc_number,
           $this->cc_expires_month . "/" . $this->cc_expires_year,
           $this->cc_cvv2
       );
       
       
       // --- Add the billing address for the order. ---
       
       $ssp->add_billing_address(
           $creditcard,
           array(
               'fullname' => $HTTP_POST_VARS[ 'surepay_fullname' ],
               'address1' => $HTTP_POST_VARS[ 'surepay_address' ],
               'address2' => '',
               'city'     => $HTTP_POST_VARS[ 'surepay_city' ],
               'state'    => $HTTP_POST_VARS[ 'surepay_state' ],
               'zip'      => $HTTP_POST_VARS[ 'surepay_postcode' ],
               'country'  => $HTTP_POST_VARS[ 'surepay_country' ],
               'phone'    => $HTTP_POST_VARS[ 'surepay_phone' ],
               'email'    => $HTTP_POST_VARS[ 'surepay_email' ]
           )
       );

       if( $ssp->err )
       {
           die( $ssp->err );
       }

       // --- Add total as lineitem ---
       // -- We only add one lineitem with the total right now.  If you wanted to, you could
       // --  rewrite this to use multiple lineitems to more accurately reflect the items
       // --  in the current order.
        
       ## Syntax:
       ##  object_identifier: add_lineitem (
       ##      object_identifier: parent object (The AUTH object)
       ##     ,int: quantity,
       ##     ,string: sku,
       ##     ,string: description, 
       ##     ,string: unit cost (currency) [d..d]d.ccUSD
       ##     ,real: taxrate in decimal notation (0.08 = 8%)
       ##    [,array: options ]
       ##  )
   
       $item = $ssp->add_lineitem (
           $auth,
           '1',
           'ORDER_TOTAL',
           'Order total for this order.',
           $amount,
           $HTTP_POST_VARS[ 'surepay_tax_rate' ]
       );
   
       if( $ssp->err )
       {
           die( $ssp->err );
       }
   
       // --- Generate the XML request for SurePay. ---
       $ssp->prepare_request();
       if( $ssp->err )
       {
           die($ssp->err);
       }

       // TODO: remove.  debug info
       if( $surepay_debug_mode )
       {
           echo "server: " . $ssp->serverurl;
           echo "</PRE><h2>The request xml we send:</H2><PRE>" . 
           htmlentities($ssp->xml_request,ENT_QUOTES) . "\n<hr>";
       }
       
       // --- Send the request to SurePay. ---
       $ssp->submit_request();
       if( $ssp->err )
       {
           die( $ssp->err );
       }
       
       // TODO: remove  debug info
       if( $surepay_debug_mode )
       {
          echo "</PRE><h2>The response xml we got back:</H2><PRE>" . 
          htmlentities($ssp->xml_response,ENT_QUOTES) . "\n<hr>";
          die( "\n<br>end" );
       }
       
       $responsecount = $ssp->parse_response();
       if( $ssp->err )
       {
           die( $ssp->err );
       }

       if( !$responsecount )
       {
           die( "Invalid response count.\n" );
       }

       
       // --- Check through the AUTH responses. --- 
       
       $auths = $ssp->auths();
       if( $ssp->err )
       {
           die( $ssp->err );
       }

       while( list( $key, $ssp_order ) = each( $auths ) )
       {
           // -- Store the transaction record in the SurePay table. ---
           $sql_data_array = array(
               'auth_code' => $ssp->auth_authcode( $ssp_order ),
               'transaction_id' => $ssp->auth_trans_id( $ssp_order ),
               'message' => $ssp->auth_text( $ssp_order )
           );
           tep_db_perform( TABLE_SUREPAY_TRANSACTIONS, $sql_data_array, 'update', 'request_id = ' . $ssp_order );
           if( $ssp->auth_status( $ssp_order ) != 'AUTH' )
           {
               // -- Redirect to error page.
               $err_msg = $ssp->auth_text( $ssp_order );
               tep_redirect( tep_href_link( FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . stripslashes( MODULE_PAYMENT_SUREPAY_TEXT_ERROR_DECLINED ), 'SSL', true, false ) );
           }
           
           if( $ssp->err )
           {
               die( $ssp->err );
           }
       }
   }

   
   /*
       No functionality yet.  This is called after the processing of the order info into the 
       database for OS Commerce.
   */
   function after_process()
   {
       return;
   }

    /*
       Returns SurePay errors.  Used in the pre-confirmation checks, iirc. 
   */

   function get_error() {
     global $HTTP_GET_VARS;
     
     // TODO: append surepay_err_header too?

     $error = array('title' => MODULE_PAYMENT_SUREPAY_TEXT_ERROR,
                    'error' => stripslashes(urldecode($HTTP_GET_VARS['error'])));

     return $error;
   }

   
   /*
       Checks to see if this payment module is installed.
   */
   function check()
   {
       if( !isset( $this->_check ) )
       {
           $check_query = tep_db_query( "select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_SUREPAY_STATUS'" );
           $this->_check = tep_db_num_rows( $check_query );
       }
       return $this->_check;
   }

   /*
       Installs this payment module into OS Commerce.
   */
   function install()
   {
       tep_db_query( "insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Allow Surepay', 'MODULE_PAYMENT_SUREPAY_STATUS', '1', 'Do you want to accept Surepay payments?', '6', '0', now())" );
       tep_db_query( "insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Surepay Login', 'MODULE_PAYMENT_SUREPAY_LOGIN', '1001', 'Merchant id used for Surepay processing', '6', '0', now())" );
       tep_db_query( "insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Surepay Password', 'MODULE_PAYMENT_SUREPAY_PASSWORD', 'password', 'Password used for Surepay processing', '6', '0', now())" );
       tep_db_query( "insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Surepay Test Mode', 'MODULE_PAYMENT_SUREPAY_TESTMODE', '1', 'Test mode for Surepay payments', '6', '0', now())" );
       tep_db_query( "create table " . TABLE_SUREPAY_TRANSACTIONS . " ( request_id int(12) unsigned NOT NULL auto_increment, auth_code varchar(60) default NULL, transaction_id varchar(60) default NULL, message varchar(255) default NULL, PRIMARY KEY ( request_id ) );" ); 
   }

   
   /*
       Installs this payment module into OS Commerce.
   */
   function remove()
   {
       tep_db_query( "delete from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_SUREPAY_STATUS'" );
       tep_db_query( "delete from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_SUREPAY_LOGIN'" );
       tep_db_query( "delete from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_SUREPAY_PASSWORD'" );
       tep_db_query( "delete from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_SUREPAY_TESTMODE'" );
       tep_db_query( "drop table " . TABLE_SUREPAY_TRANSACTIONS . ";" );
   }

   /*
       Returns configuration keys.  Used by OS Commerce to determine what global vars to make available. 
   */
   function keys()
   {
       $keys = array( 'MODULE_PAYMENT_SUREPAY_STATUS', 'MODULE_PAYMENT_SUREPAY_LOGIN', 'MODULE_PAYMENT_SUREPAY_PASSWORD', 'MODULE_PAYMENT_SUREPAY_TESTMODE' );
       return $keys;
   }
 }
?>

 

Lastly, my /includes/classes/sausurepay.php file:

 

<?php

// Sauen PHP Surepay lib - version 0.1.1 Beta - 2002 March 19

// sausurepay.php - The main classes and functions library file  

// ---------------------------------------------------------------------------

/* Licensed under GNU General Public License (GPL) v2.0

   Code collection providing functions and classes for the Surepay.Com gateway.

   Copyright (C) 2001-2002 J.T.Stokkeland and Sauen.Com.

 

   This code-collection is free software; you can redistribute it and/or modify

   it under the terms of the GNU General Public License as published by

   the Free Software Foundation; either version 2 of the License, or

   (at your option) any later version.

 

   This program is distributed in the hope that it will be useful,

   but WITHOUT ANY WARRANTY; without even the implied warranty of

   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

   GNU General Public License for more details.

 

   You should have received a copy of the GNU General Public License

   along with this program; if not, write to the Free Software

   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

// With this file you should have received the file license.txt which contains

// the full GNU GPL license details. Author contact information:

//   Jon T Stokkeland aka /Stoke/  [email protected]

//   302 E State St, Salamanca, NY, 14779, USA

// ---------------------------------------------------------------------------

// For more information about versions and other helpful info, see readme.*  

// Homepage of this PHP code collection lib: http://sausurepay.sourceforge.net

// PS! This version is NOT a complete library of all the Surepay functions!

// ---------------------------------------------------------------------------

 

 

 

### Main class - the only one users need to interreact with

class sausp {

 

  ###############################

  #

  #  Public Functions

  #

  #     Parameters listed as R is required, O is optional.

  #

  ###############################

 

 

  # add_auth : create an AUTH object

 

    function add_auth (

       $params = array(),       # R: Associative array. Must include surepay pp.auth params

       $ship_address = array(), # O: Associative array.

       $ordertext = array() )   # O: Associative array. (One element)

    {

       if (is_array($params) && $params) {

           $this->request['request'][$idx = ++$this->request['cnt']]['type'] = 'pp.auth';

           $this->request['request'][$idx]['params'] = $params;

           $this->request['request'][$idx]['cnt'] = 0;

           $pstr = '['.$idx.']';

           if ($ship_address) {

               if (is_array($ship_address)) {

                   $this->add_shipping_address($pstr,$ship_address);

               } else {

                   $this->err = 'Address supplied to add_auth was not an array';

               }

           }

           if (!$this->err && $ordertext) {

               if (is_array($ordertext)) {

                   reset($ordertext);

                   $this->add_ordertext($pstr,

                       key($ordertext),

                       $ordertext[key($ordertext)]

                    );

               } else {

                   $this->err = 'ordertext supplied to add_auth was not an array';

               }

           }

           if (!$this->err) return $pstr;

       } else {

           $this->err = 'pp.auth parameters error. Not given or none-array';

       }

    }

 

 

  # add_shipping_address : adds an adress of type shipping

 

    function add_shipping_address (

        $pstr,         # "Object" identifier

        $params )      # Array: address parameters excluding type

    {

        $params = array_merge(

            array( 'type' => 'shipping' ),

            $params);

        return $this->add_address($pstr,$params);

    }

 

 

  # add_billing_address : adds an adress of type billing

 

    function add_billing_address (

        $pstr,         # "Object" identifier

        $params )      # Array: address parameters excluding type

    {

        $params = array_merge(

            array( 'type' => 'billing' ),

            $params);

        return $this->add_address($pstr,$params);

    }

 

 

  # add_ordertext : adds an ordertext object

 

    function add_ordertext (

        $pstr,     # "Object" identifier

        $type,     # String

        $data )    # String  

    {

       if ( strlen($data) > 25 ) {

        $this->err = 'Order text length exceeded 25 characters';

       }

       elseif (

              ( strtolower($type) == 'description')

           || ( strtolower($type) == 'instructions')

           || ( strtolower($type) == 'classification')

          )

       {

            eval($this->peval($pstr));

            $idx = ++$ptr['cnt'];

            $ptr[$idx]['type'] = 'pp.ordertext';

            $ptr[$idx]['params'] = array('type'=> strtolower($type));

            $ptr[$idx]['data'] = trim($data);

            $ptr[$idx]['cnt'] = 0;

            return $pstr.'['.$idx.']';

       }

       else {

           $this->err = 'ordertext type was not (description|instructions|classification)';

       }

    }

 

 

  # add_creditcard : add a credit card object

  #     Planned for future versions: Validate even more parameters.

 

    function add_creditcard (

      $pstr,               # "Object" identifier

      $number,             # string cc number

      $expiration,         # string expiration format mm/yy

      $cvv2,               # string (must be 0 or '' if not used, then set stat to 0 or 9)

      $cvv2status = 1,     # int set(0,1,9)

      $baddress=array() )  # Array

    {

       if (!$number || !$expiration ) {

         $this->err = 'Number or Expiration not present in add_creditcard';

       }

       elseif (!preg_match('/^[0-9]{1,2}\/[0-9]{1,2}$/',$expiration)) {

         $this->err = 'Expiration is formatted wrong (mm/yy)';

       }

       elseif (!$cvv2 && $cvv2status == 1) {

         $this->err = 'cvv2 enabled but no cvv2 given';

       }

       elseif ($cvv2status == 1 && strlen($cvv2) > 4) {

         $this->err = 'cvv2 code to long (max 4)';

       }

       elseif ($cvv2status == 1 && strlen($cvv2) < 3) {

         $this->err = 'cvv2 code to short (min 3)';

       }

       else {

            if (!$cvv2) $cvv2 = '0';

            eval($this->peval($pstr));

            $idx = ++$ptr['cnt'];

            $ptr[$idx]['type'] = 'pp.creditcard';

            $ptr[$idx]['params'] = array(

                 'number'=> $number,

                 'expiration'=> $expiration,

                 'cvv2'=> $cvv2,

                 'cvv2status'=> $cvv2status

             );

            $ptr[$idx]['data'] = '';

            $ptr[$idx]['cnt'] = 0;

            $pstr = $pstr.'['.$idx.']';

            if ($baddress) {

                 if (is_array($baddress)) {

                     $this->add_billing_address($pstr,$baddress);

                 } else {

                     $this->err = 'Billing address supplied in add_cc but was not an array';

                 }

            }

            if (!$this->err) return $pstr;

       }

    }

 

 

 

  # add_lineitem : add an item object to an auth object

  #   Planned for future versions: Better validation of parameters.

 

    function add_lineitem (

            $pstr,           # Object identifier

            $quantity,       # int

            $sku,            # product sku

            $description,    # string (200)

            $unitprice,      # string (nnn.nnUSD)

            $taxrate='0',    # real (0.08 = 8%)

            $options=array() # Optional options array

      )

    {  

       if (!$quantity || !$sku || !$description || !$unitprice ) {

          $this->err = 'Missing required parameters for add_lineitem';

       }

       else {

            eval($this->peval($pstr));

            $idx = ++$ptr['cnt'];

            $ptr[$idx]['type'] = 'pp.lineitem';

            $ptr[$idx]['params'] = array(

                 'quantity'=> $quantity,

                 'sku'=> $sku,

                 'description'=>substr($description,0,200),

                 'unitprice'=> $unitprice,

                 'taxrate'=> $taxrate

             );

            $ptr[$idx]['data'] = '';

           

Link to comment
Share on other sites

Try replacing the following lines in /includes/modules/payment/surepay.php file:

 

function process_button()

  {

      global $HTTP_POST_VARS, $CardName, $CardNumber, $order;

     

      // TODO: enter real tax rate.

      $process_button_string = tep_draw_hidden_field( 'surepay_cc_number', $this->cc_number ) .

                                tep_draw_hidden_field( 'surepay_cc_cvv2', $this->cc_cvv2 ) .

                                tep_draw_hidden_field( 'surepay_cc_expires_month', $this->cc_expires_month ) .

                                tep_draw_hidden_field( 'surepay_cc_expires_year', $this->cc_expires_year ) .

                                tep_draw_hidden_field( 'surepay_fullname', $order->customer['firstname'] . ' ' . $order->customer['lastname'] ) .

                                tep_draw_hidden_field( 'surepay_address', $order->customer['street_address'] ) .

                                tep_draw_hidden_field( 'surepay_city', $order->customer['city'] ) .

                                tep_draw_hidden_field( 'surepay_state', $order->customer['state'] ) .

                                tep_draw_hidden_field( 'surepay_postcode', $order->customer['postcode'] ) .

                                tep_draw_hidden_field( 'surepay_country',$order->customer['country']['title'] ) .

                                tep_draw_hidden_field( 'surepay_phone', $order->customer['telephone'] ) .

                                tep_draw_hidden_field( 'surepay_email', $order->customer['email_address'] ) .

                                tep_draw_hidden_field( 'surepay_delivery_fullname', $order->delivery[ 'firstname' ] . ' ' . $order->delivery[ 'lastname' ] ) .

                                tep_draw_hidden_field( 'surepay_delivery_address', $order->delivery['street_address'] ) .

                                tep_draw_hidden_field( 'surepay_delivery_city', $order->delivery['city'] ) .

                                tep_draw_hidden_field( 'surepay_delivery_state', $order->delivery['state'] ) .

                                tep_draw_hidden_field( 'surepay_delivery_postcode', $order->delivery['postcode'] ) .

                                tep_draw_hidden_field( 'surepay_delivery_country',$order->delivery['country']['title'] ) .

                                tep_draw_hidden_field( 'surepay_tax_rate', '0.00' ) .

                                tep_draw_hidden_field( 'surepay_shipping_cost', number_format( $order->info['shipping_cost'], 2 ) . 'USD' ) .

                                tep_draw_hidden_field( 'surepay_tax', number_format( $order->info[ 'tax' ], 2 ) . 'USD' ) .

                                tep_draw_hidden_field( 'surepay_total', number_format( $order->info[ 'total' ], 2 ) . 'USD' )

                              ;

     

      return $process_button_string;

  }

 

 

With:

 

function process_button()

  {

      global $HTTP_POST_VARS, $CardName, $CardNumber, $order;

 

$total = $order->info[ 'total' ] - ($order->info['shipping_cost'] +  $order->info[ 'tax' ]);

     

      // TODO: enter real tax rate.

      $process_button_string = tep_draw_hidden_field( 'surepay_cc_number', $this->cc_number ) .

                                tep_draw_hidden_field( 'surepay_cc_cvv2', $this->cc_cvv2 ) .

                                tep_draw_hidden_field( 'surepay_cc_expires_month', $this->cc_expires_month ) .

                                tep_draw_hidden_field( 'surepay_cc_expires_year', $this->cc_expires_year ) .

                                tep_draw_hidden_field( 'surepay_fullname', $order->customer['firstname'] . ' ' . $order->customer['lastname'] ) .

                                tep_draw_hidden_field( 'surepay_address', $order->customer['street_address'] ) .

                                tep_draw_hidden_field( 'surepay_city', $order->customer['city'] ) .

                                tep_draw_hidden_field( 'surepay_state', $order->customer['state'] ) .

                                tep_draw_hidden_field( 'surepay_postcode', $order->customer['postcode'] ) .

                                tep_draw_hidden_field( 'surepay_country',$order->customer['country']['title'] ) .

                                tep_draw_hidden_field( 'surepay_phone', $order->customer['telephone'] ) .

                                tep_draw_hidden_field( 'surepay_email', $order->customer['email_address'] ) .

                                tep_draw_hidden_field( 'surepay_delivery_fullname', $order->delivery[ 'firstname' ] . ' ' . $order->delivery[ 'lastname' ] ) .

                                tep_draw_hidden_field( 'surepay_delivery_address', $order->delivery['street_address'] ) .

                                tep_draw_hidden_field( 'surepay_delivery_city', $order->delivery['city'] ) .

                                tep_draw_hidden_field( 'surepay_delivery_state', $order->delivery['state'] ) .

                                tep_draw_hidden_field( 'surepay_delivery_postcode', $order->delivery['postcode'] ) .

                                tep_draw_hidden_field( 'surepay_delivery_country',$order->delivery['country']['title'] ) .

                                tep_draw_hidden_field( 'surepay_tax_rate', '0.00' ) .

                                tep_draw_hidden_field( 'surepay_shipping_cost', number_format( $order->info['shipping_cost'], 2 ) . 'USD' ) .

                                tep_draw_hidden_field( 'surepay_tax', number_format( $order->info[ 'tax' ], 2 ) . 'USD' ) .

                                tep_draw_hidden_field( 'surepay_total', number_format( $total, 2 ) . 'USD' )

                              ;

     

      return $process_button_string;

  }

 

 

Make a backup of your file before modifications.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...