Using Gravity Forms ‘gform_authorizenet_transaction_pre_capture’ PHP filter

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

Usage

To use this filter for all ‘product and services’ type Authorize.net feeds:

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

Parameters

  • $transaction (object) – The Authorize.net transaction object.
  • $form_data (array) – 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 (array) – The feed which is currently being processed.
  • $form (object) – The form which is currently being processed.
  • $entry (object) – The entry which is currently being processed (since version 2.1.8).

More information

See Gravity Forms Docs: gform_authorizenet_transaction_pre_capture

Examples

Prevent capture

Prevent the payment from being captured:

add_filter('gform_authorizenet_transaction_pre_capture', '__return_false');

Add a custom field

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;
}

Set the taxExempt property

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;
}

Set the invoice_num property

Pass an entry value as the transaction’s invoice number:

add_filter('gform_authorizenet_transaction_pre_capture', function($transaction, $form_data, $config, $form, $entry) {
if ($form['id'] == 10) {
$transaction->invoice_num = rgar($entry, '4');
}
return $transaction;
}, 10, 5);

Add a Description

Add a description (up to 255 characters) for one-time transactions in a form with id 30:

add_filter('gform_authorizenet_transaction_pre_capture', function($transaction, $form_data, $config, $form, $entry) {
if ($form['id'] != 30) {
return $transaction;
}
$transaction->description = 'This is my custom description...';
return $transaction;
}, 10, 5);