Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Official PayPal IPN Support Thread


Mark Evans

Recommended Posts

Greetings,

Great module, works perfectly. I would like to be able to pass the text attribute (created with Text Attributes Mod v1.2) to PayPal and confirm email. In testing, it does not record in the Admin orders or email. Will I need to add the following code (mod in check_process.php from aboce contrib) to both the paypal_ipn.php in includes/modules as well as /languages? If anyone has these 2 contribs, would appreciate the knowledge share.

 

// denuz text attr

 

$attr_q = tep_db_query("select * from customers_basket_text_attributes where session_id = '$osCsid' and products_id = " . tep_get_prid($order->products[$i]['id']));

while ($attr = tep_db_fetch_array($attr_q)) {

tep_db_query("insert into orders_text_attributes values ($insert_id, " . tep_get_prid($order->products[$i]['id']) . ", " . $attr['products_text_attributes_id'] . ", '" . $attr['products_text_attributes_text'] . "')");

}

tep_db_query("delete from customers_basket_text_attributes where products_id = " . tep_get_prid($order->products[$i]['id']) . " and session_id = '" . $osCsid . "'");

 

// eof denuz text attr

 

 

 

Thanks in advance..

Link to comment
Share on other sites

I would like to be able to pass the text attribute (created with Text Attributes Mod v1.2) to PayPal and confirm email.

