Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gform_braintree_payload filter #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

macbookandrew
Copy link

Allows users to specify more information to add to the payload, including the email address field, which is required if payment receipts are enabled.

If payment receipts are enabled but the email address is not passed to Braintree, the customer sees the error “Your card could not be billed. Please ensure the details you entered are correct and try again.”

Here’s a sample filter that adds email and first/last names:

add_filter( 'gform_braintree_payload', 'my_braintree_add_email', 10, 3 );
function my_braintree_add_email( $args, $entry, $form ) {
    foreach ( $form['fields'] as $field ) {
        if ( 'Email' == $field->label ) {
            // field named "Email"
            $args['customer']['email'] = $entry[$field->id];
        } elseif ( 'name' == $field->type ) {
            // field using the "name" type
            foreach ( $field['inputs'] as $input ) {
                if ( 'First' == $input['label'] ) {
                    $args['customer']['firstName'] = $entry[$input['id']];
                    $args['billing']['firstName'] = $entry[$input['id']];
                } elseif ( 'Last' == $input['label'] ) {
                    $args['customer']['lastName'] = $entry[$input['id']];
                    $args['billing']['lastName'] = $entry[$input['id']];
                }
            }
        }
    }

    return $args;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant