THANKS FOR THE HELP FROM THE ONLINE GUYS AT #zencart at freenode.net
This mod will allow you to show credit card payment method depending on the shopping cart total. For this example, the following settings are used:
- Online CC gateway has $2500 limit
- Authroize.net-AIM module installed, configured, and enabled (with mods)
- Manual CC processing module installed, configured, and enabled (with mods)
- Check/COD module installed, configured, and enabled
- Some of your single-item products+shipping+tax/vat may exceed $2500 limit
At checkout time cart total $2350.75. Following options will be presented:
At checkout time cart total $3505.60. Following options will be presented:
In scenario 1 where cart is under limit, the CC payment will be processed online by Authorize.net gateway and an email from Authorize.net will be sent to the admin email.
In scenario 2 where cart is over the limit, the CC payment will be forwarded to the admin email for manual processing the credit card.
In both cases, only 1 credit card payment method is presented to the customer.
===== [ZENCART_BASE]/includes/modules/payment/cc.php
This part retrieves the limits from the configuration options
PHP Code:
function cc() {
// first part skipped - add the next 2 lines towards the end
$this->cc_min = MODULE_PAYMENT_CC_MIN; // ** Add this
$this->cc_max = MODULE_PAYMENT_CC_MAX; // ** Add this
if (is_object($order)) $this->update_status(); // ** Leave this alone
}
This part checks if we want to show this CC payment option
PHP Code:
function selection() {
global $order;
/**
* The following 2 lines check if cart total is within the limits
* If outside of limits, then disable module for processing for this transaction only
*/
$this->enabled = (($this->enabled && $this->cc_min > 0 && $order->info["total"] < $this->cc_min) ? false : $this->enabled );
$this->enabled = (($this->enabled && $this->cc_max > 0 && $order->info["total"] >= $this->cc_max) ? false : $this->enabled );
// Wrap the rest of the function in an enabled check
if ( $this->enabled) {
for ($i=1; $i<13; $i++) {
// rest of function stays the same
}
} // ** Add closing bracket here for if .... statement
}
This part adds limit options in admin->modules->payment->manual cc module configuration
PHP Code:
function install() {
// add at the end of the function
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Minimum Charge Amount', 'MODULE_PAYMENT_CC_MIN', '0', 'Would you like to set a MINIMUM charge amount for this payment option? Leave at 0 for no mimimum. Whole dollar amounts only.', '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 ('Maximum Charge Amount', 'MODULE_PAYMENT_CC_MAX', '0', 'Would you like to set a MAXIMUM charge amount for this payment option? Leave at 0 for no maximum. Whole dollar amounts only.', '6', '0', now())");
}
The following adds the MIN/MAX keys to they will be enabled
PHP Code:
function keys() {
// ** Add MODULE_PAYMENT_CC_MIN
// ** Add MODULE_PAYMENT_CC_MAX
return array('MODULE_PAYMENT_CC_STATUS', 'MODULE_PAYMENT_CC_EMAIL', 'MODULE_PAYMENT_CC_ZONE', 'MODULE_PAYMENT_CC_ORDER_STATUS_ID', 'MODULE_PAYMENT_CC_SORT_ORDER', 'MODULE_PAYMENT_CC_COLLECT_CVV', 'MODULE_PAYMENT_CC_MIN', 'MODULE_PAYMENT_CC_MAX' );
}
===== [ZENCART_BASE]/includes/modules/payment/authorizenet_aim.php
Do the same changes to authorizenet_aim.php except:
instead of changing function cc(), make changes to function authorizenet_aim()
Other function changes are the same.
With possible minor alterations, the same code could be used for other CC processing modules.