You need to merge the code into paypal_ipn.php (similar to what I've done for QTPro in one of the help files). Take care to make all necessary changes, including anything for the email if needed. I don't think you need to touch the language file but a test will show that quickly. All the best, Terra

My code for combining PayPal IPN with ** QTPro 4.25 ** osC Affiliate ** CCGV(trad)

and how to solve the invoice already paid error

General info: Allow customer to delete order comment ** FTP Programs & Text Editors ** Amending order email **

Link to comment
Share on other sites

Warning: main(includes/modules/payment/paypal/classes/osC/osC.class.php): failed to open stream: No such file or directory in /home/*******/public_html/includes/application_top.php on line 134

That code / file is not part of the IPN - looks like you are using a different module. Now of course, you could always just install the official PayPal IPN on your site :D all the best, Terra

 

PS: but if you are trying to debug - first thing is to check is whether the file is there it tries to access - could be that something got lost or corrupted in the transfer.

My code for combining PayPal IPN with ** QTPro 4.25 ** osC Affiliate ** CCGV(trad)

and how to solve the invoice already paid error

General info: Allow customer to delete order comment ** FTP Programs & Text Editors ** Amending order email **

Link to comment
Share on other sites

Hi everyone,

I having a strange problem with this mod, and I'm hoping someone can help.

 

I installed all the files of the newest version of the PayPal IPN mod as instructed in the Readme file, and then installed it using the OSC Admin tool. As soon as I did, I realized that I can't complete orders anymore. When I access Checkout, I get the first page (Delivery Information), but when I hit Continue (to the checkout_payment.php page) only a blank page loads. Before I installed this mod, I was able to get to the checkout_payment.php page. I am currently not using any other contribs.

 

Has anyone encoutered a similar problem before? Let me know if I need to provide more info.

 

Thanks in advance,

GL

Link to comment
Share on other sites

Firstly - great contribution!!!

 

OK onto my problem

 

I have trawled through (as best I can!) the 60+ pages but did not come across anybody with this issue

 

Basically I end up with 2 orders for each customer.

 

For example I make a purchase, go through the checkout process, get transferred to paypal, complete the purchase and am returned to my site (which I think is how it should work) but when I go and look at my orders I see 2 for the purchase.

 

One of the orders has the status set to "Preparing [Paypal IPN]" and the second is set to "Pending" - both of which refelct accurately the values I have in the Prparing Order STatus & Paypal Acknolwged Order Status fields for the contribution...

 

It looks like the mod is creating a new order as opposed to updating the old one - is this the way it is supposed towork?

 

Any help is gratefully appreciated

 

Thanks,

Simon

Link to comment
Share on other sites

I tried searching the thread but couldn't find the answer. Everything is working fine actually, my question is about the methodology of the module. Why is _cart set to not work with EWP? If it a size/POST limit or something? I like the functionality of EWP, just for knowing that my POST data WILL NOT be manipulated at all, but would prefer the customer to be able to see the contents of their cart on paypal also.. I've already converted the code to do _cart over EWP, but just wondering if anyone else has tried this and experienced problems with it. It seems to be working, but horror stories are welcome also.

 

Oh, one other thing I did change about my install is the way tax and shipping were done for the _cart method. Shipping was correct, but looked kind of odd with the tax already added in (it didn't jive with what the customer saw on my checkout screen, even though it was correct). But the actual tax on the items was wrong and unfortunately doing it the way paypal requires you to do it per item will frequently yield incorrect results. the problem is that paypal requires tax per item per single quantity. So (real life example):

 

Item is $1.75

tax at 5.6% is $.098

if I bought 10 of these items, my tax would be $.98

 

unfortunately paypal requires a 2 decimal tax (I already triple checked this). so you would have to round up for paypal ($.10). So now if I order 10 units, tax would be $1.00, not $.98. luckily paypal has the tax_cart field which will override tax_x for the entire cart. so I simply stick tax in tax_cart and everything is fine on paypal.

Link to comment
Share on other sites

Inventory does not subtract when a successful payment through paypal is made, why not? It reduces when they use the option for money order or check? Below is my paypal_ipn code

 

THANKS!!

 

Jon

 

<?php

/*

$Id: paypal_ipn.php,v 1.1.2.11 2004/12/05 19:14:35 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright (c) 2004 osCommerce

 

Released under the GNU General Public License

*/

 

class paypal_ipn {

var $code, $title, $description, $enabled, $identifier;

 

// class constructor

function paypal_ipn() {

global $order;

 

$this->code = 'paypal_ipn';

$this->title = MODULE_PAYMENT_PAYPAL_IPN_TEXT_TITLE;

$this->description = MODULE_PAYMENT_PAYPAL_IPN_TEXT_DESCRIPTION;

$this->sort_order = MODULE_PAYMENT_PAYPAL_IPN_SORT_ORDER;

$this->enabled = ((MODULE_PAYMENT_PAYPAL_IPN_STATUS == 'True') ? true : false);

$this->identifier = 'osCommerce PayPal IPN v1.0';

 

if ((int)MODULE_PAYMENT_PAYPAL_IPN_PREPARE_ORDER_STATUS_ID > 0) {

$this->order_status = MODULE_PAYMENT_PAYPAL_IPN_PREPARE_ORDER_STATUS_ID;

}

 

if (is_object($order)) $this->update_status();

 

if (MODULE_PAYMENT_PAYPAL_IPN_GATEWAY_SERVER == 'Live') {

$this->form_action_url = 'https://www.paypal.com/cgi-bin/webscr';

} else {

$this->form_action_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';

}

}

 

// class methods

function update_status() {

global $order;

 

if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PAYPAL_IPN_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_IPN_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 $cartID, $cart_PayPal_IPN_ID, $customer_id, $languages_id, $order, $order_total_modules;

 

if (tep_session_is_registered('cartID')) {

$insert_order = false;

 

if (tep_session_is_registered('cart_PayPal_IPN_ID')) {

$order_id = substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1);

 

$curr_check = tep_db_query("select currency from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");

$curr = tep_db_fetch_array($curr_check);

 

if ( ($curr['currency'] != $order->info['currency']) || ($cartID != substr($cart_PayPal_IPN_ID, 0, strlen($cartID))) ) {

$check_query = tep_db_query('select orders_id from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '" limit 1');

 

if (tep_db_num_rows($check_query) < 1) {

tep_db_query('delete from ' . TABLE_ORDERS . ' where orders_id = "' . (int)$order_id . '"');

tep_db_query('delete from ' . TABLE_ORDERS_TOTAL . ' where orders_id = "' . (int)$order_id . '"');

tep_db_query('delete from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '"');

tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS . ' where orders_id = "' . (int)$order_id . '"');

tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . ' where orders_id = "' . (int)$order_id . '"');

tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_DOWNLOAD . ' where orders_id = "' . (int)$order_id . '"');

}

 

$insert_order = true;

}

} else {

$insert_order = true;

}

 

if ($insert_order == true) {

$order_totals = array();

if (is_array($order_total_modules->modules)) {

reset($order_total_modules->modules);

while (list(, $value) = each($order_total_modules->modules)) {

$class = substr($value, 0, strrpos($value, '.'));

if ($GLOBALS[$class]->enabled) {

for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {

if (tep_not_null($GLOBALS[$class]->output[$i]['title']) && tep_not_null($GLOBALS[$class]->output[$i]['text'])) {

$order_totals[] = array('code' => $GLOBALS[$class]->code,

'title' => $GLOBALS[$class]->output[$i]['title'],

'text' => $GLOBALS[$class]->output[$i]['text'],

'value' => $GLOBALS[$class]->output[$i]['value'],

'sort_order' => $GLOBALS[$class]->sort_order);

}

}

}

}

}

 

$sql_data_array = array('customers_id' => $customer_id,

'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'],

'customers_company' => $order->customer['company'],

'customers_street_address' => $order->customer['street_address'],

'customers_suburb' => $order->customer['suburb'],

'customers_city' => $order->customer['city'],

'customers_postcode' => $order->customer['postcode'],

'customers_state' => $order->customer['state'],

'customers_country' => $order->customer['country']['title'],

'customers_telephone' => $order->customer['telephone'],

'customers_email_address' => $order->customer['email_address'],

'customers_address_format_id' => $order->customer['format_id'],

'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'],

'delivery_company' => $order->delivery['company'],

'delivery_street_address' => $order->delivery['street_address'],

'delivery_suburb' => $order->delivery['suburb'],

'delivery_city' => $order->delivery['city'],

'delivery_postcode' => $order->delivery['postcode'],

'delivery_state' => $order->delivery['state'],

'delivery_country' => $order->delivery['country']['title'],

'delivery_address_format_id' => $order->delivery['format_id'],

'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'],

'billing_company' => $order->billing['company'],

'billing_street_address' => $order->billing['street_address'],

'billing_suburb' => $order->billing['suburb'],

'billing_city' => $order->billing['city'],

'billing_postcode' => $order->billing['postcode'],

'billing_state' => $order->billing['state'],

'billing_country' => $order->billing['country']['title'],

'billing_address_format_id' => $order->billing['format_id'],

'payment_method' => $order->info['payment_method'],

'cc_type' => $order->info['cc_type'],

'cc_owner' => $order->info['cc_owner'],

'cc_number' => $order->info['cc_number'],

'cc_expires' => $order->info['cc_expires'],

'date_purchased' => 'now()',

'orders_status' => $order->info['order_status'],

'currency' => $order->info['currency'],

'currency_value' => $order->info['currency_value']);

 

tep_db_perform(TABLE_ORDERS, $sql_data_array);

 

$insert_id = tep_db_insert_id();

 

for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {

$sql_data_array = array('orders_id' => $insert_id,

'title' => $order_totals[$i]['title'],

'text' => $order_totals[$i]['text'],

'value' => $order_totals[$i]['value'],

'class' => $order_totals[$i]['code'],

'sort_order' => $order_totals[$i]['sort_order']);

 

tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);

}

 

for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {

$sql_data_array = array('orders_id' => $insert_id,

'products_id' => tep_get_prid($order->products[$i]['id']),

'products_model' => $order->products[$i]['model'],

'products_name' => $order->products[$i]['name'],

'products_price' => $order->products[$i]['price'],

'final_price' => $order->products[$i]['final_price'],

'products_tax' => $order->products[$i]['tax'],

'products_quantity' => $order->products[$i]['qty']);

 

tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);

 

$order_products_id = tep_db_insert_id();

 

$attributes_exist = '0';

