Payment Module Integration in osCommerce
Some contributed payment modules in osCommerce (such as PayPal) are not naturally aware of the existence of discounts (mine or any other contribution or extension). This is an issue in osCommerce 2.2 and 2.3 (and the issue is different in each version).I have figured out a workaround for osCommerce 2.2, but I don't have enough experience installing in osCommerce 2.3 to know what will work and what won't.
Please test a free discounting program, such as Quantity Discounts for osCommerce or Better Together for osCommerce, and run a complete transaction through it using each payment module you support, prior to buying any paid discount module from me.
If you need me to fix a payment module so that it works with one of my modules, I'm happy to do it, but please understand that it is a paid installation service costing $120.
Payment Modules in osCommerce 2.2
Note: This only applies to osCommerce 2.2. For osCommerce 2.3, please click here.Some contributed payment modules in osCommerce 2.2 (such as PayPal) are not naturally aware of the existence of discounts (mine or any other contribution or extension). For this reason, you must ensure any payment module you use takes discounts into account. Here are some guidelines:
- If the payment module passes in a subtotal, shipping and tax, modify the subtotal (as shown below) to include the discount.
- If the payment module passes in a shipping, tax, and total, modify the total (as shown below) to include the discount.
- In the case of PayPal, turn OFF the sending of line item details, which will confuse PayPal since the total is not the sum of the line items. This can be done through the admin panel by setting Transaction Type to "Aggregate."
paypal_ipn.php
):
foreach ($order_totals as $ot) { $order_total[$ot['code']] = $ot['value']; }then the discount is available in the $order_total variable as follows:
Module | Variable Name |
---|---|
Quantity Discounts | $order_total['ot_quantity_discount'] |
Better Together | $order_total['ot_better_together'] |
Big Chooser | $order_total['ot_big_chooser'] |
Big Spender | $order_total['ot_bigspender_discount'] |
Table Discounts | $order_total['ot_table_discounts'] |
Free Gift Chooser | ot_freegift_chooser.php |
So for instance, subtracting the Quantity Discounts discount from a variable called $subtotal would be done as follows:
$subtotal = $subtotal - $order_total['ot_quantity_discounts'];This would be done in process_button() for example.
Another more sophisticated approach would be to execute the order totals and use
ot_total
, which is the final total after discounts.
// BEGIN: Change to use order_totals to get values $order_id = substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1); $ord_totals = array(); $ord_totals_query = tep_db_query("select class, value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' order by sort_order"); while ($totals = tep_db_fetch_array($ord_totals_query)) { $ord_totals[$totals['class']] = $totals['value']; } // END . . . $parameters['business'] = MODULE_PAYMENT_PAYPAL_IPN_ID; // BEGIN : use order_totals['ot_total'] for order total to include all discounts. if ($ord_totals['ot_total'] > 0) { $parameters['amount'] = number_format($ord_totals['ot_total'], $currencies->get_decimal_places($currency)); } else { $parameters['amount'] = number_format($order->info['total'] - $order->info['shipping_cost'] - $order->info['tax'], $currencies->get_decimal_places($currency)); } // END
Payment Modules in osCommerce 2.3
Note: This only applies to osCommerce 2.3. For osCommerce 2.2, please click here.Some contributed payment modules in osCommerce 2.3 (2.3.1-2.3.3.x) are not naturally aware of the existence of discounts (mine or any other contribution or extension). For this reason, you must ensure any payment module you use takes discounts into account.
For some carts, PayPal Website Payments Standard has been changed to accommodate these osC discounts, but in a bizarre way. If you have
Subtotal: $30 Postage: $7.69 Discount: -$12.00 Tax (7%): $1.26 ----------------------------- Total: $26.95PayPal turns this into
Subtotal: $17.16 Tax (7%): $2.10 Shipping: $7.69 ----------------------------- Total: $26.95This is in osC 2.3.3, with no changes made to PayPal. But the final number is correct (and your actual order total figures as shown in osC admin will be correct per the checkout confirmation page).
I have seen this work on some carts and not on others depending on mods and settings; please test your own cart carefully.
PayPal Express in osCommerce 2.3 still has problems with osCommerce discounts. Here is one way to fix it:
In
./ext/modules/payment/paypal/express.php
, right above the block on
line 544-545 that sets the item and tax amounts:
$params['ITEMAMT'] = $items_total; $params['TAXAMT'] = $tax_total;insert the discount computation. Here's an example for Quantity Discounts. Pull in the module and its language file. Then compute the discount and add it in as a line item.
// Add OT require('includes/modules/order_total/ot_quantity_discount.php'); include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_quantity_discount.php'); $discount = new ot_quantity_discount(); if ($discount->check()) { $qd = $discount->calculate_deductions(); if ($qd['total'] > 0) { $amt = $qd['total'] * -1; $params['L_NAME' . $line_item_no] = 'Discount'; $params['L_AMT' . $line_item_no] = $amt; $params['L_NUMBER' . $line_item_no] = 0; $params['L_QTY' . $line_item_no] = 1; $product_tax = 0; $params['L_TAXAMT' . $line_item_no] = $paypal_express->format_raw($product_tax); $items_total += $paypal_express->format_raw($amt); $line_item_no++; } }
For other modules, here are the filenames. The object to be created is the filename without the
.php
suffix.
Module | File Name |
---|---|
Quantity Discounts | ot_quantity_discount.php |
Better Together | ot_better_together.php |
Big Chooser | ot_big_chooser.php |
Big Spender | ot_bigspender_discount.php |
Table Discounts | ot_table_discounts.php |
Free Gift Chooser | ot_freegift_chooser.php |