5

I'm new to drupal development and am programming a payment module for the new drupal commerce module. It's will be a basic api module that allows the user to stay on the site and makes a separate curl call to send the data and use the response to indicate success or failure.

I copied the authorize.net aim payment module and have so far gotten to a point where I'm correctly posting the information that's being sent using the authorize module. However the payment system I'm using requires the customer name and billing address and I'm not sure about how to go about gathering that information. I know in the order there is a user/customer profile id but I don't know how to get any other information about the customer. I do know that the billing address is gathered, it just isn't sent to authorize.

3 Answers 3

8

The customer profile is attached to the order, and it has an address field that holds the information. To get it you could do;

$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$address = $order_wrapper->commerce_customer_billing->commerce_customer_address->value();
$postal_code = $order_wrapper->commerce_customer_billing->commerce_customer_address->postal_code->value();
...

It's a lot simpler to use the entity metadata wrapper as shown above. What it does is that it loads the customer profile entity for you and let you access it's field.

2
  • I'm getting an error when I include the above code. EntityMetadataWrapperException: Unknown data property commerce_customer_address. in EntityStructureWrapper->getPropertyInfo() (line 317 of /usr/local/domains-nfs/mountainmedia.com/drupal/www/sites/all/modules/entity/includes/entity.wrapper.inc).
    – Aglystas
    Commented Jul 6, 2011 at 15:38
  • @Aglystas sounds like you have modified the default commerce fields or have caching issue with your entities. I just tested on an install a few weeks old and it works there, and I also use it on a live site running beta 3.
    – googletorp
    Commented Jul 6, 2011 at 15:52
2

@googletorp is right about your EntityMetadataWrapperException problem. For me I had entitycache installed. By disabling it and clearing the cache I was able to fix the same problem. The drush commands for clear cache, or the drupal clear cache does not clear the entitycache.

0

I get the exact same, depending on ordering of the panes-- the entity has not been saved when you call the above.

You should look at the pane values to find what you need. If you still need help, post again and I'll find the Drupal thread on this issue / reply what exactly you are doing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.