News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Credit card surcharging

Started by duk, October 09, 2007, 09:15:47 AM

Previous topic - Next topic

duk

Hi Guys and Gals,

I am in the process of developing a Payment Module using the Payment Processor method (similar to authorize.net).

One of the requirement for this module is, if the customer decides to pay using the credit card the shop owner should be able to add a surcharge to the total amount (surcharging is legal in Australia). The surcharge will be a % of the order total (not a fixed amount). Depending on the card type used a different % will be applied (higher % for Amex and Diners).

I have managed to customise the Admin interface to allow the shop owner to set the surcharge % for different card types. This information will be stored in the cfg.php file for the payment module.

What I am having trouble with is, calculating the surcharge and adding it to the order total.

All the required information (such as order_subtotal_withtax, shipping_total) to calculate the surcharge is only available in the function process_payment() via the parameter $d. If I calculate the surcharge in this method and add it to the order total, technically it will work, but the customer won't be aware of the surcharge amount being added, which is not a good thing as it will lead to confusion and disputes.

IMO, the best place to calculate the surcharge is function get_payment_rate(). The surcharge can be calculated and returned as a -ve value so the Order Confirmation page in the checkout process will display this value as a Fee. The catch is, this function only has access to $subtotal. This means the shipping fee and taxes are not included when the surcharge is calculated.

I am stumped here. Any suggestion?

duk

duk

I have found a long winded work around for adding surcharge.Not sure if this is the most elegant or effective way of doing this. Feedback is most welcome.

   function get_payment_rate($subtotal) {
      global $VM_LANG;

      // Get the card type being used
      $card_id = $_SESSION['ccdata']['creditcard_code'];

      // Read current Configuration
      require_once(CLASSPATH ."payment/".$this->classname.".cfg.php");

      // Identify the surcharge rate (surcharge rate for different CC types will be set in cfg file via Admin)
      $surcharge_rate = (is_numeric(${SURCHARGE_FIELD_PREFIX.$card_id})? ${SURCHARGE_FIELD_PREFIX.$card_id} : 0);

      // Get the discount spcific to this payment method
      // A discount specific to the selected payment method can be set via the admin section
      // get this value
      $payment_method_id = mosGetParam( $_REQUEST, 'payment_method_id', null );
      require_once(CLASSPATH.'ps_payment_method.php');
      $ps_payment_method = new ps_payment_method;
      $discount = $ps_payment_method->get_field($payment_method_id, "payment_method_discount");

      // Check if the Merchant wants to Surcharge or if the surcharge rate is 0
      if ($VM_LANG->_PHPSHOP_ADMIN_CFG_NO == SP_SURCHARGE || 0 == $surcharge_rate) {
         //If the merchant is not surcharging return the discount
         return $discount;
      }
      else {
         //Calculate the surcharge

         // Calculate the total discount
         // Total Discount =  discount specific to the payment option + discount based on coupon
         $discount += $_SESSION['coupon_discount'];
         
         // Get the shipping charges
         $rate_array = explode( "|", urldecode(mosGetParam($_REQUEST,'shipping_rate_id')) );
         $shipping = $rate_array[3];
   //      $filename = basename( $rate_array[0] );
   //      include_once( CLASSPATH. "shipping/".$filename.".php" );
   //      eval( "\$ps_shipping_method = new ".$filename."();");
   //      echo("Shipping Rate: ".$ps_shipping_method->get_rate(&array("shipping_rate_id"=>mosGetParam($_REQUEST,'shipping_rate_id'))));

         //Display a msg so that customer knows a surcharge has been added
         echo "<p><b>A $surcharge_rate% credit card charge for $card_id payment has been added to the total.</b></p>";
         //Calculate the surcharge
         //Surcharge = (sub total + shipping - discount) % surcharge rate
         //get_payment_rate() is used by the cart to calculate the discount value
         //Any value returned will be applied as a -ve value to the order total
         //So, the return value must be -ve so the fee will be added (double -ve = +ve)
         return -(($subtotal + $shipping - $discount)/100)*$surcharge_rate;
      }
   }

Mark Wass

This is great thanks for all your effort, but where does this get applied? There was no mention of what file/s to ammend.

Thanks

duk

In the payment module you are using. For example, if you are using authorize.net as your payment processor this change should go in to your <www root>/administrator/components/com_virtuemart/classes/payment/ps_authorize.php

PLEASE NOTE:
Before making any changes
-Read about how the payment modules are designed at
http://virtuemart.net/index.php?option=com_openwiki&Itemid=109&id=tutorials:paymentmodules
and
http://virtuemart.net/index.php?option=com_openwiki&Itemid=109&id=references:payment

-Backup the file you are about to change
-Test things thoroughly before making it live to your customers