Posted by: Maxxxie Aug 24 2007, 11:47 PM
Hi everyone,
I'd like to have a payment module that works along the lines of a lay-by system. The customer is presented with a total, then presented with a value of 10% which is the deposit they must pay for the order to be acted upon. It is a requirement that the customer receive a receipt stating the terms and conditions of the layby arrangement. My intention is to use email to do this.
To this end, I've butchered the http://www.oscommerce.com/community/contributions,1777 and combined it with another payment module (Australian bank deposits) to suit my needs. At checkout, the customer is presented with the terms and conditions and the 10% deposit value they must put down. No worries. But I can't seem to get the deposit value to go into the order confirmation email. The best I can seem to do is to derive 10% of the cart total excluding shipping. But I want to show 10% of the total, not the subtotal.
Here's the code I've played with so far (complete with inept failed attempts at fixing the email problem):
CODE
<?php
/*
$Id: LAYBY.php,v 1.10 2003/01/29 19:57:14 hpdl Exp $
amended by Edwin Martinez
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2003 osCommerce
Released under the GNU General Public License
*/
class layby {
var $code, $title, $description, $enabled;
// class constructor
function layby() {
global $HTTP_POST_VARS, $order, $currencies, $cart;
$this->code = 'layby';
$this->title = MODULE_PAYMENT_LAYBY_TEXT_TITLE;
$this->description = MODULE_PAYMENT_LAYBY_TEXT_DESCRIPTION;
$this->sort_order = MODULE_PAYMENT_LAYBY_SORT_ORDER;
// $this->enabled = ((MODULE_PAYMENT_LAYBY_STATUS == 'True') ? true : false);
if(MODULE_PAYMENT_LAYBY_STATUS == 'True'){
if($_SESSION['cart']->total>=100){
$this->enabled = true;
} else {
$this->enabled = false;
}
} else {
$this->enabled = false;
}
if ((int)MODULE_PAYMENT_LAYBY_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_LAYBY_ORDER_STATUS_ID;
}
// $this->email_footer = MODULE_PAYMENT_LAYBY_TEXT_EMAIL_FOOTER;
//echo ($_SESSION['order']->total);
//$down_payment = ($_SESSION['order']->total) * 0.10;
// $orderinfototal = $order->info['total'];
// $orderinfototal = $_SESSION['order']->total;
// $orderfinalprice = $order->products['final_price'];
//$orderinfoshipping = $_SESSION['order']->info['shipping_cost'];
//$ordertotal = $orderinfototal + $orderinfoshipping;
$down_payment = $_SESSION['cart']->total / 10;
// $down_payment2 = $currencies->price() * 0.10;
$EMAIL_LAYBY12 = "Please note: \nYour initial payment (deposit) is: " . number_format($down_payment, 2) . "\n";
$this->email_footer = MODULE_PAYMENT_LAYBY_TEXT_EMAIL_T_AND_C . $EMAIL_LAYBY12 . MODULE_PAYMENT_LAYBY_TEXT_EMAIL_FOOTER;
// $this->email_footer = "orderinfototal: " . $orderinfototal . ", orderfinalprice: " . $orderfinalprice;
//. " , orderinfoshipping" . $orderinfoshipping . ", ordertotal" . $ordertotal;
if (is_object($order)) $this->update_status();
}
// class methods
function update_status() {
global $order;
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_LAYBY_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_LAYBY_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() {
global $HTTP_POST_VARS, $order, $currencies;
define('TOTAL_PAYMENT_INT12', microtime());
$down_payment= $currencies->price() * 0.10;
//$monthly_payment= ($currencies->price() - $down_payment) * 0.10573;
//$salary = ($monthly_payment / 0.2);
// $LAYBY12= 'Please note: <br><b> Down Payment: <font color="red"> ' . number_format($down_payment, 2). '</font color><br> 12 Payments of: <font color="red">' . number_format($monthly_payment, 2). ' </b></font color>'. '<br> To apply for this credit line you must have minimum monthly earnings of: <b>' . number_format($salary, 2) . '</b> <br>';
$LAYBY12= 'Please note: <br><b>Your initial payment (deposit) is: <font color="red"> ' . number_format($down_payment, 2) . '</b></font color> <br>';
return array('title' => MODULE_PAYMENT_LAYBY_TEXT_T_AND_C . $LAYBY12 . MODULE_PAYMENT_LAYBY_TEXT_DESCRIPTION);
}
function process_button() {
global $HTTP_POST_VARS, $order, $currencies;
$process_button_string = tep_draw_hidden_field('payment', $currencies->price());
return $process_button_string;
}
function before_process() {
return false;
}
function after_process() {
return false;
}
function get_error() {
return false;
}
function check() {
if (!isset($this->_check)) {
$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_LAYBY_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 Lay-by Module', 'MODULE_PAYMENT_LAYBY_STATUS', 'True', 'Do you want to accept Lay-by 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 ('Make Payable to:', 'MODULE_PAYMENT_LAYBY_PAYTO', '', 'Who should payments be made payable to?', '6', '1', 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_LAYBY_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_LAYBY_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_LAYBY_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())");
}
function remove() {
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array('MODULE_PAYMENT_LAYBY_STATUS', 'MODULE_PAYMENT_LAYBY_ZONE', 'MODULE_PAYMENT_LAYBY_ORDER_STATUS_ID', 'MODULE_PAYMENT_LAYBY_SORT_ORDER', 'MODULE_PAYMENT_LAYBY_PAYTO');
}
}
?>
I'm struggling with the code at around line 59 (trying to define $EMAIL_LAYBY12). My guess is that I'm just interrogating the wrong variable, but I've no idea which one I should touch. I'm pretty sure I'm grasping at straws with the $_SESSION variable.
I'd appreciate any help!
Cheers,
Max
Posted by: Vger Aug 25 2007, 12:06 AM
This is the first time I've looked at this, but if you want the 10% deposit amount to show in the email then you need to use an echo command.
Vger
Posted by: Maxxxie Aug 25 2007, 12:09 PM
QUOTE(Vger @ Aug 25 2007, 10:06 AM)

This is the first time I've looked at this, but if you want the 10% deposit amount to show in the email then you need to use an echo command.
Vger
Thanks for getting back to me, Vger. Which variable would I interrogate to get the 10% value though?
Cheers,
Max