Jump to content



Photo
* * * - - 3 votes

[add-on] Discount Code (support)


  • Please log in to reply
143 replies to this topic

#41   wijnendael

wijnendael
  • Members
  • 58 posts
  • Real Name:Tony

Posted 05 February 2011 - 14:46

How doe the customer notification of discount code work. I understand that the customer can enter the discount code into the box on payment information, but in the explanation it says you can use the link for newsletters etc as follows:-
Customer gets a discount by clicking a link or inserting the discount code while checkout. The link containing the discount code (http://www.yourshop....t_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   ffl

ffl
  • Members
  • 25 posts
  • Real Name:David Surgi

Posted 15 February 2011 - 00:52

To All.

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   scandic_outlet

scandic_outlet
  • Members
  • 108 posts
  • Real Name:Michael David

Posted 27 February 2011 - 22:12

Hi All

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?
Dedicated OsCommerce user. 2011 will be the return of OsC

#44   PiLLaO

PiLLaO
  • Members
  • 156 posts
  • Real Name:Gustavo

Posted 28 February 2011 - 23:25

Hi All

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?

Open catalog/includes/modules/order_total/ot_discount.php and find:

$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 /rolleyes.gif' class='bbc_emoticon' alt=':rolleyes:' />
Bye!

#45   PiLLaO

PiLLaO
  • Members
  • 156 posts
  • Real Name:Gustavo

Posted 01 March 2011 - 22:19

Using this "fix", tax are ok

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 /wink.gif' class='bbc_emoticon' alt=';)' />

Regards!!

#46   scandic_outlet

scandic_outlet
  • Members
  • 108 posts
  • Real Name:Michael David

Posted 01 March 2011 - 22:21

great.
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..
Dedicated OsCommerce user. 2011 will be the return of OsC

#47   ardesjo

ardesjo
  • Members
  • 80 posts
  • Real Name:Stephanie

Posted 02 March 2011 - 04:41

Aww, I could never get any coupons to work with my checkout on my older version of OSC, but now that I finally upgraded to 2.3.1 I was hoping it would work.
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? /smile.gif' class='bbc_emoticon' alt=':)' />

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.


#48   ardesjo

ardesjo
  • Members
  • 80 posts
  • Real Name:Stephanie

Posted 02 March 2011 - 05:15

Alright, so I fixed my SQL issues by removing "dc.customers_id," from the query in my ot_discount.php file. Not sure if that's going to cause an issue, but it's working for now, with credit cards at least.

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 /sad.gif' class='bbc_emoticon' alt=':(' />

Aww, I could never get any coupons to work with my checkout on my older version of OSC, but now that I finally upgraded to 2.3.1 I was hoping it would work.
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? /smile.gif' class='bbc_emoticon' alt=':)' />

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   ardesjo

ardesjo
  • Members
  • 80 posts
  • Real Name:Stephanie

Posted 02 March 2011 - 18:41

Alright, so I fixed my SQL issues by removing "dc.customers_id," from the query in my ot_discount.php file. Not sure if that's going to cause an issue, but it's working for now, with credit cards at least.

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 /sad.gif' class='bbc_emoticon' alt=':(' />


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   lalalalala

lalalalala
  • Validating
  • 8 posts
  • Real Name:lala
  • Gender:Not Telling

Posted 13 March 2011 - 08:32

Hi,

I'm using this http://addons.oscomm.../info/7700/v,23

Here's the link of the screenshot:
http://img857.images...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   wildvettes

wildvettes
  • Members
  • 81 posts
  • Real Name:Damien Routledge

Posted 21 March 2011 - 04:43

I am running 2.3.1 and did the manual install instructions.

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   wooshman

wooshman
  • Members
  • 19 posts
  • Real Name:Ben

Posted 22 March 2011 - 16:24

Hi, I have looked at the tax fixes already and none seem to fix my problem.

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   Zucchero

Zucchero
  • Members
  • 2 posts
  • Real Name:Ploucos
  • Gender:Male

Posted 04 April 2011 - 10:00

Hello! I'm French.
How have the price including TAX in module (-> PRODUCTS + EXCLUTED) please? Thank you!

#54   Zucchero

Zucchero
  • Members
  • 2 posts
  • Real Name:Ploucos
  • Gender:Male

Posted 05 April 2011 - 06:36

Hello !

Example : sub-total + excluted = impossible... Why ? Thank !!!

Edited by Zucchero, 05 April 2011 - 06:38.


#55   epwork

epwork
  • Members
  • 48 posts
  • Real Name:Tiffany
  • Gender:Female
  • Location:Los Angeles

Posted 16 April 2011 - 22:13

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!


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   Mr. Osei

Mr. Osei
  • Members
  • 1 posts
  • Real Name:Craig Davis

Posted 24 April 2011 - 12:21

Hello,

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) . '&nbsp;' . 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   jlmorales

jlmorales
  • Members
  • 2 posts
  • Real Name:Jose Luis Morales

Posted 25 April 2011 - 19:18

Please do you find the solution... Having the same issue

#58   jlmorales

jlmorales
  • Members
  • 2 posts
  • Real Name:Jose Luis Morales

Posted 25 April 2011 - 19:22

Probelm:
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   chicagola

chicagola
  • Members
  • 1 posts
  • Real Name:Chicago La

Posted 11 May 2011 - 23:07

I installed Discount Code 2.9 for osCommerce 2.2, and everything works good, except the discount is not adding to the total.

Sub-Total: $160.00
Discount (PERKS): $32.00
United Parcel Service (1 x 4lbs) (Ground): $14.30
Total: $174.30

Any thoughts?

#60   danthman

danthman
  • Members
  • 192 posts
  • Real Name:Dan Snyder
  • Location:Ft Lauderdale, FL

Posted 01 August 2011 - 19:40

I added Discount codes to OSCommerce 2.2 and it totals fine but I get MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_CONFIG instead of the discount coupon that was used on the checkout page and on the order process email. Thinking it was a problem with the includes/languages/english/modules/order_total/ot_discount_coupon.php file I changed MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY to MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_CONFIG and now I see Discount Coupon %s applied. Getting closer, bit it still does not display the actual discount code used.

What have I done wrong?

Thanks for the help,

Dan