I'm using Braintree with Craft Commerce using this Omnipay Braintree Gateway for Craft Commerce https://github.com/samuelbirch/craftcommerce-braintree

It's working well, but I noticed that some customer data is not passed through to Braintree at the time of a successful purchase. Specifically, the customer information that is mapped from the customer parameters in the transactions sale call.

Working directly with Braintree API it would be done as part of the sale method that includes amount and creditCard etc on the transaction.

Braintree_Transaction::sale([...], array('customer' => array())); 

I'm a bit stuck trying to find where to actually make a modification to pass this data through in the context of Omnipay and Craft Commerce. Does anyone have an idea of where to start? I realize this is a vague question... please comment if there is something specific that I can clarify to make this question more answerable.


It looks like maybe what I should be using is a Craft Commerce hook. Probably commerce_modifyGatewayRequestData. So I'm starting there, but if anyone has tips it would be appreciated!

2 Answers 2


Ok so it works pretty much how the documentation would lead you to think.

This is for Commerce V1 but apart from hooking up to the event, it should be much the same for V2.

public function commerce_modifyGatewayRequestData($data,$type,$transaction)

        // Dump the data to see what is there...you can do what you like to $data and then you return it at the end...
        BusinessLogicPlugin::log("commerce_modifyGatewayRequestData - UNMODIFIED DATA"); 

    # Example...
    # TRUNCATE any over-sized data eWay might not like....
    # Data limits come from here: https://eway.io/api-v3/#direct-connection

        $data['Customer']['FirstName'] = substr($data['Customer']['FirstName'], 0, 49);


        // Dump the modified data for checking if you need to...

        BusinessLogicPlugin::log("commerce_modifyGatewayRequestData - MODIFIED DATA"); 

    // Now actually return the modified data...
    return $data
  • Thanks, Jeremy. I discovered that it does... mostly. I found that a number of Braintree Configuration settings need to be set manually in this function, even though they are already set in Commerce settings (merchantId, publicKey, privateKey, environment). This is true even if I return $data untouched. Not sure why that is, but I've got it working now. I may answer my own question, but def upvoting. You've been giving tons of great Commerce answers here. Oct 17, 2018 at 2:19

The commerce_modifyGatewayRequestData hook did work for my purposes.

One unexpected error I countered when using this hook was a missing Braintree merchantId, publicKey, privateKey, and environment. I expected these to already be set, since they're configured and working fine in Craft Commerce Payment Method settings when I do not use this hook. This error occurred even when I returned $data from this hook as-is. Not sure why this is, but setting it manually with Braintree_Configuration inside the function did the trick:

use Braintree_Configuration;

public function commerce_modifyGatewayRequestData($data, $type, $transaction){

    // Get the Commerce order
    $orderId = $transaction->orderId;
    $order = craft()->commerce_orders->getOrderById($orderId);

    // Set the customer data from the Commerce order
    $customer['email'] = $order->email;
    $customer['firstName'] = $order->billingAddress->firstName;
    $customer['lastName'] = $order->billingAddress->lastName;
    $customer['phone'] = $order->billingAddress->phone;

    // Add customer to $data sent to Braintree
    $data['customer'] = $customer;

    // For some reason this needs to be set manually here, 
    // Should already be set via Craft Commerce?

    return $data;
  • Interesting - that extra config stuff really shouldn't be needed there - defintiely doesn't seem right - I'd raise that as an issue on the github to puzzle that out. Oct 17, 2018 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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