Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Paypal Standard in OSC 2.31 - Convert to Itemized Cart?


varina

Recommended Posts

I currently have Paypal Standard installed in my OSC 2.3.1 store.

I would like to integrate the Itemized cart from the old Paypal that I had with OSC .2.2

 

It had the option for itemized and aggregate cart.

 

I tried this fix:

 

http://addons.oscommerce.com/info/6783

 

But it did not work for me, all I got was one item name in the invoice and the same quantity of one, and the total price...

 

Looking at the code in my old paypal.php file, it seems it could be added to the new paypal_standard.php file with a little bit of updating for the new code format.

 

Unfortunately I am not a PHP programmer, and so far the conversions I have tried have just sent me to the paypal website when I click confirm instead of coming up with an invoice.

 

I was hoping someone could help me figure out how to make the code work.

 

Old Code from paypal.php

 

function formFields($txn_sign = '', $payment_amount = '', $payment_currency = '', $payment_currency_value = '', $orders_id = '', $return_url = '', $cancel_url = '' ) {
  global $order, $currencies;
  $my_currency = (!empty($payment_currency)) ? $payment_currency : $this->currency();
  $my_currency_value = (!empty($payment_currency_value)) ? $payment_currency_value : $currencies->get_value($my_currency);
  //Merchant Info
  $paypal_fields = tep_draw_hidden_field('business', MODULE_PAYMENT_PAYPAL_BUSINESS_ID);
  //Currency
  $paypal_fields .= tep_draw_hidden_field('currency_code', $my_currency);
  //Shopping Cart Info
  if(MODULE_PAYMENT_PAYPAL_METHOD == 'Itemized') {
    $paypal_fields .= tep_draw_hidden_field('upload', sizeof($order->products)) .
    tep_draw_hidden_field('redirect_cmd', '_cart') .
    tep_draw_hidden_field('handling_cart', number_format($order->info['shipping_cost'] * $my_currency_value, $currencies->get_decimal_places($my_currency)));
    //Itemized Order Details
    for ($i=0,$index=1; $i<sizeof($order->products); $i++, $index++) {
	  //$index = $i+1;
	  $paypal_fields .= tep_draw_hidden_field('item_name_'.$index, $order->products[$i]['name']).
	  tep_draw_hidden_field('item_number_'.$index, $order->products[$i]['model']).
	  tep_draw_hidden_field('quantity_'.$index, $order->products[$i]['qty']).
	  tep_draw_hidden_field('amount_'.$index, number_format($order->products[$i]['final_price']* $my_currency_value,2));
	  $tax = ($order->products[$i]['final_price'] * ($order->products[$i]['tax'] / 100)) * $my_currency_value;
	  $paypal_fields .= tep_draw_hidden_field('tax_'.$index, number_format($tax, 2));
	  //Customer Specified Product Options: PayPal Max = 2
	  if ($order->products[$i]['attributes']) {
	    //$n = sizeof($order->products[$i]['attributes']);
	    for ($j=0; $j<2; $j++) {
		  if($order->products[$i]['attributes'][$j]['option']){
		    $paypal_fields .= $this->optionSetFields($j,$index,$order->products[$i]['attributes'][$j]['option'],$order->products[$i]['attributes'][$j]['value']);
		  } else {
		    $paypal_fields .= $this->optionSetFields($j,$index);
		  }
	    }
	  } else {
	    for ($j=0; $j<2; $j++) {
		  $paypal_fields .= $this->optionSetFields($j,$index);
	    }
	  }
    }
  } else { //Aggregate Cart (Method 1)
    $paypal_fields .= tep_draw_hidden_field('item_name', STORE_NAME) .
    tep_draw_hidden_field('redirect_cmd', '_xclick') .
    tep_draw_hidden_field('amount', !empty($payment_amount) ? $payment_amount : $this->amount($my_currency)) .
    tep_draw_hidden_field('shipping', number_format($order->info['shipping_cost'] * $my_currency_value, $currencies->get_decimal_places($my_currency)));
    $item_number = '';
    for ($i=0; $i<sizeof($order->products); $i++) $item_number .= ' '.$order->products[$i]['name'].' ,';
    $item_number = substr_replace($item_number,'',-2);
    $paypal_fields .= tep_draw_hidden_field('item_number', $item_number);
  }

 

New code I would like to add the itemized part to:

 

function process_button() {
  global $customer_id, $order, $sendto, $currency, $cart_PayPal_Standard_ID, $shipping;
  $process_button_string = '';
  $parameters = array('cmd' => '_xclick',
					  'item_name' => STORE_NAME,
					  'shipping' => $this->format_raw($order->info['shipping_cost']),
					  'tax' => $this->format_raw($order->info['tax']),
					  'business' => MODULE_PAYMENT_PAYPAL_STANDARD_ID,
					  'amount' => $this->format_raw($order->info['total'] - $order->info['shipping_cost'] - $order->info['tax']),
					  'currency_code' => $currency,
					  'invoice' => substr($cart_PayPal_Standard_ID, strpos($cart_PayPal_Standard_ID, '-')+1),
					  'custom' => $customer_id,
					  'no_note' => '1',
					  'notify_url' => tep_href_link('ext/modules/payment/paypal/standard_ipn.php', '', 'SSL', false, false),
					  'return' => tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL'),
					  'cancel_return' => tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'),
					  'bn' => 'osCommerce22_Default_ST',
					  'paymentaction' => ((MODULE_PAYMENT_PAYPAL_STANDARD_TRANSACTION_METHOD == 'Sale') ? 'sale' : 'authorization'));

 

Everything else is working fine, I am getting my order process emails, and the customer gets sent back to my store after completing the Paypal transaction. I really don't want to have to install Paypal IPN, especially since I can't figure out which version I need, and the Standard pretty much does everything else I need.

 

Does anyone want to help me tackle this project?

Link to comment
Share on other sites

  • 3 weeks later...

Hello Chris,

 

I've been trying to deal with the same thorny problem that Varina has or had, without a great deal of success.

 

To date I found your advice to be absolutely bang on, so decided will make the jump to website payments pro.

 

On v2.3.1 the list of payment modules includes 3 for WPP, Direct Payments, Payflow Direct Payments and Payflow Express Checkout.

 

The later 2 seem to be dependant on each other being installed and the first dependant on express checkout being installed, which hopefully won't be a problem, but do both pairs give the itemized listing.

Os-commerce v2.3.3

Security Pro v11

Site Monitor

IP Trap

htaccess Protection

Bad Behaviour Block

Year Make Model

Document Manager

X Sell

Star Product

Modular Front Page

Modular Header Tags

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