bookmark_bordergform_authorizenet_transaction_pre_capture

Description

This filter can be used to modify the transaction object before it is sent to Authorize.net. It can also be used to prevent capture by returning false.

Usage

The filter which would run for all ‘product and services’ type Authorize.net feeds can be used like so:

add_filter( 'gform_authorizenet_transaction_pre_capture', 'your_function_name', 10, 5 );

Parameters

  • $transaction object

    The Authorize.net transaction object.

  • $form_data Form Data

    An associative array containing the form title, billing address, payment amount, setup fee amount, line items created using the submitted pricing field values and any discounts from coupons.

  • $config Authorize.net Config

    The feed which is currently being processed.

  • $form

    The form which is currently being processed.

  • $entry Entry Object

    The entry which is currently being processed. Since version 2.1.8.

Examples

1. Prevent capture

The following example shows how you can prevent the payment being captured.

add_filter( 'gform_authorizenet_transaction_pre_capture', '__return_false' );

2. Add a custom field

The following example shows how you can add a custom Authorize.net field to the transaction and pass it the value from a form field.

add_filter( 'gform_authorizenet_transaction_pre_capture', 'add_custom_field', 10, 5 );
function add_custom_field( $transaction, $form_data, $config, $form, $entry ) {
    if ( $form['id'] == 10 ) {
        $value = rgpost( 'input_5');
        $transaction->setCustomField( 'your_field_name', $value );
    }

    return $transaction;
}

3. Set the taxExempt property.

The following example shows how you can add a custom Authorize.net field to the transaction and pass it the value from a form field.

add_filter( 'gform_authorizenet_transaction_pre_capture', 'set_tax_exempt', 10, 5 );
function set_tax_exempt( $transaction, $form_data, $config, $form, $entry ) {
    if ( $form['id'] == 10 ) {
        $transaction->tax_exempt = 'true';
    }

    return $transaction;
}

Placement

Your code snippet should be placed in the functions.php file of your active theme.

Source Code

This filter is located in GFAuthorizeNet::authorize() in class-gf-authorizenet.php