Jump to content
Sign in to follow this  
scotch33

Secpay and Templates

Recommended Posts

does anyone know how to get the secpay module working with a template? at the moment it is going to a grim looking green screen to take the credit card details.

Share this post


Link to post
Share on other sites

Ok - think I've solved it - heres the method for anyone that wants it.

 

1. copy the below code which is an amalgamation of a successful secpay module, and save it as secpay.php.

 

2. in the code (look for the comments) you will see that a template variable has been added that points the module to a template, and a new hidden field that tells the module to use it.

you need to change the template variable - replacing 'merchant_id' with the merchant ID assigned to you when you joined secpay, you can also change the template name which is currently set as 'secpay_template.htm'. Giving it your own name may be a good idea, for ease of identification at the secpay end.

 

3. back-up your original secpay module. then replace it with the your version of secpay.php

 

4. right - quick check - look at your store name in configuration settings. Any spaces? If so remove them and replace with underscores (_). Don't ask me why, but the secpay module doesn't like spaces in the shop title - it may not work on you until you have done this.

 

5. uninstall secpay in the admin panel, and re-install (don't forget to do this - otherwise you will be using the code in the module you have replaced). change the settings to your merchant ID and digest code.

 

6. upload a template to your secpay user area that includes the original secpay template code (found on the secpay site) and test it (for a quicktest just add a line at the beginning of the body of the html such as 'test template')

 

Hope someone finds this useful! here's the code.

 

<?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
 
 Notes:-
 Module uses 'secpay' as the default Digest Key.  This must be changed to a
 valid digest key before going live.
 
 The Digest key is implemented as database resident (Configuration table) but may be
 hard coded if required.  See notes in the before_process function.
 
 cb_flds in the hidden 'Options' form field uses the Session Id as default but any other 
 field or combination of fields may be used.
 
 For details of the digest key and md_flds refer to the SECpay implementation manual 
 at http://www.secpay.com/tech.html or their User Manual at http://www.secpay.com/sc_api.html
 
 this version updated to include simple template code by Scotch33 - www.pearsontreehouse.co.uk 

*/

 class secpay {
   var $code, $title, $description, $enabled;

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

     $this->code = 'secpay';
     $this->title = MODULE_PAYMENT_SECPAY_TEXT_TITLE;
     $this->description = MODULE_PAYMENT_SECPAY_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_PAYMENT_SECPAY_SORT_ORDER;
     $this->enabled = ((MODULE_PAYMENT_SECPAY_STATUS == 'True') ? true : false);

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

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

     $this->form_action_url = 'https://www.secpay.com/java-bin/ValCard';
   }

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

     if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_SECPAY_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_SECPAY_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_SECPAY_CURRENCY) {
       case 'Default Currency':
         $sec_currency = DEFAULT_CURRENCY;
         break;
       case 'Any Currency':
       default:
         $sec_currency = $currency;
         break;
     }

     switch (MODULE_PAYMENT_SECPAY_TEST_STATUS) {
       case 'Always Fail':
         $test_status = 'false';
         break;
       case 'Production':
         $test_status = 'live';
         break;
       case 'Always Successful':
       default:
         $test_status = 'true';
         break;
     }

//next line is the template line - change merchant id to your id (without the speechmarks), and change the template name to your own.
     $sec_template = 'http://www.secpay.com/users/'MERCHANT_ID'/secpay_template_1.htm';
     $process_button_string = tep_draw_hidden_field('merchant', MODULE_PAYMENT_SECPAY_MERCHANT_ID) .
                              tep_draw_hidden_field('trans_id', STORE_NAME . date('Ymdhis')) .
                              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('bill_name', $order->billing['firstname'] . ' ' . $order->billing['lastname']) .
                              tep_draw_hidden_field('bill_addr_1', $order->billing['street_address']) .
                              tep_draw_hidden_field('bill_addr_2', $order->billing['suburb']) .
                              tep_draw_hidden_field('bill_city', $order->billing['city']) .
                              tep_draw_hidden_field('bill_state', $order->billing['state']) .
                              tep_draw_hidden_field('bill_post_code', $order->billing['postcode']) .
                              tep_draw_hidden_field('bill_country', $order->billing['country']['title']) .
                              tep_draw_hidden_field('bill_tel', $order->customer['telephone']) .
                              tep_draw_hidden_field('bill_email', $order->customer['email_address']) .
                              tep_draw_hidden_field('ship_name', $order->delivery['firstname'] . ' ' . $order->delivery['lastname']) .
                              tep_draw_hidden_field('ship_addr_1', $order->delivery['street_address']) .
                              tep_draw_hidden_field('ship_addr_2', $order->delivery['suburb']) .
                              tep_draw_hidden_field('ship_city', $order->delivery['city']) .
                              tep_draw_hidden_field('ship_state', $order->delivery['state']) .
                              tep_draw_hidden_field('ship_post_code', $order->delivery['postcode']) .
                              tep_draw_hidden_field('ship_country', $order->delivery['country']['title']) .
                              tep_draw_hidden_field('currency', $sec_currency) .
                              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()) .
         // cb_flds uses the Session Id as default but any other field or combination of fields may be used
         tep_draw_hidden_field('template', $sec_template) .
                              tep_draw_hidden_field('options', 'test_status=' . $test_status . ',dups=false,cb_flds=' . tep_session_name());

     return $process_button_string;
   }

   function before_process() {
     global $HTTP_GET_VARS;

     if ($HTTP_GET_VARS['code'] == 'A' && !empty($HTTP_GET_VARS['auth_code']) && empty($HTTP_GET_VARS['resp_code']) && !empty($HTTP_GET_VARS['osCsid'])) {
//      Hard code Digest Key here if required.  
//      $DIGEST_PASSWORD = "secpay";        
       list($REQUEST_URI, $CHECK_SUM) = split("hash=", $_SERVER['REQUEST_URI']); 
       if ($HTTP_GET_VARS['hash'] != MD5($REQUEST_URI.MODULE_PAYMENT_SECPAY_READERS_DIGEST)) {
          tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, tep_session_name() . '=' . $HTTP_GET_VARS[tep_session_name()] . '&payment_error=' . $this->code, 'SSL', false, false));
       }


     }
   }

   function after_process() {
     return false;
   }

