I've been toying around with checkout on the PayPal sandbox, and the billing information I enter doesn't show up pre-entered on PayPal when I'm redirected there. Is this something that's possible?

Thanku,
Diwant

Comments

qwales1’s picture

Yes it is possible. PayPal WPS doesn't send that info by default. There may be a better way to do this, but you can populate the PayPal guest account form by doing something like this:

Use hook_commerce_paypal_wps_order_form_data_alter().
You will then need to fetch the customer shipping profile for the order using commerce_customer_profile_load().
Add the values you need from the shipping profile to the $data array. You can find the available names for the keys here.

diwant’s picture

Thanks qwales1. I'm going to try this now. Happy New Year!

diwant’s picture

Status: Active » Closed (works as designed)

I found this hook and although I solved my problem a different way, qwales1 has a correct solution if this is your problem as well. Implement hook_commerce_paypal_wps_order_form_data_alter and modify the variables you get in that function to modify what is sent to Paypal.

farse’s picture

I'm a relative newb, and this worked like a charm! My code looks like this for anyone wondering:

/**
 * Allows modules to alter the data array used to create a PayPal WPS redirect
 * form prior to its form elements being created.
 *
 * @param &$data
 *   The data array used to create redirect form elements.
 * @param $order
 *   The full order object the redirect form is being generated for.
 */
function mymodule_commerce_paypal_wps_order_form_data_alter(&$data, $order) {
 
 $customer_profile = commerce_customer_profile_load($order->commerce_customer_billing['und'][0]['profile_id']);

 //create additional data from customer profile to paypal form
 $data['first_name'] =  $customer_profile->commerce_customer_address['und'][0]['first_name'];
 $data['last_name'] =  $customer_profile->commerce_customer_address['und'][0]['last_name'];
 $data['address1'] =  $customer_profile->commerce_customer_address['und'][0]['thoroughfare'];
 $data['city'] = $customer_profile->commerce_customer_address['und'][0]['locality']; 
 $data['zip'] =  $customer_profile->commerce_customer_address['und'][0]['postal_code'];
}
stongo’s picture

Should the code from comment #4 fill in the billing address if one clicks "New to Paypal?" on the paypal site?
I can verify in watchdog that $data is being altered correctly in hook_commerce_paypal_wps_order_form_data_alter() but it doesn't seem to do anything on the paypal site.

johannez’s picture

Thank you for the hook and API info. I had troubles with the address fields, because the state field was missing.

$data['state'] =  $customer_profile->commerce_customer_address[LANGUAGE_NONE][0]['administrative_area'];
Jason Dean’s picture

Thanks for the code snippet in #4. Works a treat :)

benjarlett’s picture

So where do I put the code in #4? I want this functionality too... and would be great if it was just part of the module.

agileadam’s picture

Issue summary: View changes

I've got a hybrid solution from #1872804: Billing Address to PayPal and #1494586: Add the option to collect a shipping address at PayPal. It did not work until I added the no_shipping value of 0.

@benjarlett, this code would go in a custom module that you would create and enable. See https://drupal.org/node/1074360.

/**
 * Implements hook_commerce_paypal_wps_order_form_data_alter().
 */
function heli_commerce_paypal_wps_order_form_data_alter(&$data, $order) {
  // Send shipping address to PayPal for Seller protection.
  $wrapper = entity_metadata_wrapper('commerce_order', $order);
  $shipping_address = $wrapper->commerce_customer_shipping->commerce_customer_address->value();
  $data['address_override'] = 'true';
  $data['showShippingAddress'] = 'false';
  $data['first_name'] = $shipping_address['first_name'];
  $data['last_name'] = $shipping_address['last_name'];
  $data['address1'] = $shipping_address['thoroughfare'];
  $data['address2'] = $shipping_address['premise'];
  $data['city'] = $shipping_address['locality'];
  $data['country'] = $shipping_address['country'];
  $data['state'] = $shipping_address['administrative_area'];
  $data['zip'] = $shipping_address['postal_code'];
  $data['no_shipping'] = 0;
}
benjarlett’s picture

thanks for the pointer.. I created a module with a .module with your code in, and a .info, and enabled it... but doesn't send

looking a bit further I realise I'm not collecting shipping info, I'm wondering now if there were shipping fields that I've deleted for this project (it was going to be a download only store, but things changed and now they want to ship things) that arent being sent cos they're not existing.

do I need to create another drupal install to help me work out what fields were there so I can recreate them?
or...
have I missed the collect shipping tickbox somewhere?
or..
can i modify this info to send the billing info as shipping info (as that'd be fine for my customer).

help much appreciated

Ben

agileadam’s picture

Hi Ben,

If you setup Drupal Commerce manually you probably didn't setup a shipping profile.
I'm not exactly sure what PayPal's policies are, but technically you can pass the billing information to PayPal (instead of shipping).

If you do want to introduce shipping into your site I believe you can achieve this by simply installing commerce_shipping. That'll create the customer profile if I recall correctly.

If your site is already setup for shipping maybe you did delete that customer profile type?

benjarlett’s picture

so would this work to send billing address?
- my clients after a simple fix

/**
 * Implements hook_commerce_paypal_wps_order_form_data_alter().
 */
function heli_commerce_paypal_wps_order_form_data_alter(&$data, $order) {
  // Send billing address to PayPal for Seller protection.
  $wrapper = entity_metadata_wrapper('commerce_order', $order);
  $billing_address = $wrapper->commerce_customer_billing->commerce_customer_address->value();
  $data['address_override'] = 'true';
  $data['showbillingAddress'] = 'false';
  $data['first_name'] = $billing_address['first_name'];
  $data['last_name'] = $billing_address['last_name'];
  $data['address1'] = $billing_address['thoroughfare'];
  $data['address2'] = $billing_address['premise'];
  $data['city'] = $billing_address['locality'];
  $data['country'] = $billing_address['country'];
  $data['state'] = $billing_address['administrative_area'];
  $data['zip'] = $billing_address['postal_code'];
  $data['no_shipping'] = 0;
}
agileadam’s picture

I imagine that'd work, but don't have time to test. Have you tried it yet?
Don't forget to change the function name to match your module (heli » yourmodule).

ptmkenny’s picture

gebiss’s picture

I understand that the fix applies to Commerce PayPal 7.x-1.0. Is there a fix to version 7.x-2.3? The shipping address is still not passed to PayPal using WPS... or am I missing something?

imclean’s picture

Anonymous’s picture

@gebiss I have applied this fix in #9 to paypal_commerce_wps 7.x2-3 module and it works.

All I did was: Create a custom module with the code in #9, changing the word "heli" for the name of my custom module and omitting the closing php tag. Create a info file placed in the module folder with correct details. Turn on the module in Drupal.

imclean’s picture

@gebiss, sorry, I missed you were asking about the shipping address. See: #1494586: Add the option to collect a shipping address at PayPal