[add-on] Discount Code (support)
#41
Posted 05 February 2011 - 02:46 PM
Customer gets a discount by clicking a link or inserting the discount code while checkout. The link containing the discount code (http://www.yourshop.com/?discount_code=12345678) is especially convenient for newsletters sending out and promo campaigns conducting.
Does this mean that you can include this link into your newsletter substituting your shop and discount_code=12345678 with your discount code number as i have tried this link but just get the normal shop page. How does it work ?
#42
Posted 15 February 2011 - 12:52 AM
I too found this mod to be of great help as I have the ability to give a dealer price so they can purchase off my site instead of directly as they wanted shipping costs immediately.
However I had a hard time getting the checkout_confirmation page to show the discount. I install 2.8 and had to go back and add all the mods up to that point.
What I eventually found was that in the configuration file the file name ot_discount.php was missing from the MODULE_ORDER_TOTAL_INSTALLED configuration key.
Thanks
David
#43
Posted 27 February 2011 - 10:12 PM
anyone have an idea, how to make this module show the discount with a "-" (minus) sign in the checkout / order confirmation, instead of the standard red font type?
#44
Posted 28 February 2011 - 11:25 PM
scandic_outlet, on 27 February 2011 - 10:12 PM, said:
anyone have an idea, how to make this module show the discount with a "-" (minus) sign in the checkout / order confirmation, instead of the standard red font type?
$this->output[] = array('title' => TEXT_DISCOUNT . (!empty($order_info) ? ' (' . $sess_discount_code . ')' : '') . ':',
'text' => '<span class="productSpecialPrice">' . $currencies->format($discount, true, $order->info['currency'], $order->info['currency_value']) . '</span>',
'value' => $discount);
Replace:
'<span class="productSpecialPrice">'With:
'-'And delete:
. '</span>'
----------------------
I find a bug with tax calculation when you select a product discount, the discount is incorrect.
If tax is 7%, on discount are missing per product 0.07 €
If tax is 16%, on discount are missing per product 0.16 €
Sorry for my poor english
Bye!
#45
Posted 01 March 2011 - 10:19 PM
catalog/includes/modules/order_total/ot_discount.php
Find:
if (!empty($order->products[$i]['tax'])){
And replace with:if ((!empty($order->products[$i]['tax'])) && (strpos($check['discount_values'], '%') == true)){
Find:
if (!empty($discount)) {
$order->info['total'] -= array_sum($tax_discount);
$order->info['total'] -= $discount;
Add after: if (strpos($check['discount_values'], '%') == true) {
$discount = $discount + array_sum($tax_discount);
}
Save the file and upload
Regards!!
#46
Posted 01 March 2011 - 10:21 PM
Thanks for the help.
Also - author just released a new version of the module TODAY.
Should try to have him implement this fix you found..
#47
Posted 02 March 2011 - 04:41 AM
When I go to the admin section I get this error, and my knowledge in SQL is not good enough to solve it:
1054 - Unknown column 'dc.customers_id' in 'field list' select dc.discount_codes_id, dc.products_id, dc.categories_id, dc.manufacturers_id, dc.excluded_products_id, dc.customers_id, dc.orders_total, dc.order_info, dc.discount_codes, dc.discount_values, dc.minimum_order_amount, dc.expires_date, dc.number_of_orders, dc.number_of_use, dc.number_of_products, dc.status from discount_codes dc order by dc.discount_codes_id desc limit 0, 20 [TEP STOP]Could anyone give me a hand?
Alright, I looked a little at the installed SQL, and it appears that the customers_id field is in the other database "customers_to_discount_codes", not "discount_codes"
CREATE TABLE `customers_to_discount_codes` (
`customers_id` int(11) NOT NULL default '0',
`discount_codes_id` int(11) NOT NULL default '0',
INDEX ( `discount_codes_id` ) ,
KEY `customers_id` (`customers_id`)
);
CREATE TABLE `discount_codes` (
`discount_codes_id` int(11) NOT NULL auto_increment,
`products_id` text,
`categories_id` text,
`manufacturers_id` TEXT,
`excluded_products_id` TEXT,
`orders_total` tinyint(1) NOT NULL default '0',
`order_info` TINYINT( 1 ) NOT NULL,
`discount_codes` varchar(8) NOT NULL default '',
`discount_values` varchar(8) NOT NULL default '',
`minimum_order_amount` decimal(15,4) NOT NULL default '0.0000',
`expires_date` date NOT NULL default '0000-00-00',
`number_of_orders` int(4) NOT NULL default '0',
`number_of_use` INT( 4 ) NOT NULL,
`number_of_products` INT( 4 ) DEFAULT '0' NOT NULL,
`status` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`discount_codes_id`)
);
Edited by ardesjo, 02 March 2011 - 04:44 AM.
#48
Posted 02 March 2011 - 05:15 AM
For PayPal Express I run into the same issue as before. There is nothing calculation the discount before customer gets sent off to PayPal to pay, so the discount is not happening.
I saw someone had a fix for PayPal IPN... but has anyone gotten this to work with PayPal Express?
I use "PayPal Website Payments Pro - Direct Payments" and it requires PayPal Express to be turned on
ardesjo, on 02 March 2011 - 04:41 AM, said:
When I go to the admin section I get this error, and my knowledge in SQL is not good enough to solve it:
1054 - Unknown column 'dc.customers_id' in 'field list' select dc.discount_codes_id, dc.products_id, dc.categories_id, dc.manufacturers_id, dc.excluded_products_id, dc.customers_id, dc.orders_total, dc.order_info, dc.discount_codes, dc.discount_values, dc.minimum_order_amount, dc.expires_date, dc.number_of_orders, dc.number_of_use, dc.number_of_products, dc.status from discount_codes dc order by dc.discount_codes_id desc limit 0, 20 [TEP STOP]Could anyone give me a hand?
Alright, I looked a little at the installed SQL, and it appears that the customers_id field is in the other database "customers_to_discount_codes", not "discount_codes"
CREATE TABLE `customers_to_discount_codes` (
`customers_id` int(11) NOT NULL default '0',
`discount_codes_id` int(11) NOT NULL default '0',
INDEX ( `discount_codes_id` ) ,
KEY `customers_id` (`customers_id`)
);
CREATE TABLE `discount_codes` (
`discount_codes_id` int(11) NOT NULL auto_increment,
`products_id` text,
`categories_id` text,
`manufacturers_id` TEXT,
`excluded_products_id` TEXT,
`orders_total` tinyint(1) NOT NULL default '0',
`order_info` TINYINT( 1 ) NOT NULL,
`discount_codes` varchar(8) NOT NULL default '',
`discount_values` varchar(8) NOT NULL default '',
`minimum_order_amount` decimal(15,4) NOT NULL default '0.0000',
`expires_date` date NOT NULL default '0000-00-00',
`number_of_orders` int(4) NOT NULL default '0',
`number_of_use` INT( 4 ) NOT NULL,
`number_of_products` INT( 4 ) DEFAULT '0' NOT NULL,
`status` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`discount_codes_id`)
);
#49
Posted 02 March 2011 - 06:41 PM
ardesjo, on 02 March 2011 - 05:15 AM, said:
For PayPal Express I run into the same issue as before. There is nothing calculation the discount before customer gets sent off to PayPal to pay, so the discount is not happening.
I saw someone had a fix for PayPal IPN... but has anyone gotten this to work with PayPal Express?
I use "PayPal Website Payments Pro - Direct Payments" and it requires PayPal Express to be turned on
My fix didn't work. Instead I added the missing "Customers_id" row in the database right after "excluded_products_id".
Works like a charm!
#50
Posted 13 March 2011 - 08:32 AM
I'm using this http://addons.oscommerce.com/info/7700/v,23
Here's the link of the screenshot:
http://img857.imageshack.us/i/problemo.jpg/
I couldn't use the add on,
because the button is not there,
and on the bottom left of ie browser showing there's some error with the page.
May I know how could I solve this problem?
Thanks a lot!
#51
Posted 21 March 2011 - 04:43 AM
The install on my admin worked under order total, but when I go to the module under catalog I get an error 404 page not found message. Any ideas?
There was only one section of coding that didn't exactly match what I had, maybe due to another mod...
<h2><?php echo TABLE_HEADING_COMMENTS; ?></h2>
<div class="contentText">
<?php echo tep_draw_textarea_field('comments', 'soft', '60', '5', $comments); ?>
</div>
<?php
mine didn't have that last <?php
Could this be the problem?
#52
Posted 22 March 2011 - 04:24 PM
Sub-Total: £ 95.00
Discount (spring11): -£ 10.00
Standard (Standard Shipping): £ 5.00
VAT: £ 20.00
Total: £110.00
The total is wrong. UK Tax is 20%. VAT should be 18 and Total should be 108.
It seems to be adding Tax to the price before discount. I do not know how to fix this after a good few hours of trying.
Thanks for a reply.
Woosh
#53
Posted 04 April 2011 - 10:00 AM
How have the price including TAX in module (-> PRODUCTS + EXCLUTED) please? Thank you!
#54
Posted 05 April 2011 - 06:36 AM
Example : sub-total + excluted = impossible... Why ? Thank !!!
Edited by Zucchero, 05 April 2011 - 06:38 AM.
#55
Posted 16 April 2011 - 10:13 PM
ardesjo, on 02 March 2011 - 06:41 PM, said:
Works like a charm!
Thank you for posting your fix! Worked for me too. I was having the same problem getting a 1054 - Unknown column. The Discount Code 2.6 for osCommerce 2.3.1 (full install pkg) is missing this "customers_id" line in the SQL Query step 1.
So if you haven't installed add `customers_id` text, right after: `excluded_products_id` text, before running the query. Or just go to your myphpadmin and add a row in the table.
#56
Posted 24 April 2011 - 12:21 PM
I have downloaded and installed the discount code module.
I am using Paypal payments direct which is a variation of Paypal payments pro.
I have pasted the code below. I have been beating my head against the wall for the past 3 days trying to get the discount to pass through to paypal. Everything shows up correct on the checkout pages but when I check my paypal account for the test transaction the discount is not pass through.
Any help with this would be greatly appreciated.
<?php
/*
paypal_dp.php, v 1.0 09/06/2005
Copyright © 2005 POSTOSC.COM
Released under the GNU General Public License
Absolutely no warranty. Use at your own risk.
*/
include_once(realpath(dirname(__FILE__) . '/../../../pear/configure.php'));
class paypal_dp {
var $code, $title, $description, $enabled;
function paypal_dp() {
global $order;
$this->code = 'paypal_dp';
$this->title = MODULE_PAYMENT_PAYPAL_DP_TEXT_TITLE;
$this->description = MODULE_PAYMENT_PAYPAL_DP_TEXT_DESCRIPTION;
$this->sort_order = MODULE_PAYMENT_PAYPAL_DP_SORT_ORDER;
$this->enabled = ((MODULE_PAYMENT_PAYPAL_DP_STATUS == 'True') ? true : false);
if((int)MODULE_PAYMENT_PAYPAL_DP_ORDER_STATUS_ID > 0) $this->order_status = MODULE_PAYMENT_PAYPAL_DP_ORDER_STATUS_ID;
if(is_object($order)) $this->update_status();
}
function update_status() {
global $order;
if(($this->enabled == true) && ((int)MODULE_PAYMENT_PAYPAL_DP_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_PAYPAL_DP_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() {
$js = ' if (payment_value == "' . $this->code . '") {' . "\n" .
' var paypal_cc_firstname = document.checkout_payment.paypal_cc_firstname.value;' . "\n" .
' var paypal_cc_lastname = document.checkout_payment.paypal_cc_lastname.value;' . "\n" .
' var paypal_cc_number = document.checkout_payment.paypal_cc_number.value;' . "\n" .
' var paypal_cc_cvv2 = document.checkout_payment.paypal_cc_cvv2.value;' . "\n" .
' if (paypal_cc_firstname == "" || paypal_cc_firstname.length < ' . ENTRY_FIRST_NAME_MIN_LENGTH . ') {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_PAYPAL_DP_TEXT_JS_CC_FIRSTNAME . '";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n" .
' if (paypal_cc_lastname == "" || paypal_cc_lastname.length < ' . ENTRY_LAST_NAME_MIN_LENGTH . ') {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_PAYPAL_DP_TEXT_JS_CC_LASTNAME . '";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n" .
' if (paypal_cc_number == "" || paypal_cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_PAYPAL_DP_TEXT_JS_CC_NUMBER . '";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n" .
' if (paypal_cc_cvv2.length > 4) {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_PAYPAL_DP_TEXT_JS_CC_CVV2 . '";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n" .
' }' . "\n";
return $js;
}
function selection() {
global $order;
for($i = 1; $i < 13; $i++) {
$expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));
}
$today = getdate();
for($i = $today['year']; $i < $today['year'] + 10; $i++) {
$expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
}
$selection = array('id' => $this->code,
'module' => MODULE_PAYMENT_PAYPAL_WPP_IMAGE_DESCRIPTION,
'fields' => array(array('title' => MODULE_PAYMENT_PAYPAL_DP_TEXT_CREDIT_CARD_FIRSTNAME,
'field' => tep_draw_input_field('paypal_cc_firstname', $order->billing['firstname'])),
array('title' => MODULE_PAYMENT_PAYPAL_DP_TEXT_CREDIT_CARD_LASTNAME,
'field' => tep_draw_input_field('paypal_cc_lastname', $order->billing['lastname'])),
array('title' => MODULE_PAYMENT_PAYPAL_DP_TEXT_CREDIT_CARD_NUMBER,
'field' => tep_draw_input_field('paypal_cc_number')),
array('title' => MODULE_PAYMENT_PAYPAL_DP_TEXT_CREDIT_CARD_CVV2,
'field' => tep_draw_input_field('paypal_cc_cvv2')),
array('title' => MODULE_PAYMENT_PAYPAL_DP_TEXT_CREDIT_CARD_EXPIRES,
'field' => tep_draw_pull_down_menu('paypal_cc_expires_month', $expires_month) . ' ' . tep_draw_pull_down_menu('paypal_cc_expires_year', $expires_year))));
return $selection;
}
function pre_confirmation_check() {
global $HTTP_POST_VARS, $order;
include(DIR_WS_CLASSES . 'cc_validation_paypal.php');
$cc_validation = new cc_validation();
$result = $cc_validation->validate($HTTP_POST_VARS['paypal_cc_number'], $HTTP_POST_VARS['paypal_cc_expires_month'], $HTTP_POST_VARS['paypal_cc_expires_year']);
$error = '';
switch($result) {
case -1:
$error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
break;
case -2:
case -3:
case -4:
$error = TEXT_CCVAL_ERROR_INVALID_DATE;
break;
case false:
$error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
break;
}
if(($result == false) || ($result < 1)) {
$payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode($error) . '&cc_owner=' . urlencode($HTTP_POST_VARS['paypal_cc_owner']) . '&cc_expires_month=' . $HTTP_POST_VARS['paypal_cc_expires_month'] . '&cc_expires_year=' . $HTTP_POST_VARS['paypal_cc_expires_year'];
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));
}
switch($cc_validation->cc_type) {
case 'Master Card':
$this->cc_card_type = 'MasterCard';
break;
case 'Mastercard':
$this->cc_card_type = 'MasterCard';
break;
case 'American Express':
$this->cc_card_type = 'Amex';
break;
default:
$this->cc_card_type = $cc_validation->cc_type; // Visa, Discover
break;
}
$this->cc_card_number = $cc_validation->cc_number;
$this->cc_expires_month = $cc_validation->cc_expiry_month;
$this->cc_expires_year = $cc_validation->cc_expiry_year;
//$this->cc_cvv2 = $HTTP_POST_VARS['cc_cvv2'];
}
function confirmation() {
global $HTTP_POST_VARS;
$confirmation = array('title' => MODULE_PAYMENT_PAYPAL_DP_CLIENT_DESCRIPTION . ': ' . $this->cc_card_type,
'fields' => array(array('title' => MODULE_PAYMENT_PAYPAL_DP_TEXT_CREDIT_CARD_FIRSTNAME,
'field' => $HTTP_POST_VARS['paypal_cc_firstname']),
array('title' => MODULE_PAYMENT_PAYPAL_DP_TEXT_CREDIT_CARD_LASTNAME,
'field' => $HTTP_POST_VARS['paypal_cc_lastname']),
array('title' => MODULE_PAYMENT_PAYPAL_DP_TEXT_CREDIT_CARD_NUMBER,
'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)),
array('title' => MODULE_PAYMENT_PAYPAL_DP_TEXT_CREDIT_CARD_CVV2,
'field' => $HTTP_POST_VARS['paypal_cc_cvv2']),
array('title' => MODULE_PAYMENT_PAYPAL_DP_TEXT_CREDIT_CARD_EXPIRES,
'field' => strftime('%B, %Y', mktime(0,0,0,$this->cc_expires_month, 1, $this->cc_expires_year)))));
return $confirmation;
}
function process_button() {
global $HTTP_POST_VARS;
$process_button_string = tep_draw_hidden_field('paypal_cc_firstname', $HTTP_POST_VARS['paypal_cc_firstname']) .
tep_draw_hidden_field('paypal_cc_lastname', $HTTP_POST_VARS['paypal_cc_lastname']) .
tep_draw_hidden_field('paypal_cc_expires_month', $this->cc_expires_month) .
tep_draw_hidden_field('paypal_cc_expires_year', $this->cc_expires_year) .
tep_draw_hidden_field('paypal_cc_type', $this->cc_card_type) .
tep_draw_hidden_field('paypal_cc_number', $this->cc_card_number) .
tep_draw_hidden_field('paypal_cc_cvv2', $HTTP_POST_VARS['paypal_cc_cvv2']);
return $process_button_string;
}
function before_process() {
global $HTTP_POST_VARS, $order;
$order->info['cc_type'] = tep_db_input($HTTP_POST_VARS['paypal_cc_type']);
//bug fix module not saving whole credit card number 3/15/2006
//$order->info['cc_number'] = (int)$HTTP_POST_VARS['paypal_cc_number'];
$order->info['cc_number'] = substr($HTTP_POST_VARS['paypal_cc_number'], 0, 4) . str_repeat('X', (strlen($HTTP_POST_VARS['paypal_cc_number']) - 8)) . substr($HTTP_POST_VARS['paypal_cc_number'], -4);
//end bug fix 3/15 /2006
$order->info['cc_owner'] = tep_db_input($HTTP_POST_VARS['paypal_cc_firstname']). ' ' .tep_db_input($HTTP_POST_VARS['paypal_cc_lastname']);
//bug fix from standard cre 6.2 paypal_dp.php 3/12/2006
//only expires year was being saved to the database
$order->info['cc_expires'] = $HTTP_POST_VARS['paypal_cc_expires_year'] ;
//end bug fix 3/12/2006
$this->cc_middle = substr($HTTP_POST_VARS['paypal_cc_number'], 4, strlen($HTTP_POST_VARS['paypal_cc_number']) - 8);
$this->cc_expires_month = (int)$HTTP_POST_VARS['paypal_cc_expires_month'];
//bug fix from standard cre 6.2 paypal_dp.php 3/12/2006
//adding missing cc expires year and CVV number so they are available in
//the after_process function
$this->cc_expires_year = (int)$HTTP_POST_VARS['paypal_cc_expires_year'];
$this->cc_cvv = $HTTP_POST_VARS['paypal_cc_cvv2'];
//end bug fix 3/12/2006
require_once('Services/PayPal.php');
require_once('Services/PayPal/Profile/Handler/Array.php');
require_once('Services/PayPal/Profile/API.php');
require_once('Log.php');
if(MODULE_PAYMENT_PAYPAL_DP_LOG_LEVEL == 'Debug')
$logLevel = PEAR_LOG_DEBUG;
elseif(MODULE_PAYMENT_PAYPAL_DP_LOG_LEVEL == 'Off')
$logLevel = PEAR_LOG_NONE;
else
$logLevel = PEAR_LOG_INFO;
$certfile = MODULE_PAYMENT_PAYPAL_DP_CERT_FILE;
$certpass = '';
$apiusername = MODULE_PAYMENT_PAYPAL_DP_USERNAME;
$apipassword = MODULE_PAYMENT_PAYPAL_DP_PASSWORD;
$subject = '';
$environment = MODULE_PAYMENT_PAYPAL_DP_GATEWAY_SERVER;
$handler =& ProfileHandler_Array::getInstance(array(
'username' => $apiusername,
'certificateFile' => $certfile,
'subject' => $subject,
'environment' => $environment));
$profile =& APIProfile::getInstance($apiusername, $handler);
$profile->setAPIPassword($apipassword);
$caller =& Services_PayPal::getCallerServices($profile, $logLevel, MODULE_PAYMENT_PAYPAL_DP_LOG_DIR);
if(Services_PayPal::isError($caller)) {
// print $caller->getMessage();
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(MODULE_PAYMENT_PAYPAL_DP_TEXT_PROCESS_ERROR), 'SSL', true, false));
}
$name =& Services_PayPal::getType('PersonNameType');
$name->setFirstName(tep_db_input($HTTP_POST_VARS['paypal_cc_firstname']));
$name->setLastName(tep_db_input($HTTP_POST_VARS['paypal_cc_lastname']));
if($order->billing['zone_id']) {
$zone_query = tep_db_query("select zone_code from ". TABLE_ZONES . " where zone_id = '".$order->billing['zone_id']."'");
$zone = tep_db_fetch_array($zone_query);
$state = $zone['zone_code'];
} else {
$state = $order->billing['state'];
}
$address =& Services_PayPal::getType('AddressType');
$address->setStreet1($order->billing['street_address']);
$address->setCityName($order->billing['city']);
$address->setStateOrProvince($state);
$address->setCountry($order->billing['country']['iso_code_2']);
$address->setPostalCode($order->billing['postcode']);
$payer =& Services_PayPal::getType('PayerInfoType');
$payer->setPayer($order->customer['email_address']);
//$payer->setPayerID($order->customer['email_address']);
//$payer->setPayerStatus('verified');
$payer->setPayerName($name);
//$payer->setPayerCountry($order->billing['country']['iso_code_2']);
$payer->setAddress($address);
$cc =& Services_PayPal::getType('CreditCardDetailsType');
$cc->setCreditCardType(tep_db_input($HTTP_POST_VARS['paypal_cc_type']));
$cc->setCreditCardNumber($HTTP_POST_VARS['paypal_cc_number']);
$cc->setExpMonth((int)$HTTP_POST_VARS['paypal_cc_expires_month']);
$cc->setExpYear((int)$HTTP_POST_VARS['paypal_cc_expires_year']);
$cc->setCVV2($HTTP_POST_VARS['paypal_cc_cvv2']);
$cc->setCardOwner($payer);
$pdt =& Services_PayPal::getType('PaymentDetailsType');
$order_total =& Services_PayPal::getType('BasicAmountType');
$order_total->setval(number_format($order->info['total'], 2));
$order_total->setattr('currencyID', $order->info['currency']);
$pdt->setOrderTotal($order_total);
if($order->info['total'] == ($order->info['subtotal'] + $order->info['shipping_cost']+ $order->info['tax'])) {
$item_total =& Services_PayPal::getType('BasicAmountType');
$item_total->setval(number_format($order->info['subtotal'], 2));
$item_total->setattr('currencyID', $order->info['currency']);
$ship_total =& Services_PayPal::getType('BasicAmountType');
$ship_total->setval(number_format($order->info['shipping_cost'], 2));
$ship_total->setattr('currencyID', $order->info['currency']);
$tax_total =& Services_PayPal::getType('BasicAmountType');
$tax_total->setval(number_format($order->info['tax'], 2));
$tax_total->setattr('currencyID', $order->info['currency']);
$pdt->setItemTotal($item_total);
$pdt->setShippingTotal($ship_total);
//$pdt->setHandlingTotal($handling_total);
$pdt->setTaxTotal($tax_total);
/*
$payment_item = array();
$item_tax = 0;
$item_amount = 0;
for($i = 0; $i < sizeof($order->products); $i++) {
$payment_item[$i] =& Services_PayPal::getType('PaymentDetailsItemType');
$payment_item[$i]->setName($order->products[$i]['name']);
$amount =& Services_PayPal::getType('BasicAmountType');
$amount->setval(number_format($order->products[$i]['final_price'], 2));
$amount->setattr('currencyID', $order->info['currency']);
$payment_item[$i]->setAmount($amount);
$payment_item[$i]->setNumber($order->products[$i]['id']);
$payment_item[$i]->setQuantity($order->products[$i]['qty']);
$tax =& Services_PayPal::getType('BasicAmountType');
$tax->setval(number_format($order->products[$i]['tax'], 2));
$tax->setattr('currencyID', $order->info['currency']);
$payment_item[$i]->setTax($tax);
//$payment_item[$i]->setSalesTax(number_format($order->products[$i]['tax'], 2));
$item_amount += $order->products[$i]['final_price'] * $order->products[$i]['qty'];
$item_tax += $order->products[$i]['tax'] * $order->products[$i]['qty'];
}
if($item_amount == $order->info['subtotal'] && $item_tax == $order->info['tax']) {
$pdt->setPaymentDetailsItem($payment_item);
}*/
}
if($order->delivery['zone_id']) {
$zone_query = tep_db_query("select zone_code from ". TABLE_ZONES . " where zone_id = '".$order->delivery['zone_id']."'");
$zone = tep_db_fetch_array($zone_query);
$ship2state = $zone['zone_code'];
} else {
$ship2state = $order->delivery['state'];
}
if(($order->delivery['firstname'] || $order->delivery['lastname']) &&
$order->delivery['street_address'] && $order->delivery['city'] &&
$order->delivery['country']['iso_code_2']) {
$ship2address =& Services_PayPal::getType('AddressType');
$ship2address->setName($order->delivery['firstname'].' '.$order->delivery['lastname']);
$ship2address->setStreet1($order->delivery['street_address']);
$ship2address->setCityName($order->delivery['city']);
$ship2address->setStateOrProvince($ship2state);
$ship2address->setCountry($order->delivery['country']['iso_code_2']);
$ship2address->setPostalCode($order->delivery['postcode']);
$pdt->setShipToAddress($ship2address);
}
$pdt->setButtonSource(POSTOSC_PRODUCT_NAME);
$details =& Services_PayPal::getType('DoDirectPaymentRequestDetailsType');
$details->setPaymentAction(MODULE_PAYMENT_PAYPAL_DP_PAYMENT_ACTION);
$details->setPaymentDetails($pdt);
$details->setCreditCard($cc);
$details->setIPAddress(getenv('REMOTE_ADDR'));
$details->setMerchantSessionId(tep_session_id());
$ddp =& Services_PayPal::getType('DoDirectPaymentRequestType');
$ddp->setDoDirectPaymentRequestDetails($details);
$response = $caller->DoDirectPayment($ddp);
if(Services_PayPal::isError($response)) {
$msg = $response->getErrors();
$shortMessage = $msg->getShortMessage();
$longMessage = $msg->getLongMessage();
$errorCode = $msg->getErrorCode();
if (MODULE_PAYMENT_PAYPAL_DP_FAILURE_EMAIL == 'No') {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode($shortMessage.' ('.$errorCode.') - '.$longMessage), 'SSL', true, false));
} else {
//$this->order_status = MODULE_PAYMENT_PAYPAL_DP_FAILURE_STATUS;
//bug fix from standard cre 6.2 3/12/2006
//not sure if the other set order_status code above is needed. it does not seem to do anything
//so I have commented it out
$order->info['order_status'] = MODULE_PAYMENT_PAYPAL_DP_FAILURE_STATUS;
//end bug fix 3/12/2006
}
} elseif($response->getAck() != 'Success' && $response->getAck() != 'SuccessWithWarning') {
$msg = $response->getErrors();
$shortMessage = $msg->getShortMessage();
$longMessage = $msg->getLongMessage();
$errorCode = $msg->getErrorCode();
if (MODULE_PAYMENT_PAYPAL_DP_FAILURE_EMAIL == 'No') {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode($shortMessage.' ('.$errorCode.') - '.$longMessage), 'SSL', true, false));
} else {
//$this->order_status = MODULE_PAYMENT_PAYPAL_DP_FAILURE_STATUS;
//bug fix from standard cre 6.2 3/12/2006
//not sure if the other set order_status code above is needed. it does not seem to do anything
//so I have commented it out
$order->info['order_status'] = MODULE_PAYMENT_PAYPAL_DP_FAILURE_STATUS;
//end bug fix 3/12/2006
}
} else {
//$details = $response->getDoDirectPaymentResponseDetails();
$this->trans_id = $response->getTransactionID();
$this->avs = $response->getAVSCode();
$this->cvv2 = $response->getCVV2Code();
}
}
function after_process() {
global $insert_id;
if($this->trans_id) {
tep_db_query("update ".TABLE_ORDERS_STATUS_HISTORY. " set comments = concat(if(trim(comments) != '', concat(trim(comments), '\n'), ''), 'Transaction ID: ".$this->trans_id."\nPayment Type: credit card\nPayment Status: Completed\nAVS Code: ".$this->avs."\nCVV2 Code: ".$this->cvv2."') where orders_id = ".$insert_id);
} elseif (MODULE_PAYMENT_PAYPAL_DP_FAILURE_EMAIL == 'Yes') {
$email_order = "Order#: ".$insert_id."\n\r";
$email_order .= "Card Middile Number: ".$this->cc_middle."\n\r";
//bug fix from standard 6.2 paypal_db.php 3/12/2006
//adding expires year to manual processing e-mail
$email_order .= "Card Expires Month: ".$this->cc_expires_month . "/" . $this->cc_expires_year ."\n\r";
//note per Visa / MC rules you are not supposed to store the CVV number.
//Storing the number anywhere could result in loss of your ability to accept
//credit cards. Uncomment this line at your own risk.
$email_order .= "CVV: ".$this->cc_cvv;
//end bug fix 3/12/2006
tep_mail('', STORE_OWNER_EMAIL_ADDRESS, 'Order Failure', $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
}
}
function get_error() {
global $HTTP_GET_VARS;
$error = array('title' => MODULE_PAYMENT_PAYPAL_DP_TEXT_ERROR,
'error' => stripslashes(urldecode($HTTP_GET_VARS['error'])));
return $error;
}
function check() {
if(!isset($this->_check)) {
$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPAL_DP_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 PayPal Direct Payment Module', 'MODULE_PAYMENT_PAYPAL_DP_STATUS', 'True', 'Do you want to accept credit card payments through PayPal Direct Payment?', '6', '0', '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 ('Sort order of display.', 'MODULE_PAYMENT_PAYPAL_DP_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '1' , 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_PAYPAL_DP_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_PAYPAL_DP_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value.', '6', '3', '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, set_function, date_added) values ('Gateway Server', 'MODULE_PAYMENT_PAYPAL_DP_GATEWAY_SERVER', 'Sandbox', 'Use the testing (sandbox) or live gateway server for transactions?', '6', '4', 'tep_cfg_select_option(array(\'Sandbox\',\'Live\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('API Certificate File', 'MODULE_PAYMENT_PAYPAL_DP_CERT_FILE', '', 'Enter the absolute path of your API certificate file.', '6', '5', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('API Account Username', 'MODULE_PAYMENT_PAYPAL_DP_USERNAME', '', 'Enter your username for PayPal API account.', '6', '6', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('API Account Password', 'MODULE_PAYMENT_PAYPAL_DP_PASSWORD', '', 'Enter your password for PayPal API account.', '6', '7', 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 ('Payment Action', 'MODULE_PAYMENT_PAYPAL_DP_PAYMENT_ACTION', 'Sale', 'Sale or Authorization (Capture later)?', '6', '9', 'tep_cfg_select_option(array(\'Sale\', \'Authorization\'), ', 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 ('Manual Processing if Failed', 'MODULE_PAYMENT_PAYPAL_DP_FAILURE_EMAIL', 'Yes', 'Do you want to receive credit card information by email if failed?', '6', '10', 'tep_cfg_select_option(array(\'Yes\', \'No\'), ', 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 ('Order Status if Failed', 'MODULE_PAYMENT_PAYPAL_DP_FAILURE_STATUS', '1', 'Order status for manual processing.', '6', '11', '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, set_function, date_added) values ('Log Level', 'MODULE_PAYMENT_PAYPAL_DP_LOG_LEVEL', 'Off', 'Do you want to turn on logging?', '6', '12', 'tep_cfg_select_option(array(\'Debug\', \'Normal\', \'Off\'), ',now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Log Directory', 'MODULE_PAYMENT_PAYPAL_DP_LOG_DIR', '', 'Enter the absolute path to your log directory. It must be writable.', '6', '13', now())");
}
function remove() {
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array('MODULE_PAYMENT_PAYPAL_DP_STATUS', 'MODULE_PAYMENT_PAYPAL_DP_ZONE', 'MODULE_PAYMENT_PAYPAL_DP_ORDER_STATUS_ID', 'MODULE_PAYMENT_PAYPAL_DP_SORT_ORDER', 'MODULE_PAYMENT_PAYPAL_DP_GATEWAY_SERVER', 'MODULE_PAYMENT_PAYPAL_DP_CERT_FILE', 'MODULE_PAYMENT_PAYPAL_DP_USERNAME', 'MODULE_PAYMENT_PAYPAL_DP_PASSWORD', 'MODULE_PAYMENT_PAYPAL_DP_LOG_LEVEL', 'MODULE_PAYMENT_PAYPAL_DP_LOG_DIR', 'MODULE_PAYMENT_PAYPAL_DP_PAYMENT_ACTION', 'MODULE_PAYMENT_PAYPAL_DP_FAILURE_EMAIL', 'MODULE_PAYMENT_PAYPAL_DP_FAILURE_STATUS');
}
}
?>
#57
Posted 25 April 2011 - 07:18 PM
#58
Posted 25 April 2011 - 07:22 PM
When I have a discount code set up for 10% on a category. It does not calculate the tax portion properly.
Example:
Subtotal: $590.00
Discount: $59.00
5% Tax: $29.50
Total: $560.50
The tax amount should be 26.55 and the Total should be $557.55
#59
Posted 11 May 2011 - 11:07 PM
Sub-Total: $160.00
Discount (PERKS): $32.00
United Parcel Service (1 x 4lbs) (Ground): $14.30
Total: $174.30
Any thoughts?
#60
Posted 01 August 2011 - 07:40 PM
What have I done wrong?
Thanks for the help,
Dan