function get_error() {
global $HTTP_GET_VARS;

if ($HTTP_GET_VARS['code'] == "N") {
$error = "TRANSACTION WAS NOT AUTHORISED. PLEASE TRY ANOTHER CARD.";
} 
elseif ($HTTP_GET_VARS['code'] == "C") {
$error = "There was a communications problem in contacing the bank, please try again.";
}
else {
$error = MODULE_PAYMENT_SECPAY_TEXT_ERROR_MESSAGE;
}

return array('title' => MODULE_PAYMENT_SECPAY_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_SECPAY_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 SECpay Module', 'MODULE_PAYMENT_SECPAY_STATUS', 'True', 'Do you want to accept SECPay 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_SECPAY_MERCHANT_ID', 'secpay', 'Merchant ID to use for the SECPay 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_SECPAY_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_SECPAY_TEST_STATUS', 'Always Successful', 'Transaction mode to use for the SECPay 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 ('Sort order of display.', 'MODULE_PAYMENT_SECPAY_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_SECPAY_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_SECPAY_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())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Readers Digest', 'MODULE_PAYMENT_SECPAY_READERS_DIGEST', 'secpay', 'Digest Key', '6', '0', now())");
   }

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

   function keys() {
     return array('MODULE_PAYMENT_SECPAY_STATUS', 'MODULE_PAYMENT_SECPAY_MERCHANT_ID', 'MODULE_PAYMENT_SECPAY_CURRENCY', 'MODULE_PAYMENT_SECPAY_TEST_STATUS', 'MODULE_PAYMENT_SECPAY_ZONE', 'MODULE_PAYMENT_SECPAY_ORDER_STATUS_ID', 'MODULE_PAYMENT_SECPAY_SORT_ORDER', 'MODULE_PAYMENT_SECPAY_READERS_DIGEST');
   }
 }
?>

Share this post


Link to post
Share on other sites

Hi

 

I am having problems with the SECPAY module

 

I have followed the steps above - but am unsure about step 6

 

I have downloaded a template from secpay but don't know what changes to make

 

When I process an order on my site, it appears to go to secpay (and has captured the amount to pay) but there is no template/functionality

 

All I get is a stream of text, as follows:

 

"Fields marked * are mandatory for all card types Click here for help text Name of Cardholder* Card Type* Master Card Visa Debit, Delta or Connect Visa Switch/UK Maestro Solo JCB Card Number* Expiry Date (MM/YY)* Issue No. (Switch use 0 if not known) Last 3 digits on signature strip (security code) Start Date (MM/YY) Amount 29.45 GBP Please do not press Authorise more than once. Please wait while your card details are authorised. This transaction is encrypted for your privacy. Do not exit or press back until confirmation received"

 

 

ANY IDEAS?

Share this post


Link to post
Share on other sites

I did a bit more searching on oscommerce - and found some code that brought up the secpay standard template. I have included the new code which I have inserted to the above code.

 

I placed it just above the line where it says $process_button_string =

 

//*********Correct variable setup *********

$sec_template = $HTTP_GET_VARS['sec_template']; //couldn't get this to work with $HTTP_POST_VARS

 

$sec_template = 'http://www.secpay.com/users/*******/name_of_your_template.html';

 

I can now access the secpay standard template.

 

Thanks

Share this post


Link to post
Share on other sites

I need to use secpay and have installed it however i need help with.....

 

1) when you go to the pay using secpay it only has the default secpay form - how do i change this??

2) cant go back to the shop from the secpay form (if someone changes their mind)

3) after the card input it just goes back to the main page of the shop

4) the customer email just has "NEW ORDER (Details attached)" and a file that doesnt open when you click on it - as it has no extension can this be put direct into the body of the email?

 

if anyone can help please

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×