if (isset($order->products[$i]['attributes'])) {

$attributes_exist = '1';

for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {

if (DOWNLOAD_ENABLED == 'true') {

$attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename

from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa

left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad

on pa.products_attributes_id=pad.products_attributes_id

where pa.products_id = '" . $order->products[$i]['id'] . "'

and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'

and pa.options_id = popt.products_options_id

and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'

and pa.options_values_id = poval.products_options_values_id

and popt.language_id = '" . $languages_id . "'

and poval.language_id = '" . $languages_id . "'";

$attributes = tep_db_query($attributes_query);

} else {

$attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");

}

$attributes_values = tep_db_fetch_array($attributes);

 

$sql_data_array = array('orders_id' => $insert_id,

'orders_products_id' => $order_products_id,

'products_options' => $attributes_values['products_options_name'],

'products_options_values' => $attributes_values['products_options_values_name'],

'options_values_price' => $attributes_values['options_values_price'],

'price_prefix' => $attributes_values['price_prefix']);

 

tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array);

 

if ((DOWNLOAD_ENABLED == 'true') && isset($attributes_values['products_attributes_filename']) && tep_not_null($attributes_values['products_attributes_filename'])) {

$sql_data_array = array('orders_id' => $insert_id,

'orders_products_id' => $order_products_id,

'orders_products_filename' => $attributes_values['products_attributes_filename'],

'download_maxdays' => $attributes_values['products_attributes_maxdays'],

'download_count' => $attributes_values['products_attributes_maxcount']);

 

tep_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array);

}

}

}

}

 

tep_session_register('cart_PayPal_IPN_ID');

$cart_PayPal_IPN_ID = $cartID . '-' . $insert_id;

}

}

 

return false;

}

 

