kenD Posted October 27, 2003 Share Posted October 27, 2003 This is not fully complete but it works (at least for me, I have MS2). What this does is prepopulates your cart info into paypal, so when you recieve the invoice from paypal you dont just have an amount, you have the items and options listed as well, also the same as another contribution that prepopulates the signup form. Since I am not very familiar with PHP or OSC, I hope somebody can fill in the holes. Its my first contribution, so I hope sombody can use it! Problems: 1. The following will not prepopulate for the following reasons a. phone number / phone number needs to be split into 3 strings, night_phone_a, night_phone_b, night_phone_C Somebody should know how to do this...these var must only contain #'s b. email / I dont have the correct pointer for the customer email address c. State / State needs to be a 2 letter state, the pointer I am using is the full name of the state, I need to know how to get the 2 letter abbreviation. in catalog/includes/moduels/payment/paypal.php find function process_button() { global $order, $currencies, $currency; if (MODULE_PAYMENT_PAYPAL_CURRENCY == 'Selected Currency') { $my_currency = $currency; } else { $my_currency = substr(MODULE_PAYMENT_PAYPAL_CURRENCY, 5); } if (!in_array($my_currency, array('CAD', 'EUR', 'GBP', 'JPY', 'USD'))) { $my_currency = 'USD'; } $process_button_string = tep_draw_hidden_field('cmd', '_xclick') . tep_draw_hidden_field('business', MODULE_PAYMENT_PAYPAL_ID) . tep_draw_hidden_field('item_name', STORE_NAME) . tep_draw_hidden_field('amount', number_format(($order->info['total'] - $order->info['shipping_cost']) * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency))) . tep_draw_hidden_field('shipping', number_format($order->info['shipping_cost'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency))) . tep_draw_hidden_field('currency_code', $my_currency) . tep_draw_hidden_field('return', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL')) . tep_draw_hidden_field('cancel_return', tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); return $process_button_string; } and replace with function process_button() { global $order, $currencies, $currency; if (MODULE_PAYMENT_PAYPAL_CURRENCY == 'Selected Currency') { $my_currency = $currency; } else { $my_currency = substr(MODULE_PAYMENT_PAYPAL_CURRENCY, 5); } if (!in_array($my_currency, array('CAD', 'EUR', 'GBP', 'JPY', 'USD'))) { $my_currency = 'USD'; } $process_button_string = tep_draw_hidden_field('cmd', '_ext-enter') . tep_draw_hidden_field('redirect_cmd', '_cart') . tep_draw_hidden_field('cs', '1') . tep_draw_hidden_field('business', MODULE_PAYMENT_PAYPAL_ID) . tep_draw_hidden_field('item_name', STORE_NAME ) . tep_draw_hidden_field('currency_code', $my_currency) . tep_draw_hidden_field('day_phone_a', $order->customer['phone']). tep_draw_hidden_field('day_phone_b', $order->customer['phone']). tep_draw_hidden_field('day_phone_c', $order->customer['phone']). tep_draw_hidden_field('first_name', $order->billing['firstname']). tep_draw_hidden_field('last_name', $order->billing['lastname']). tep_draw_hidden_field('address1', $order->billing['street_address']). tep_draw_hidden_field('city', $order->billing['city']). tep_draw_hidden_field('state', $order->billing['state']). tep_draw_hidden_field('zip', $order->billing['postcode']). tep_draw_hidden_field('email', $order->customer['email']). tep_draw_hidden_field('lc', 'US') . tep_draw_hidden_field('rm', '2') . tep_draw_hidden_field('notify_url', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL')) . tep_draw_hidden_field('return', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL')) . tep_draw_hidden_field('cancel_return', tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')). tep_draw_hidden_field('upload', '1'); for ($loop=0; $loop<sizeof($order->products); $loop++) { $amount=0; $optionvalue=': '; $process_button_string = $process_button_string. tep_draw_hidden_field(('quantity_'.($loop+1)), ($order->products[$loop]['qty'])) . tep_draw_hidden_field(('item_name_'.($loop+1)), ($order->products[$loop]['name'])); if (sizeof($order->products[$loop]['attributes']) > 0) { for ($j=0; $j<sizeof($order->products[$loop]['attributes']); $j++) { $amount = $amount + ($order->products[$loop]['attributes'][$j]['price']); $option = $option.($order->products[$loop]['attributes'][$j]['option']).', '; $optionvalue = $optionvalue.($order->products[$loop]['attributes'][$j]['value']).', '; } } $amount = ($amount + ($order->products[$loop]['price'])); $process_button_string = $process_button_string. tep_draw_hidden_field(('amount_'.($loop+1)), number_format($amount, $currencies->get_decimal_places($my_currency))). tep_draw_hidden_field(('os0_'.($loop+1)), $optionvalue). tep_draw_hidden_field(('os0_'.($loop+1)), $option); $option = ''; $optionvalue=': '; $amount=0; } $process_button_string = $process_button_string. tep_draw_hidden_field(('item_name_'.($loop+1)), 'Shipping') . tep_draw_hidden_field(('amount_'.($loop+1)), number_format($order->info['shipping_cost'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency))); return $process_button_string; } Quote Link to comment Share on other sites More sharing options...
kenD Posted October 28, 2003 Author Share Posted October 28, 2003 typo in the bottom portion, where it says: tep_draw_hidden_field(('os0_'.($loop+1)), $optionvalue). tep_draw_hidden_field(('os0_'.($loop+1)), $option); should be: tep_draw_hidden_field(('os0_'.($loop+1)), $optionvalue). tep_draw_hidden_field(('on0_'.($loop+1)), $option); Quote Link to comment Share on other sites More sharing options...
mimages Posted October 28, 2003 Share Posted October 28, 2003 I'm a newbie myself, and don't know if I follow your post correctly. Will this code work to automatically create a paypal entry, or dooes it need fixing? I'll gladly pay for a contribution that works. Quote Link to comment Share on other sites More sharing options...
frank1002us Posted October 28, 2003 Share Posted October 28, 2003 thanks this is great i am using paypal ipn and was trying to do the same thing . i found the following code on the forums but can't get the attributes to work for me ////derek global $order, $currencies, $currency; if (MODULE_PAYMENT_PAYPALIPN_CURRENCY == 'Selected Currency') { $my_currency = $currency; } else { $my_currency = substr(MODULE_PAYMENT_PAYPALIPN_CURRENCY, 5); } if (!in_array($my_currency, array('CAD', 'EUR', 'GBP', 'JPY', 'USD'))) { $my_currency = 'USD'; } $process_button_string ='?'; for ($i=0; $i<sizeof($order->products); $i++) { $x=$i+1; $process_button_string .= 'item_name_'.$x.'='.urlencode($order->products[$i]['name']) .'&'. 'quantity_'.$x.'='.$order->products[$i]['qty'] .'&'. 'amount_'.$x.'='.$currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'],1) .'&'. 'shipping_'.$x.'='.number_format($order->info['shipping_cost'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency)).'&'; if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) { for ($j=0, $n2=1;$j<$n2; $j++) { $process_button_string .= 'on'.$j.'_'.$x.'='.urlencode($order->products[$i]['attributes'][$j]['option']) .'&'. 'os'.$j.'_'.$x.'='.$order->products[$i]['attributes'][$j]['value'] .'&'; } } } $process_button_string .= 'cmd=_cart&'. 'upload=1&'. 'business='.MODULE_PAYMENT_PAYPALIPN_ID .'&'. 'return='.tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL').'&'. 'cancel_return='.tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'). '&tax='.$paypal_ipn_tax_amount. '&first_name='.urlencode($order->customer['firstname']). '&last_name='.urlencode($order->customer['lastname']). '&address1='.urlencode($order->customer['street_address']). '&city='.urlencode($order->customer['city']). '&state='.urlencode($order->customer['state']). '&zip='.urlencode($order->customer['postcode']). '&email='.$order->customer['email_address']. '¬ify_url='.MODULE_PAYMENT_PAYPALIPN_NOTIFY_URL; ///derek //echo "$process_button_string"; tep_redirect("https://www.paypal.com/cgi-bin/webscr".$process_button_string); ?> i tried to put the loop in but getting oarse error ////derek global $order, $currencies, $currency; if (MODULE_PAYMENT_PAYPALIPN_CURRENCY == 'Selected Currency') { $my_currency = $currency; } else { $my_currency = substr(MODULE_PAYMENT_PAYPALIPN_CURRENCY, 5); } if (!in_array($my_currency, array('CAD', 'EUR', 'GBP', 'JPY', 'USD'))) { $my_currency = 'USD'; } $process_button_string ='?'; for ($i=0; $i<sizeof($order->products); $i++) { $x=$i+1; $process_button_string .= 'item_name_'.$x.'='.urlencode($order->products[$i]['name']) .'&'. 'quantity_'.$x.'='.$order->products[$i]['qty'] .'&'. 'amount_'.$x.'='.$currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'],1) .'&'. 'shipping_'.$x.'='.number_format($order->info['shipping_cost'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency)).'&'; //////////i made changes from here if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) { $option = ''; $optionvalue=': '; for ($j=0; $j<sizeof($order->products[$i]['attributes']); $j++) { $option = $option.($order->products[$loop]['attributes'][$j]['option']).', '; $optionvalue = $optionvalue.($order->products[$loop]['attributes'][$j]['value']).', '; } ////getting parse error for the next line $process_button_string .= 'on0_'.$x.'='$option.'&'. 'os0_'.$x.'='$optionvalue.'&'; } } ///////end of my changes $process_button_string .= 'cmd=_cart&'. 'upload=1&'. 'business='.MODULE_PAYMENT_PAYPALIPN_ID .'&'. 'return='.tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL').'&'. 'cancel_return='.tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'). '&tax='.$paypal_ipn_tax_amount. '&first_name='.urlencode($order->customer['firstname']). '&last_name='.urlencode($order->customer['lastname']). '&address1='.urlencode($order->customer['street_address']). '&city='.urlencode($order->customer['city']). '&state='.urlencode($order->customer['state']). '&zip='.urlencode($order->customer['postcode']). '&email='.$order->customer['email_address']. '¬ify_url='.MODULE_PAYMENT_PAYPALIPN_NOTIFY_URL; ///derek if any one can see the problem //echo "$process_button_string"; i can't get the loop for attributes done i did by the way paypal ipnv0.97 and 71 and all 8 series work it took me about a month but i figured the problem out it is missing part of the installation direction and you have to make some changes to order.php you must also download v0.97 and find the changes to order.php Quote Link to comment Share on other sites More sharing options...
kenD Posted October 28, 2003 Author Share Posted October 28, 2003 mimages - Will this code work to automatically create a paypal entry, or dooes it need fixing? It works the way it is, it prepopulates the signup form (minus the phone, state and email) and it creates your shoping cart in paypal so that when you recieve an ivoice from paypal you can see all the items that were purchased.....not just an amount. frank1002us - .....like i said I do not know php to well, but the code worked in its original state..... it will take me some time to go through your changes. Quote Link to comment Share on other sites More sharing options...
steve.luther Posted October 28, 2003 Share Posted October 28, 2003 I just have a couple of questions about this MOD. Can I change this 5 to a 3 if I delete 2 currencies $my_currency = substr(MODULE_PAYMENT_PAYPALIPN_CURRENCY, 5); What do these 2 lines mean? tep_draw_hidden_field('lc', 'US') . tep_draw_hidden_field('rm', '2') Also my shop is in Germany where we have umlauts on some letters, when I submitted a test cart paypal told me that non us ascii characters wer not supported and that I should change to a non umlaut letter. also the cost cam up in US dollars and I do not want us dollars. I changed the line $my_currency = 'USD'; to $my_currency = 'EUR'; but is still came up in dollars. Does this mean I will need to tell all my German, Austrian, Swiss, French and Spanish customers that they can not use paypal to pay for stuff from my shop. Cheers Steve Quote Link to comment Share on other sites More sharing options...
kenD Posted October 28, 2003 Author Share Posted October 28, 2003 lc - is for the default language your customer sees during sign-up ... I guess you could check to see what language he uses and then put in the appropriate variable...i do not know what countries/lang paypal supports. In the end you do not need this line for english to display euro, you will need an additional line: tep_draw_hidden_field('currency_code', 'EUR'). cs - is for the color of the screen, black or white...default is white you can see all the variables here PayPal Manual not to sure about the umlauts I dont work with euro, so I am not to sure how OSC stores the price for an item that is in Euro....if it stores it as US then converts it to Euro with the current exchange rate during order confimation, you will have to include that into the price for paypal....its just a matter of multiplying the price by the currency. somthing like this: number_format((amount$ * $currencies->get_value($my_currency)), $currencies->get_decimal_places($my_currency))). would replace the number format in this line: tep_draw_hidden_field(('amount_'.($loop+1)), number_format($amount, $currencies->get_decimal_places($my_currency))). Everyone needs to know if you populate the paypal cart, paypal determines how much to charge....you can't tell paypal to charge 100 if everything in the cart adds to 60...... You should be able to transfer shipping, but i was unable to so I transefered shipping as a cart item..... I just did this so in case a customer does not press continue at paypal, i still had a record of what was in the cart, with the options selected Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.