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
Comment #1
classicridge commentedThanks 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:
Comment #2
Jason Dean commentedSimilar request and solution here, but for WPS.
Comment #3
rszrama commentedLet'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.
Comment #4
ngreenup commentedI 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?
Comment #5
arkjoseph commentedTrying 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...
Comment #6
preston3271 commentedI 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?
Comment #7
winberg.chris commentedJust 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
Comment #8
karingIt 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
Comment #9
tomtech commentedAutomatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.