When a customer adds a shipping address to their order, the shipping address is not sent in the API request to PayPal.

Of course the shipping address exists and can be found on the order in Drupal Commerce, and then copied manually to PayPal to print shipping labels, but this takes a lot of extra time especially if there are a lot of orders.

I was able to temporarily get this working by adding the following lines to commerce_paypal_wpp.module, right before the api request line, but shouldn't this be a normal part of the module's function?

$shipping_address = $order_wrapper->commerce_customer_shipping->commerce_customer_address->value();

  $nvp += array(
    'SHIPTONAME' => substr($shipping_address['name_line'], 0, 25),
    'SHIPTOSTREET' => substr($shipping_address['thoroughfare'], 0, 100),
    'SHIPTOSTREET2' => substr($shipping_address['premise'], 0, 100),
    'SHIPTOCITY' => substr($shipping_address['locality'], 0, 40),
    'SHIPTOSTATE' => substr($shipping_address['administrative_area'], 0, 40),
    'SHIPTOCOUNTRY' => $shipping_address['country'],
    'SHIPTOZIP' => substr($shipping_address['postal_code'], 0, 20),
  );


// Submit the request to PayPal.
  $response = commerce_paypal_api_request($payment_method, $nvp, $order);

Thanks in advance!

Comments

classicridge’s picture

Thanks to a friend for suggesting I move this to hook_commerce_paypal_api_request_alter(), which I have done. For others, here is the code to add to your own module:

/**
 * Implements hook_commerce_paypal_api_request_alter() to properly add the SHIPTO items for wpp transactions
 */
function do_custom_commerce_paypal_api_request_alter(&$nvp, $order, $payment_method) {
  if ($payment_method['base'] == 'commerce_paypal_wpp' ) {
  	$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  	$shipping_address = $order_wrapper->commerce_customer_shipping->commerce_customer_address->value();
  
    $nvp += array(
      'SHIPTONAME' => substr($shipping_address['name_line'], 0, 25),
      'SHIPTOSTREET' => substr($shipping_address['thoroughfare'], 0, 100),
      'SHIPTOSTREET2' => substr($shipping_address['premise'], 0, 100),
      'SHIPTOCITY' => substr($shipping_address['locality'], 0, 40),
      'SHIPTOSTATE' => substr($shipping_address['administrative_area'], 0, 40),
      'SHIPTOCOUNTRY' => $shipping_address['country'],
      'SHIPTOZIP' => substr($shipping_address['postal_code'], 0, 20),
    );
  }
}
Jason Dean’s picture

Similar request and solution here, but for WPS.

rszrama’s picture

Title: Missing shipping address (SHIPTO) parameters in PayPal API request » Add shipping address parameters to PayPal API request if available
Version: 7.x-2.2 » 7.x-2.x-dev
Category: Bug report » Feature request

Let's just treat this as a feature request and get a patch up for it. I'm not opposed, it's just never been done.

ngreenup’s picture

I have used the above code in a custom module. How do I test that it is working? I have WPP setup using the paypal sanbox. When I complete an order and view it in the paypal sandbox it only has the option to "refund". There is no "print shipping label" option. Is this just a feature that isn't supported in the sandbox?

arkjoseph’s picture

Trying to use the hook within a module. Will i need to go to 7.x-2.x-dev for this to work? Im still not seeing shipping info on paypal invoice...

preston3271’s picture

I was wondering if the shipto feature for Paypal WPS was added to Commerce Paypal as a patch to port the shipping address to the Paypal Module?

winberg.chris’s picture

Just what I needed! This works with 7.x-2.3

I just had to replace
do_custom_commerce_paypal_api_request_alter

with

nameofmymodule_commerce_paypal_api_request_alter

KarinG’s picture

It now appears that Shipping Address must be passed on to PayPal in order to be eligible for Seller Protection. I've opened a new issue:
https://www.drupal.org/project/commerce_paypal/issues/2986094