function process_button() {

global $customer_id, $order, $languages_id, $currencies, $currency, $cart_PayPal_IPN_ID, $shipping;

 

if (MODULE_PAYMENT_PAYPAL_IPN_CURRENCY == 'Selected Currency') {

$my_currency = $currency;

} else {

$my_currency = substr(MODULE_PAYMENT_PAYPAL_IPN_CURRENCY, 5);

}

if (!in_array($my_currency, array('CAD', 'EUR', 'GBP', 'JPY', 'USD'))) {

$my_currency = 'USD';

}

 

$parameters = array();

 

if ( (MODULE_PAYMENT_PAYPAL_IPN_TRANSACTION_TYPE == 'Per Item') && (MODULE_PAYMENT_PAYPAL_IPN_EWP_STATUS == 'False') ) {

$parameters['cmd'] = '_cart';

$parameters['upload'] = '1';

 

for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {

$item = $i+1;

 

$tax_value = ($order->products[$i]['tax'] / 100) * $order->products[$i]['final_price'];

 

$parameters['item_name_' . $item] = $order->products[$i]['name'];

$parameters['amount_' . $item] = number_format($order->products[$i]['final_price'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

$parameters['tax_' . $item] = number_format($tax_value * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

$parameters['quantity_' . $item] = $order->products[$i]['qty'];

 

if ($i == 0) {

if (DISPLAY_PRICE_WITH_TAX == 'true') {

$shipping_cost = $order->info['shipping_cost'];

} else {

$module = substr($shipping['id'], 0, strpos($shipping['id'], '_'));

$shipping_tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

$shipping_cost = $order->info['shipping_cost'] + tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);

}

 

$parameters['shipping_' . $item] = number_format($shipping_cost * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

}

 

if (isset($order->products[$i]['attributes'])) {

for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {

if (DOWNLOAD_ENABLED == 'true') {

$attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename

from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa

left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad

on pa.products_attributes_id=pad.products_attributes_id

where pa.products_id = '" . $order->products[$i]['id'] . "'

and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'

and pa.options_id = popt.products_options_id

and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'

and pa.options_values_id = poval.products_options_values_id

and popt.language_id = '" . $languages_id . "'

and poval.language_id = '" . $languages_id . "'";

$attributes = tep_db_query($attributes_query);

} else {

$attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");

}

$attributes_values = tep_db_fetch_array($attributes);

 

// Unfortunately PayPal only accepts two attributes per product, so the

// third attribute onwards will not be shown at PayPal

$parameters['on' . $j . '_' . $item] = $attributes_values['products_options_name'];

$parameters['os' . $j . '_' . $item] = $attributes_values['products_options_values_name'];

}

}

}

 

$parameters['num_cart_items'] = $item;

} else {

$parameters['cmd'] = '_xclick';

$parameters['item_name'] = STORE_NAME;

$parameters['shipping'] = number_format($order->info['shipping_cost'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

$parameters['tax'] = number_format($order->info['tax'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

}

 

$parameters['business'] = MODULE_PAYMENT_PAYPAL_IPN_ID;

$parameters['amount'] = number_format(($order->info['total'] - $order->info['shipping_cost'] - $order->info['tax']) * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

$parameters['currency_code'] = $my_currency;

$parameters['invoice'] = substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1);

$parameters['custom'] = $customer_id;

$parameters['no_shipping'] = '1';

$parameters['no_note'] = '1';

$parameters['notify_url'] = tep_href_link('ext/modules/payment/paypal_ipn/ipn.php', '', 'SSL', false, false);

$parameters['return'] = tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL');

$parameters['cancel_return'] = tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL');

$parameters['bn'] = $this->identifier;

 

if (tep_not_null(MODULE_PAYMENT_PAYPAL_IPN_PAGE_STYLE)) {

$parameters['page_style'] = MODULE_PAYMENT_PAYPAL_IPN_PAGE_STYLE;

}

 

if (MODULE_PAYMENT_PAYPAL_IPN_EWP_STATUS == 'True') {

$parameters['cert_id'] = MODULE_PAYMENT_PAYPAL_IPN_EWP_CERT_ID;

 

$random_string = rand(100000, 999999) . '-' . $customer_id . '-';

 

$data = '';

while (list($key, $value) = each($parameters)) {

$data .= $key . '=' . $value . "\n";

}

 

$fp = fopen(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt', 'w');

fwrite($fp, $data);

fclose($fp);

 

unset($data);

 

if (function_exists('openssl_pkcs7_sign') && function_exists('openssl_pkcs7_encrypt')) {

openssl_pkcs7_sign(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt', MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt', file_get_contents(MODULE_PAYMENT_PAYPAL_IPN_EWP_PUBLIC_KEY), file_get_contents(MODULE_PAYMENT_PAYPAL_IPN_EWP_PRIVATE_KEY), array('From' => MODULE_PAYMENT_PAYPAL_IPN_ID), PKCS7_BINARY);

 

unlink(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt');

 

// remove headers from the signature

$signed = file_get_contents(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt');

$signed = explode("\n\n", $signed);

$signed = base64_decode($signed[1]);

 

$fp = fopen(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt', 'w');

fwrite($fp, $signed);

fclose($fp);

 

unset($signed);

 

openssl_pkcs7_encrypt(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt', MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt', file_get_contents(MODULE_PAYMENT_PAYPAL_IPN_EWP_PAYPAL_KEY), array('From' => MODULE_PAYMENT_PAYPAL_IPN_ID), PKCS7_BINARY);

 

unlink(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt');

 

// remove headers from the encrypted result

$data = file_get_contents(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt');

$data = explode("\n\n", $data);

$data = '-----BEGIN PKCS7-----' . "\n" . $data[1] . "\n" . '-----END PKCS7-----';

 

unlink(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt');

} else {

exec(MODULE_PAYMENT_PAYPAL_IPN_EWP_OPENSSL . ' smime -sign -in ' . MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt -signer ' . MODULE_PAYMENT_PAYPAL_IPN_EWP_PUBLIC_KEY . ' -inkey ' . MODULE_PAYMENT_PAYPAL_IPN_EWP_PRIVATE_KEY . ' -outform der -nodetach -binary > ' . MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt');

unlink(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt');

 

exec(MODULE_PAYMENT_PAYPAL_IPN_EWP_OPENSSL . ' smime -encrypt -des3 -binary -outform pem ' . MODULE_PAYMENT_PAYPAL_IPN_EWP_PAYPAL_KEY . ' < ' . MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt > ' . MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt');

unlink(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt');

 

$fh = fopen(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt', 'rb');

$data = fread($fh, filesize(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt'));

fclose($fh);

 

unlink(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt');

}

 

$process_button_string = tep_draw_hidden_field('cmd', '_s-xclick') .

tep_draw_hidden_field('encrypted', $data);

 

unset($data);

} else {

while (list($key, $value) = each($parameters)) {

echo tep_draw_hidden_field($key, $value);

}

}

 

return $process_button_string;

}

 

function before_process() {

global $customer_id, $order, $sendto, $billto, $payment, $currencies, $cart, $cart_PayPal_IPN_ID;

global $$payment;

 

include(DIR_WS_CLASSES . 'order_total.php');

$order_total_modules = new order_total;

 

$order_totals = $order_total_modules->process();

 

$order_id = substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1);

 

$sql_data_array = array('orders_id' => $order_id,

'orders_status_id' => $order->info['order_status'],

'date_added' => 'now()',

'customer_notified' => (SEND_EMAILS == 'true') ? '1' : '0',

'comments' => $order->info['comments'

Link to comment
Share on other sites

Instead of posting a whole page of code, how about going through the read me file?

 

Known issues

* If a customer does not return to the site, stock quantities are not updated, no order emails are generated and the customer's basket is not emptied. However, unlike with the standard PayPal module, the shop administrator does have a record of the order.

 

Terra

My code for combining PayPal IPN with ** QTPro 4.25 ** osC Affiliate ** CCGV(trad)

and how to solve the invoice already paid error

General info: Allow customer to delete order comment ** FTP Programs & Text Editors ** Amending order email **

Link to comment
Share on other sites

one question here. I posted it in the CCGV thread (because that IS where it belongs) but I'll post it here as well because it directly affects the paypal IPN mod (no other mod). Essentially if a person uses the remainder of a gift voucher when they checkout at paypal, but then doesn't return to the site afterwards (for checkout process), the voucher is never deducted from their total. does anyone have a fix around this already? I have a few ideas (basically moving apply_credit() to ipn.php and passing some variables in the custom variable of the IPN API) but don't want to reinvent the wheel if I don't have to.

Link to comment
Share on other sites

:D Hello

 

setting up my store on a current version of "OSC" and have down load the current version of "oscommerce PayPal IPN V 1.3

Also read the install instructions and it has raised a few points, that I am sure are fairly straight forward.

 

The install says to , "Note: Be sure to also copy the new "ext" directory to the catalog root directory"

This is inside the new "catalog" folder in the download. I am assuming they do not mean to say take the "EXT" folder out of the catalog folder and place it in the root, (I am on a hosted service).

 

Also my "catalog" is now called "shop", if I rename this contribution folder to suit mine. Will I have to rename any other parts of the files.

 

And when it mentions, to delete the existing "PayPal" module from the admin, what is the prescribed method. As the modules section only lists "install", do I have to do it through the files section or go through "FTP" and remove the required sections.

 

Thanks for looking

 

Dave

 

:thumbsup:

Edited by Jaguars
Link to comment
Share on other sites

Also my "catalog" is now called "shop", if I rename this contribution folder to suit mine. Will I have to rename any other parts of the files. And when it mentions, to delete the existing "PayPal" module from the admin, what is the prescribed method. As the modules section only lists "install", do I have to do it through the files section or go through "FTP" and remove the required sections.

Dave - if your shop is in a folder called /shop/, then you just need to copy the /ext/... in there as in /shop/ext/..... No need to rename anything - it just needs to be at the right level. No code changes needed.

 

The terms installing & uninstalling refer to your admin area - when you go to a payment module, you have install / uninstall buttons. No neeed to delete any files. Just have a look under modules / payment and click on a module to see the buttons.

 

Terra

Edited by Terra

My code for combining PayPal IPN with ** QTPro 4.25 ** osC Affiliate ** CCGV(trad)

and how to solve the invoice already paid error

General info: Allow customer to delete order comment ** FTP Programs & Text Editors ** Amending order email **

Link to comment
Share on other sites

Dave - if your shop is in a folder called /shop/, then you just need to copy the /ext/... in there as in /shop/ext/..... No need to rename anything - it just needs to be at the right level. No code changes needed.

 

The terms installing & uninstalling refer to your admin area - when you go to a payment module, you have install / uninstall buttons. No neeed to delete any files. Just have a look under modules / payment and click on a module to see the buttons.

 

Terra

Hi Terra :D

 

thanks for the reply. So from what you have said I just copy the "EXT" file to the server and then run the install from the admin panel.

No need to upload the other parts of the folder for the PayPal IPN V 1.3, just the "EXT" file. Sorry to be a bit of a pain just want to get it right.

 

Regards

 

Dave

 

:thumbsup:

Link to comment
Share on other sites

Hi Terra :D

 

thanks for the reply. So from what you have said I just copy the "EXT" file to the server and then run the install from the admin panel.

No need to upload the other parts of the folder for the PayPal IPN V 1.3, just the "EXT" file. Sorry to be a bit of a pain just want to get it right.

Dave,

Terra's reply covered installation of the /ext/ folder. You still have to put the other parts of the module in their respective folders. Then you can click the Install button on PayPal IPN in Admin -> Modules -> Payment.

 

If the standard PayPal module has an Install button, it isn't installed, so no further action is necessary. If it has an Uninstall button, click it.

 

--Glen

Link to comment
Share on other sites

Dave,

Terra's reply covered installation of the /ext/ folder. You still have to put the other parts of the module in their respective folders. Then you can click the Install button on PayPal IPN in Admin -> Modules -> Payment.

 

If the standard PayPal module has an Install button, it isn't installed, so no further action is necessary. If it has an Uninstall button, click it.

 

--Glen

 

Hello Glen

 

thanks for the reply. I was just a bit off there and that has cleared that part for me.

 

So if I now rename the catalog folder to "shop" and upload all of the contribution folder to my site I can then just click "Install" and follow the required prompts.

 

Hope I have understood this, I do have an existing "PayPal" account.

 

Many Thanks

 

Dave

 

:thumbsup:

Link to comment
Share on other sites

Hello Glen

 

thanks for the reply. I was just a bit off there and that has cleared that part for me.

 

So if I now rename the catalog folder to "shop" and upload all of the contribution folder to my site I can then just click "Install" and follow the required prompts.

Assuming that your FTP tool adds the contents of the "shop" folder to your server and creates new folders where necessary, without deleting anything that is already there, you can do this. Otherwise, just copy the files to the correct folders. There are only three files in the contribution, so I just drag them to the appropriate places. Of course, the /ext/ folder structure has to be replicated. Since that probably isn't on your server to begin with, you should be able to upload that in one step.

 

Once you click "install", you won't get prompts. You will be able to edit the settings on the payment module. Follow the instructions from Terra's install_guide_READ_ME.html file.

Link to comment
Share on other sites

Assuming that your FTP tool adds the contents of the "shop" folder to your server and creates new folders where necessary, without deleting anything that is already there, you can do this. Otherwise, just copy the files to the correct folders. There are only three files in the contribution, so I just drag them to the appropriate places. Of course, the /ext/ folder structure has to be replicated. Since that probably isn't on your server to begin with, you should be able to upload that in one step.

 

Once you click "install", you won't get prompts. You will be able to edit the settings on the payment module. Follow the instructions from Terra's install_guide_READ_ME.html file.

 

Hello Glen

 

I went the route of uploading each file from their respective folders, to the same position upon the server.

Using "Filezilla"

 

Clicked install and wham, it is there.

 

Did the basic bits from the Read Me html, just now have to open the test account, then check my actual account and finally get the "SSL" loaded on the server.

 

Thanks again, I may have gone over things twice but wanted to be careful, as it is to do with Money.

 

Regards

 

Dave

 

:thumbsup:

Link to comment
Share on other sites

I posted this in error in the wrong place yesterday apologies to all :blush:

 

As a newbie to osCommerce, can you help ??

 

The install is 2.2ms2-051113, on Linux with Apache and MySQL 5

 

I think I have installed osCommerce PayPal IPN v1.3 OK according to the instructions ......... been trying for two days ... 3days now.:blink:

 

But I cannot get any contact with Paypal.. I have an account with the PayPal Sandbox set-up but no SSL certificates etc, all is just left open at the moment for testing.

The only password protection is on the /catalog//admin area......... and /catalog/ext/modules/payment/paypaypal_ipn/ipn.php shows a blank screen with no request for a password as I have seen elsewhere in this forum ??

 

The module shows in the Admin panel and I can set-up the options OK, but in the shop, no payment option shows when I try to go to the check-out process.

 

After two days I am sure I must have missed something stupid or made a typo.

 

All ideas appreciated.

 

TIA

Link to comment
Share on other sites

I posted this in error in the wrong place yesterday apologies to all :blush:

 

As a newbie to osCommerce, can you help ??

 

The install is 2.2ms2-051113, on Linux with Apache and MySQL 5

 

I think I have installed osCommerce PayPal IPN v1.3 OK according to the instructions ......... been trying for two days ... 3days now.:blink:

 

But I cannot get any contact with Paypal.. I have an account with the PayPal Sandbox set-up but no SSL certificates etc, all is just left open at the moment for testing.

The only password protection is on the /catalog//admin area......... and /catalog/ext/modules/payment/paypaypal_ipn/ipn.php shows a blank screen with no request for a password as I have seen elsewhere in this forum ??

You shouldn't be accessing ipn.php yourself. It is the page that PayPal uses to tell osC that the transaction was completed.

 

The module shows in the Admin panel and I can set-up the options OK, but in the shop, no payment option shows when I try to go to the check-out process.

 

If the module shows up in Admin, it is installed. The first option is whether to enable the payment method for checkout. Is it set to "True"? What is the setting for Payment Zone? It should be "--none--" unless you want to restrict the use of PayPal to certain countries.

Link to comment
Share on other sites

Hi, I've just installed this contribution and when I make the changes to the paypal_ipn.php file with the help file for QTPro (I have the latest v4.25 installed), an odd thing happens. On my admin panel > Modules > Payment, the right side of the page disappears (the section that allows you to install, update or remove, etc.). It just disappears from the page. When I use the orignial paypal.ipn file without modifications, that section is there, but gone when I modify with QTPro changes. Here is my paypal_ipn.php code:

 

<?php

/*

$Id: paypal_ipn.php,v 1.3.0.0 2006/06/22 19:29:00 Edith Karnitsch Exp $

 

Copyright (c) 2004 osCommerce

Released under the GNU General Public License

 

Original Authors: Harald Ponce de Leon, Mark Evans

Updated by Edith Karnitsch (Terra) with help from PandA.nl, Navyhost and Zoeticlight

 

*/

 

class paypal_ipn {

var $code, $title, $description, $enabled, $identifier;

 

// class constructor

function paypal_ipn() {

global $order;

 

$this->code = 'paypal_ipn';

$this->title = MODULE_PAYMENT_PAYPAL_IPN_TEXT_TITLE;

$this->description = MODULE_PAYMENT_PAYPAL_IPN_TEXT_DESCRIPTION;

$this->sort_order = MODULE_PAYMENT_PAYPAL_IPN_SORT_ORDER;

$this->enabled = ((MODULE_PAYMENT_PAYPAL_IPN_STATUS == 'True') ? true : false);

$this->identifier = 'osCommerce PayPal IPN v1.0';

 

if ((int)MODULE_PAYMENT_PAYPAL_IPN_PREPARE_ORDER_STATUS_ID > 0) {

$this->order_status = MODULE_PAYMENT_PAYPAL_IPN_PREPARE_ORDER_STATUS_ID;

}

 

if (is_object($order)) $this->update_status();

 

if (MODULE_PAYMENT_PAYPAL_IPN_GATEWAY_SERVER == 'Live') {

$this->form_action_url = 'https://www.paypal.com/cgi-bin/webscr';

} else {

$this->form_action_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';

}

}

 

// class methods

function update_status() {

global $order;

 

if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PAYPAL_IPN_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_IPN_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 $cartID, $cart_PayPal_IPN_ID, $customer_id, $languages_id, $order, $order_total_modules;

 

// if (tep_session_is_registered('cartID')) {

// PandA.nl: register_globals fix

if (array_key_exists('cartID', $_SESSION)) {

$insert_order = false;

 

if (tep_session_is_registered('cart_PayPal_IPN_ID')) {

$order_id = substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1);

 

$curr_check = tep_db_query("select currency from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");

$curr = tep_db_fetch_array($curr_check);

 

if ( ($curr['currency'] != $order->info['currency']) || ($cartID != substr($cart_PayPal_IPN_ID, 0, strlen($cartID))) ) {

$check_query = tep_db_query('select orders_id from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '" limit 1');

 

if (tep_db_num_rows($check_query) < 1) {

tep_db_query('delete from ' . TABLE_ORDERS . ' where orders_id = "' . (int)$order_id . '"');

tep_db_query('delete from ' . TABLE_ORDERS_TOTAL . ' where orders_id = "' . (int)$order_id . '"');

tep_db_query('delete from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '"');

tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS . ' where orders_id = "' . (int)$order_id . '"');

tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . ' where orders_id = "' . (int)$order_id . '"');

tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_DOWNLOAD . ' where orders_id = "' . (int)$order_id . '"');

}

 

$insert_order = true;

}

} else {

$insert_order = true;

}

 

if ($insert_order == true) {

$order_totals = array();

if (is_array($order_total_modules->modules)) {

reset($order_total_modules->modules);

while (list(, $value) = each($order_total_modules->modules)) {

$class = substr($value, 0, strrpos($value, '.'));

if ($GLOBALS[$class]->enabled) {

for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {

if (tep_not_null($GLOBALS[$class]->output[$i]['title']) && tep_not_null($GLOBALS[$class]->output[$i]['text'])) {

$order_totals[] = array('code' => $GLOBALS[$class]->code,

'title' => $GLOBALS[$class]->output[$i]['title'],

'text' => $GLOBALS[$class]->output[$i]['text'],

'value' => $GLOBALS[$class]->output[$i]['value'],

'sort_order' => $GLOBALS[$class]->sort_order);

}

}

}

}

}

 

$sql_data_array = array('customers_id' => $customer_id,

'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'],

'customers_company' => $order->customer['company'],

'customers_street_address' => $order->customer['street_address'],

'customers_suburb' => $order->customer['suburb'],

'customers_city' => $order->customer['city'],

'customers_postcode' => $order->customer['postcode'],

'customers_state' => $order->customer['state'],

'customers_country' => $order->customer['country']['title'],

'customers_telephone' => $order->customer['telephone'],

'customers_email_address' => $order->customer['email_address'],

'customers_address_format_id' => $order->customer['format_id'],

'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'],

'delivery_company' => $order->delivery['company'],

'delivery_street_address' => $order->delivery['street_address'],

'delivery_suburb' => $order->delivery['suburb'],

'delivery_city' => $order->delivery['city'],

'delivery_postcode' => $order->delivery['postcode'],

'delivery_state' => $order->delivery['state'],

'delivery_country' => $order->delivery['country']['title'],

'delivery_address_format_id' => $order->delivery['format_id'],

'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'],

'billing_company' => $order->billing['company'],

'billing_street_address' => $order->billing['street_address'],

'billing_suburb' => $order->billing['suburb'],

'billing_city' => $order->billing['city'],

'billing_postcode' => $order->billing['postcode'],

'billing_state' => $order->billing['state'],

'billing_country' => $order->billing['country']['title'],

'billing_address_format_id' => $order->billing['format_id'],

'payment_method' => $order->info['payment_method'],

'cc_type' => $order->info['cc_type'],

'cc_owner' => $order->info['cc_owner'],

'cc_number' => $order->info['cc_number'],

'cc_expires' => $order->info['cc_expires'],

'date_purchased' => 'now()',

'orders_status' => $order->info['order_status'],

'currency' => $order->info['currency'],

'currency_value' => $order->info['currency_value']);

 

tep_db_perform(TABLE_ORDERS, $sql_data_array);

 

$insert_id = tep_db_insert_id();

 

for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {

$sql_data_array = array('orders_id' => $insert_id,

'title' => $order_totals[$i]['title'],

'text' => $order_totals[$i]['text'],

'value' => $order_totals[$i]['value'],

'class' => $order_totals[$i]['code'],

'sort_order' => $order_totals[$i]['sort_order']);

 

tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);

}

 

//++++ QT Pro: Begin Changed code

for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {

$products_stock_attributes=null;

if (STOCK_LIMITED == 'true') {

$products_attributes = $order->products[$i]['attributes'];

 

$stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename

FROM " . TABLE_PRODUCTS . " p

LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa

ON p.products_id=pa.products_id

LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad

ON pa.products_attributes_id=pad.products_attributes_id

WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";

 

 

if (is_array($products_attributes)) {

$stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";

}

$stock_query = tep_db_query($stock_query_raw);

if (tep_db_num_rows($stock_query) > 0) {

$stock_values = tep_db_fetch_array($stock_query);

 

$actual_stock_bought = $order->products[$i]['qty'];

$download_selected = false;

if ((DOWNLOAD_ENABLED == 'true') && isset($stock_values['products_attributes_filename']) && tep_not_null($stock_values['products_attributes_filename'])) {

$download_selected = true;

$products_stock_attributes='$$DOWNLOAD$$';

}

// If not downloadable and attributes present, adjust attribute stock

if (!$download_selected && is_array($products_attributes)) {

$all_nonstocked = true;

$products_stock_attributes_array = array();

foreach ($products_attributes as $attribute) {

$products_stock_attributes_array[] = $attribute['option_id'] . "-" . $attribute['value_id'];

 

asort($products_stock_attributes_array, SORT_NUMERIC);

$products_stock_attributes = implode(",", $products_stock_attributes_array);

}

}

}

} else {

if ( is_array($order->products[$i]['attributes']) ) {

$products_stock_attributes_array = array();

foreach ($order->products[$i]['attributes'] as $attribute) {

$products_stock_attributes_array[] = $attribute['option_id'] . "-" . $attribute['value_id'];

}

asort($products_stock_attributes_array, SORT_NUMERIC);

$products_stock_attributes = implode(",", $products_stock_attributes_array);

}

}

 

if (!isset($products_stock_attributes)) $products_stock_attributes=null;

$sql_data_array = array('orders_id' => $insert_id,

'products_id' => tep_get_prid($order->products[$i]['id']),

'products_model' => $order->products[$i]['model'],

'products_name' => $order->products[$i]['name'],

'products_price' => $order->products[$i]['price'],

'final_price' => $order->products[$i]['final_price'],

'products_tax' => $order->products[$i]['tax'],

'products_quantity' => $order->products[$i]['qty'],

'products_stock_attributes' => $products_stock_attributes);

//++++ QT Pro: End Changed Code

 

tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);

 

$order_products_id = tep_db_insert_id();

 

$attributes_exist = '0';

if (isset($order->products[$i]['attributes'])) {

$attributes_exist = '1';

for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {

if (DOWNLOAD_ENABLED == 'true') {

$attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename

from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa

left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad

on pa.products_attributes_id=pad.products_attributes_id

where pa.products_id = '" . $order->products[$i]['id'] . "'

and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'

and pa.options_id = popt.products_options_id

and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'

and pa.options_values_id = poval.products_options_values_id

and popt.language_id = '" . $languages_id . "'

and poval.language_id = '" . $languages_id . "'";

$attributes = tep_db_query($attributes_query);

} else {

$attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");

}

$attributes_values = tep_db_fetch_array($attributes);

 

$sql_data_array = array('orders_id' => $insert_id,

'orders_products_id' => $order_products_id,

'products_options' => $attributes_values['products_options_name'],

'products_options_values' => $attributes_values['products_options_values_name'],

'options_values_price' => $attributes_values['options_values_price'],

'price_prefix' => $attributes_values['price_prefix']);

 

tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array);

 

if ((DOWNLOAD_ENABLED == 'true') && isset($attributes_values['products_attributes_filename']) && tep_not_null($attributes_values['products_attributes_filename'])) {

$sql_data_array = array('orders_id' => $insert_id,

'orders_products_id' => $order_products_id,

'orders_products_filename' => $attributes_values['products_attributes_filename'],

'download_maxdays' => $attributes_values['products_attributes_maxdays'],

'download_count' => $attributes_values['products_attributes_maxcount']);

 

tep_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array);

}

}

}

}

 

tep_session_register('cart_PayPal_IPN_ID');

// Terra register globals fix

$_SESSION['cart_PayPal_IPN_ID'] = $cartID . '-' . $insert_id;

}

}

 

return false;

}

 

function process_button() {

global $customer_id, $order, $languages_id, $currencies, $currency, $cart_PayPal_IPN_ID, $shipping;

 

if (MODULE_PAYMENT_PAYPAL_IPN_CURRENCY == 'Selected Currency') {

$my_currency = $currency;

} else {

$my_currency = substr(MODULE_PAYMENT_PAYPAL_IPN_CURRENCY, 5);

}

if (!in_array($my_currency, array('AUD', 'CAD', 'EUR', 'GBP', 'JPY', 'USD'))) {

$my_currency = 'USD';

}

 

$parameters = array();

 

if ( (MODULE_PAYMENT_PAYPAL_IPN_TRANSACTION_TYPE == 'Per Item') && (MODULE_PAYMENT_PAYPAL_IPN_EWP_STATUS == 'False') ) {

$parameters['cmd'] = '_cart';

$parameters['upload'] = '1';

 

for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {

$item = $i+1;

 

$tax_value = ($order->products[$i]['tax'] / 100) * $order->products[$i]['final_price'];

 

$parameters['item_name_' . $item] = $order->products[$i]['name'];

$parameters['amount_' . $item] = number_format($order->products[$i]['final_price'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

$parameters['tax_' . $item] = number_format($tax_value * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

$parameters['quantity_' . $item] = $order->products[$i]['qty'];

 

if ($i == 0) {

if (DISPLAY_PRICE_WITH_TAX == 'true') {

$shipping_cost = $order->info['shipping_cost'];

} else {

$module = substr($shipping['id'], 0, strpos($shipping['id'], '_'));

$shipping_tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

$shipping_cost = $order->info['shipping_cost'] + tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);

}

 

$parameters['shipping_' . $item] = number_format($shipping_cost * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

}

 

if (isset($order->products[$i]['attributes'])) {

for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {

if (DOWNLOAD_ENABLED == 'true') {

$attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename

from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa

left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad

on pa.products_attributes_id=pad.products_attributes_id

where pa.products_id = '" . $order->products[$i]['id'] . "'

and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'

and pa.options_id = popt.products_options_id

and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'

and pa.options_values_id = poval.products_options_values_id

and popt.language_id = '" . $languages_id . "'

and poval.language_id = '" . $languages_id . "'";

$attributes = tep_db_query($attributes_query);

} else {

$attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");

}

$attributes_values = tep_db_fetch_array($attributes);

 

// Unfortunately PayPal only accepts two attributes per product, so the

// third attribute onwards will not be shown at PayPal

$parameters['on' . $j . '_' . $item] = $attributes_values['products_options_name'];

$parameters['os' . $j . '_' . $item] = $attributes_values['products_options_values_name'];

}

}

}

 

$parameters['num_cart_items'] = $item;

} else {

$parameters['cmd'] = '_xclick';

$parameters['item_name'] = STORE_NAME;

$parameters['shipping'] = number_format($order->info['shipping_cost'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

if(MOVE_TAX_TO_TOTAL_AMOUNT == 'True') {

// PandA.nl move tax to total amount

$parameters['tax'] = 0;

} else {

// default

$parameters['tax'] = number_format($order->info['tax'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

}

}

 

$parameters['business'] = MODULE_PAYMENT_PAYPAL_IPN_ID;

if(MOVE_TAX_TO_TOTAL_AMOUNT == 'True') {

// PandA.nl move tax to total amount

$parameters['amount'] = number_format(($order->info['total'] - $order->info['shipping_cost']) * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

} else {

// default

$parameters['amount'] = number_format(($order->info['total'] - $order->info['shipping_cost'] - $order->info['tax']) * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));

}

$parameters['currency_code'] = $my_currency;

$parameters['invoice'] = substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-')+1);

$parameters['custom'] = $customer_id;

$parameters['no_shipping'] = '1';

$parameters['no_note'] = '1';

$parameters['notify_url'] = tep_href_link('ext/modules/payment/paypal_ipn/ipn.php', '', 'SSL', false, false);

$parameters['cbt'] = CONFIRMATION_BUTTON_TEXT;

$parameters['return'] = tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL');

$parameters['cancel_return'] = tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL');

$parameters['bn'] = $this->identifier;

 

if (tep_not_null(MODULE_PAYMENT_PAYPAL_IPN_PAGE_STYLE)) {

$parameters['page_style'] = MODULE_PAYMENT_PAYPAL_IPN_PAGE_STYLE;

}

 

if (MODULE_PAYMENT_PAYPAL_IPN_EWP_STATUS == 'True') {

$parameters['cert_id'] = MODULE_PAYMENT_PAYPAL_IPN_EWP_CERT_ID;

 

$random_string = rand(100000, 999999) . '-' . $customer_id . '-';

 

$data = '';

while (list($key, $value) = each($parameters)) {

$data .= $key . '=' . $value . "\n";

}

 

$fp = fopen(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt', 'w');

fwrite($fp, $data);

fclose($fp);

 

un

Link to comment
Share on other sites

You shouldn't be accessing ipn.php yourself. It is the page that PayPal uses to tell osC that the transaction was completed.

If the module shows up in Admin, it is installed. The first option is whether to enable the payment method for checkout. Is it set to "True"? What is the setting for Payment Zone? It should be "--none--" unless you want to restrict the use of PayPal to certain countries.

 

Thanks for the reply.

 

First I tried to get at ipn.php to make sure there was no password protection set... as seen in other parts of this forum.

 

Second Paypal IPN was enabled

 

Third Pyment Zone is set up to UK Only I have not tried it set at -none- as I wanted to force use of GBP only.

 

Regards

Link to comment
Share on other sites

any thoughts by anyone on moving the before_process() inventory reduction/order management/etc stuff to the ipn.php file as opposed to the paypal_ipn.php file? Would really like some input on this. at the very least, does anyone have practical information on the typical time it takes paypal to send out the ipn notification? are a few seconds typical? a few minutes? is it possible for it to go to hours and/or days in some instances? things I am wondering most about are people that use a bank account linked to paypal where paypal holds the funds. does the ipn still go through immediately? paypal is definitely something I want to offer, but this is a pretty big hole involving gift vouchers and coupon codes with a per customer limit. any thoughts?

Link to comment
Share on other sites

firstly thank you for this great contribution!

 

I have managed to setup and configure the paypal_ipn module with no problems, and its working great.

 

however in my control panel whenever a order is sent through and I view it in in the orders list. it displays some weird codes and the footer is moved directly under the order box....

 

and also when I try to view the invoice, the formatting is all weird...

 

This only happens when a customer checks out with paypal. So it has to be one of the files from the module that needs attention.

 

I'm thinking somewhere Im missing a /TD.... somewhere or forogot to close a quote..

 

Can Anyone Help please?

 

I have attached some screen shots

screen1.jpg

screen2.jpg

Link to comment
Share on other sites

any thoughts by anyone on moving the before_process() inventory reduction/order management/etc stuff to the ipn.php file as opposed to the paypal_ipn.php file? Would really like some input on this. at the very least, does anyone have practical information on the typical time it takes paypal to send out the ipn notification? are a few seconds typical? a few minutes? is it possible for it to go to hours and/or days in some instances? things I am wondering most about are people that use a bank account linked to paypal where paypal holds the funds. does the ipn still go through immediately? paypal is definitely something I want to offer, but this is a pretty big hole involving gift vouchers and coupon codes with a per customer limit. any thoughts?

The IPN goes through pretty much immediately. On e-check transactions, you get a "pending" IPN immediately, and a second IPN when the transaction clears. The history will look something like this:

 

06/13/2006 17:21:26 Pending PayPal IPN Verified [Pending (Verified; $16.05); echeck]

06/16/2006 08:34:26 Pending PayPal IPN Verified [Completed (Verified; $16.05)]

 

This might happen because I have PayPal point to the ipn.php file, as directed in older versions of this contribution; I have not tested it since I upgraded to 1.3, and I haven't gotten around to turning off the default IPN destination.

 

I seem to recall finding a contribution that will put the PayPal payment status into the order status column of the order list, so that it is obvious that the funds haven't cleared yet. I don't get that many e-check transactions, so it hasn't been an issue for me.

 

--Glen

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...