Paypal standard fix - allows showing of items in cart

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
There are several issues with nopCommerce's implementation of Paypal Standard. This fixes just a few...

This will allow you to have your item description, price and quantity FOR EACH ITEM passed to Paypal so it will show up when the customer is checking out with Paypal Standard. It also fixes the mistake (?) that was in the file where the nopCommerce team omitted the zip code from the string. Without the zip code Paypal won't pre-fill the address because a zip code is required. So this allows the pre-filling of addresses to work the way is should as well.

In "PaypalStandardPaymentProcessor.cs" replace "public string PostProcessPayment(Order order)" with this:


public string PostProcessPayment(Order order)
        {
            StringBuilder builder = new StringBuilder();
            string returnURL = CommonHelper.GetStoreLocation(false) + "PaypalPDTHandler.aspx";
            string cancel_returnURL = CommonHelper.GetStoreLocation(false) + "PaypalCancel.aspx";
            builder.Append(GetPaypalUrl());
            builder.AppendFormat("?cmd=_cart&business={0}", HttpUtility.UrlEncode(businessEmail));
            builder.AppendFormat("&upload=1");

            //get the items in the cart
            var cartItems = order.NpOrderProductVariants;
            int x = 1;
            foreach (var item in cartItems)
            {
                //get the productvariant so we can get the name
                var pName = ProductManager.GetProductVariantById(item.ProductVariantId);
                //set the name
                string vName = pName.FullProductName;
                builder.AppendFormat("&item_name_" + x +"={0}", HttpUtility.UrlEncode(vName)); //name
                builder.AppendFormat("&amount_" + x + "={0}", item.PriceExclTax); //amount
                builder.AppendFormat("&quantity_" + x + "={0}", item.Quantity); //quantity
                x++;
            }

            builder.AppendFormat("&custom={0}", order.OrderGuid);
            builder.Append(string.Format("&no_note=1&currency_code={0}", HttpUtility.UrlEncode(CurrencyManager.PrimaryStoreCurrency.CurrencyCode)));
            builder.AppendFormat("&invoice={0}", order.OrderId);
            builder.AppendFormat("&rm=2", new object[0]);
            if (order.ShippingStatus != ShippingStatusEnum.ShippingNotRequired)
                builder.AppendFormat("&no_shipping=2", new object[0]);
            else
                builder.AppendFormat("&no_shipping=1", new object[0]);
            builder.AppendFormat("&shipping_1={0}", order.OrderShippingExclTax);
            builder.AppendFormat("&tax_1={0}", order.OrderTax);
            
            //can use "handling" for extra charges - will be added to "shipping & handling"
            //builder.AppendFormat("&handling_1={0}", GetAdditionalHandlingFee());
            
            builder.AppendFormat("&return={0}&cancel_return={1}", HttpUtility.UrlEncode(returnURL), HttpUtility.UrlEncode(cancel_returnURL));
            builder.AppendFormat("&first_name={0}", HttpUtility.UrlEncode(order.BillingFirstName));
            builder.AppendFormat("&last_name={0}", HttpUtility.UrlEncode(order.BillingLastName));
            builder.AppendFormat("&address1={0}", HttpUtility.UrlEncode(order.BillingAddress1));
            builder.AppendFormat("&address2={0}", HttpUtility.UrlEncode(order.BillingAddress2));
            builder.AppendFormat("&city={0}", HttpUtility.UrlEncode(order.BillingCity));
            StateProvince billingStateProvince = StateProvinceManager.GetStateProvinceById(order.BillingStateProvinceId);
            if (billingStateProvince != null)
                builder.AppendFormat("&state={0}", HttpUtility.UrlEncode(billingStateProvince.Abbreviation));
            else
                builder.AppendFormat("&state={0}", HttpUtility.UrlEncode(order.BillingStateProvince));
            Country billingCountry = CountryManager.GetCountryById(order.BillingCountryId);
            if (billingCountry != null)
                builder.AppendFormat("&country={0}", HttpUtility.UrlEncode(billingCountry.TwoLetterIsoCode));
            else
                builder.AppendFormat("&country={0}", HttpUtility.UrlEncode(order.BillingCountry));

            //to send phone number - work on this later
            //Paypal requires email addressess and phone numbers from all customers, so it would be good to pre-fill them
            //var phoneN = order.BillingPhoneNumber;
            //doesn't look like phone number is formatted in any particular way... hard to parse
            //builder.AppendFormat("&night_phone_a=123"); //area code
            //builder.AppendFormat("&night_phone_b=555"); //prefix
            //builder.AppendFormat("&night_phone_c=1111"); //last four
            
            builder.AppendFormat("&Email={0}", HttpUtility.UrlEncode(order.BillingEmail));
            builder.AppendFormat("&zip={0}", HttpUtility.UrlEncode(order.BillingZipPostalCode));
            HttpContext.Current.Response.Redirect(builder.ToString());
            return string.Empty;
        }


