Tag Archives: payment module

set default payment method in checkout

Sometimes its helpful to have a payment method ‘preselected’ for customers in the checkout area, so they avoid getting an error message if they miss that option. Or maybe you want to select a method for them as an example of what it looks like … plenty of reasons. This short article explains how to set a default payment method in oscommerce 2.2 and cre loaded 6.4.1a carts (which is slightly harder as cre is using runoverride files now to ‘steer things in a paypal direction.’)

Oscommerce 2.2 version
Backup the file: /catalog/checkout_payment.php and edit as follows:
Find:

<?php
        if (sizeof($selection) > 1) {
          echo tep_draw_radio_field('payment', $selection[$i]['id']);
        } else {
          echo tep_draw_hidden_field('payment', $selection[$i]['id']);
        }
?>

Replace with:

<?php
          if (sizeof($selection) > 1) {
          if ($i == 0) { 
                $checked = true;          
                } else {  
           $checked = false;      
           }     
                echo tep_draw_radio_field('payment', $selection[$i]['id'], $checked);
           } else { 
                echo tep_draw_hidden_field('payment', $selection[$i]['id']);
           }
?>

Cre Loaded 6.4.1a
Backup the file: /catalog/includes/runoverride/ordercheckout/paypalxc_ordercheckout_paymentmodule.php

To get the selector bar highlighting the payment method row, modify as follows, replacing the payment method name in the ‘name of payment method’ bit:

<?php
 $radio_buttons = 0;
        $payment = (!$payment) ? 'name of the payment method' : $payment;
 for ($i=0, $n=sizeof($selection); $i<$n; $i++) {

If you’re not sure of the payment module names, go to Admin >> Modules >> Payment area, click on a module and read it’s name from the url in the address bar. Or just check in the /includes/modules/payment folder and drop the .php extension.

To get the radio button to default to the selected payment module, modify the following:

<?php
  if (sizeof($selection) > 1 || $ec_enabled ) {
   if ($i == 0) {  // defaults to payment method with id=0 NOT related to sort order in admin
      $checked = true;
   } else {
      $checked = false;
   }
  echo tep_draw_radio_field('payment', $selection[$i]['id'], $checked);
  } else {  ...

The key part in the code is the $i==0 which refers to the payment method id. This ISN’T related to the sort order of the payment modules in the Admin >> Modules >> Payment area, or some ‘name sort’ principle. Instead it just reflects the order of the modules in the database constant MODULE_PAYMENT_INSTALLED.

So if you take a look at the configuration table in your database and search for MODULE_PAYMENT_INSTALLED, your payment modules will be in a row there –
eg moneyorder.php,transfer.php,paypal.php
Here, moneyorder will have the id = 0 (so $i == 0 to be selected by default), transfer’s id = 1, paypal’s id = 2 … etc.

So by changing the $i == 0 in the code examples above to match your payment method id, you can easily set the default payment method at checkout.

how to setup the paypal website payments standard module

The Paypal Website Payments Standard module is a basic ‘button’ type payment facility that allows websites to collect payment from Paypal and non-Paypal customers alike, via hosted pages on the Paypal server.

This post is an outline of settings that work for me using a cre loaded 6.4.1a CE version cart and the default payment module that is supplied with it. No modifications have been made to the original Cre Loaded Paypal files, which are largely based on an old oscommerce version and incorporate the Paypal IPN (Instant Payment Notification) function as well.

There are two parts to setting up the Paypal Website Payments Standard module – firstly the module itself through the admin, and secondly your Paypal account settings. It’s reasonably easy to end up with failed transactions or inventory not being adjusted for sales correctly or Paypal payments but no order in the admin etc, with different settings.

1. Check the Paypal Website Payments Standard module

screenshot of paypal website payments standard bottom half of module settingspaypal module top half of column settings

 

 

  • Check the settings in the cart’s Paypal Website Payments Standard module and note the text in the images (see right) in red – I’ve found that if the settings for these particular entries aren’t as shown, the module may not work as expected.
  • Also, it is a good idea to uninstall and reinstall the module if you are experiencing problems.

2. Check your Paypal Account settings

  • Login to your Paypal account – which should be either a Business or Premier account, as this module will not work with a personal account. As mentioned above, make sure the email addresses in Paypal Website Standard module match exactly the email address used in your PP account. This is often the reason for module problems.
  • Next, go to Profile -> My Selling Tools:

Sales Tax -> Update:
None set.

Website Preferences -> Update:
Auto Return = On
Return Url = https://www.yourstore.com/checkout_process.php
Payment Data Transfer = Off
Encrypted Website Payments = Off
Paypal Account Optional = On (if you want to prevent Paypal from hassling customers into setting up a Paypal account)
Contact Telephone = Off
Express Checkout = No

Instant Payment Notifications -> Update:
Switch on IPN
Notification URL = https://www.yourstore.com/checkout_process.php

Shipping Calculations -> Update:
None set.
Tick “Click here to allow transaction-based shipping values to override the profile shipping settings listed above”

Please note the Auto Return and IPN Notification urls ARE THE SAME: both are checkout_process.php … not checkout_success.php or ipn.php etc.

If you have a Personal Paypal account you can test your settings now with a transaction. Alternatively use the Paypal Developer area and sandbox test accounts. The order should go through smoothly using either the 3-page or 1-page checkout and an IPN result should go through to your store’s email address.

For zen-cart setup try the zen-cart wiki page about setting up the Paypal Website Payments Standard module here
For oscommerce support try this forum how to setup the Paypal Website Payments Standards module here

(If you’ve tried all of the recommendations in this post and it still isn’t working, please use the contact me above for a quote.)

cre loaded – enctype=”multipart/form-data” and payment modules, sagepay form

Cre Loaded version 6.4.1 still widley uses enctype=”multipart/form-data” for form submission. This would be ok if the forms being submitted involved file uploads or large files, but when payment module forms get zapped with this ‘decoding’ routine, they tend to break. A case in point – the Sagepay Form module.

The code responsible is in templates/content (or /templates/your template/content) and the file is checkout_confirmation.tpl.php (around line 277 in the CE version) :

if (ACCOUNT_CONDITIONS_REQUIRED == 'false' ) {
echo tep_draw_form('checkout_confirmation', $form_action_url, 'post','enctype="multipart/form-data"');
} else {
echo tep_draw_form('checkout_confirmation', $form_action_url, 'post','onsubmit="return checkCheckBox(this)" enctype="multipart/form-data"');
}

and replace with this :

if ((ACCOUNT_CONDITIONS_REQUIRED == 'false' ) && ($_SESSION['payment'] == 'sage_pay_form')) {
            echo tep_draw_form('checkout_confirmation', $form_action_url, 'post');
          } elseif ((ACCOUNT_CONDITIONS_REQUIRED == 'true' ) && ($_SESSION['payment'] == 'sage_pay_form')) {
            echo tep_draw_form('checkout_confirmation', $form_action_url, 'post','onsubmit="return checkCheckBox(this)"');
          } elseif (ACCOUNT_CONDITIONS_REQUIRED == 'false') {
            echo tep_draw_form('checkout_confirmation', $form_action_url, 'post','enctype="multipart/form-data"');
          } else {
            echo tep_draw_form('checkout_confirmation', $form_action_url, 'post','onsubmit="return checkCheckBox(this)" enctype="multipart/form-data"');
          }