Search code examples
paypalnopcommerce

How do I pass the correct details into the PayPal email “Shipping details” field using Payments PayPalStandard Plugin?


When I process my shopping Cart, I am passing all the desired information to PayPal that relates the the purchase and user address. I am also allowing the User to choose to either Ship the purchase via UPS or to pick-up the purchase from one of our satellite locations. Therefore, If the User chose UPS, I would like the "Shipping Details" field to state UPS in the Email that PayPal sends to my Store Manager. However, if the User selected to pick-up the purchase, I would like to show the Pick-Up location Name under the "Shipping Details" field.

Currently, the Shipping Details field is displaying "Air Service" for all purchases, which does not make any sense or is useless to us as a piece of information to process the User purchase on our side.

Within the nopCommerce PayPal Standards Plugin, I am providing all the necessary information that is needed to process the purchase once Payment has been made via PayPal. I tried providing the "shipping_method" to fill that "Shipping Details" field but nothing changes in the Email report that we receive.

...

        //create query parameters
        return new Dictionary<string, string>
        {
            //PayPal ID or an email address associated with your PayPal account
            ["business"] = _payPalStandardPaymentSettings.BusinessEmail,

            //shipping method
            ["shipping_method"] = shippingMethod,

            //the character set and character encoding
            ["charset"] = "utf-8",

            //set return method to "2" (the customer redirected to the return URL by using the POST method, and all payment variables are included)
            ["rm"] = "2",

            ["bn"] = PayPalHelper.NopCommercePartnerCode,
            ["currency_code"] = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId)?.CurrencyCode,

            //order identifier
            ["invoice"] = postProcessPaymentRequest.Order.CustomOrderNumber,
            ["custom"] = postProcessPaymentRequest.Order.OrderGuid.ToString(),

            //PDT, IPN and cancel URL
            ["return"] = $"{storeLocation}Plugins/PaymentPayPalStandard/PDTHandler",
            ["notify_url"] = $"{storeLocation}Plugins/PaymentPayPalStandard/IPNHandler",
            ["cancel_return"] = $"{storeLocation}Plugins/PaymentPayPalStandard/CancelOrder",

            //shipping address, if exists
            ["no_shipping"] = postProcessPaymentRequest.Order.ShippingStatus == ShippingStatus.ShippingNotRequired ? "1" : "2",
            ["address_override"] = postProcessPaymentRequest.Order.ShippingStatus == ShippingStatus.ShippingNotRequired ? "0" : "1",
            ["first_name"] = orderAddress?.FirstName,
            ["last_name"] = orderAddress?.LastName,
            ["address1"] = orderAddress?.Address1,
            ["address2"] = orderAddress?.Address2,
            ["city"] = orderAddress?.City,
            ["state"] = orderAddress?.StateProvince?.Abbreviation,
            ["country"] = orderAddress?.Country?.TwoLetterIsoCode,
            ["zip"] = orderAddress?.ZipPostalCode,
            ["email"] = orderAddress?.Email
        };

...

How do I make sure that the Shipping method, such as UPS or Pick-Up Location name is displayed under the "Shipping Details" field in the PayPal Receipt that the Store Manager receives?

Currently, we are getting a useless value of "Air Service", as indicated in the below image, which is not something that we provide for Shipping.

PayPal Receipt
(source: ulsprouts.com)


Solution

  • shipping_details is not a valid parameter available with PayPal Standard. It's actually quite limited when it comes to shipping details.

    What I would recommend for you is to build your own email notifications with the use of Instant Payment Notification (IPN).

    This will trigger a POST of all transaction data to a script that you have sitting on your server. You can receive this data, and process it however you need. Within that script you would have access to all of the IPN data, and you could also pull any data you needed back out of your nopCommerce system. With all of the data needed available, you can then build your own custom branded email notifications, and have them sent accordingly.

    For example, the Invoice ID is getting passed to PayPal, which would then come back in the IPN data. As such, you could query your database to pull out all the shipping details, and build your email that way.