Then rebuild and replace your Paypal files in the BIN.

Another fix I would like (which I'll probably have to do myself) is that when you hit "confirm" (the last button before being sent to Paypal) the order is automatically placed with nopCommerce and an email is sent to the admin and the customer about the order that isn't even finished yet.

What happens if the customer closes out the browser before completing the transaction with Paypal? Now you have an order that is not paid for but has been created and emails have been sent out... a mess! I would like to see the order creation in nopCommerce happen after the customer is sent back to the site on the return link or after the payment has been confirmed with Paypal - I'll have to look into the best way.

Also... if the customer changes his/her mind on something and hits the "cancel and return" link on Paypal then they are taken back to the main page of the site and their cart is empty! What if they wanted to change their order? Now they have to do the order ALL OVER AGAIN - lost sale! I'd like to see the "cancel and return" link on Paypal return the user to their cart which still contains their not-yet-processed order. I'll have to look into that as well...

Hope this code helps some people... if you find it doesn't support something that it should, or is doesn't work like it should then please let me know (post here) and I'll see what I can do.

B
13 years ago
Hello:

Where can I find "PaypalStandardPaymentProcessor.cs"

I hate to sound sooo stupid but I am not in real programing.

I am interested in having the Customer input a required field ("Mobile phone Number") which I inserted as an attribute.

Can this field also pass over to Paypal?

Finally, do you offer your services for hire?

Thanks,

Robert Barrera
13 years ago
I'm pretty sure that attributes can be passed to Paypal this way. It would take a little coding, but I believe it is possible.

How do you have the mobile phone number set as an attribute? It is just one textbox? I would be better if it was three: one for the area code, one for the prefix, and one for the last four. This is how the number is passed to Paypal - in three parts. Having three separate attributes would make it slightly easier to code.

If you only have one textbox it is still doable... but, if you only have one textbox, what do you have in place to make sure that what they entered is a valid phone number? By valid I mean the correct amount of numbers in the right places.

Also... do you have Visual Studio (or Visual C#) 2010 that you can compile the code? You say you're not a programmer...
13 years ago
Thanks B,

Do you know if the v1.8 release have this corrected? I am planning to upgrade from v1.7 to v1.8.
13 years ago
ttun76 wrote:
Thanks B,

Do you know if the v1.8 release have this corrected? I am planning to upgrade from v1.7 to v1.8.


From what I could tell 1.80 has this implemented as an option- there's a checkbox in the Paypal settings. The only thing that needs to be worked out is passing the telephone number. Andrei added some code for the telephone number but then commented it out for some reason because of some issue. I'd really like to have the telephone number, so I'm going to take a crack at Andrei's code and see if I can get it to work.

There is a comment on the checkbox that allows you to show items in Paypal that reads:

Note: Discounts, gift cards, reward points and checkout attributes are not supported
when this option is enabled

... but I fixed the code so it supports all that stuff. It's possible that Andrei just didn't remove that note yet.
13 years ago
bfranklin825 wrote:
It's possible that Andrei just didn't remove that note yet.

You're right. I just forgot to remove that note
13 years ago
Hello BFranklin,

I copied the code and replaced it, saved and rebuild, but I'm getting this error:

Error  1  The name 'ProductManager' does not exist in the current context  C:\Desktop\***\Payment\Nop.Payment.PayPal\PayPalStandardPaymentProcessor.cs  194  29  Nop.Payment.PayPal

it gave the options of using either the following two:

NopSolutions.NopCommerce.BusinessLogic.Products;
or
NopSolutions.NopCommerce.BusinessLogic.Products.ProductManager

How do I resolve this issue?  Thanks in advance.
13 years ago
Forgive me for not mentioning this before, but you have to add some references to the top... in the "using" section:

using NopSolutions.NopCommerce.BusinessLogic.Products;
using NopSolutions.NopCommerce.BusinessLogic.Products.Attributes;
using NopSolutions.NopCommerce.BusinessLogic.Tax;

These will allow you to use stuff like ProductManager, TaxManager, and so on...

Let me know if that fixes it!
13 years ago
Thanks BFranklin. Working now.
13 years ago
Hello BFranklin,

I just realized that when a discount is applied to the order, the discounted amount is not passed over to paypal at all (as if there was no discount). How can i fix this issue?

Thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.