Out of the box the Authorize.Net add-on for Gravity Forms does quite a bit. However, if you needed to pass custom data to Authorize.Net you'll need to modify the transaction before it is sent to the Authorize.Net API.

By default the Authorize.Net add-on allows you to match these fields to those in your form:

  • Email
  • Address
  • Address 2
  • City
  • State
  • Zip
  • Country
  • Phone

This will automatically tie the values from your form with the specified fields in Authorize.Net.

But there are more fields available on Authorize.Net that can be tied with a transaction. These fields include:

  • address
  • allow_partial_auth
  • amount
  • auth_code
  • authentication_indicator
  • bank_aba_code
  • bank_acct_name
  • bank_acct_num
  • bank_acct_type
  • bank_check_number
  • bank_name
  • card_code
  • card_num
  • cardholder_authentication_value
  • city
  • company
  • country
  • cust_id
  • customer_ip
  • delim_char
  • delim_data
  • description
  • duplicate_window
  • duty
  • echeck_type
  • email
  • email_customer
  • encap_char
  • exp_date
  • fax
  • first_name
  • footer_email_receipt
  • freight
  • header_email_receipt
  • invoice_num
  • last_name
  • line_item
  • login
  • method
  • phone
  • po_num
  • recurring_billing
  • relay_response
  • ship_to_address
  • ship_to_city
  • ship_to_company
  • ship_to_country
  • ship_to_first_name
  • ship_to_last_name
  • ship_to_state
  • ship_to_zip
  • split_tender_id
  • state
  • tax
  • tax_exempt
  • test_request
  • tran_key
  • trans_id
  • type
  • version
  • zip
  • solution_id

You can append data to these fields using the gform_authorizenet_before_single_payment hook. In the example below the customer ID and company information is being added to the transaction based on labels set up in the form.

First, a check is made if the field label is one of "customerid", "customer_id", or "customer id" (converted to lowercase). If so, the field value provided is set as the cust_id parameter on the transaction. A similar check is made for the company, and its value is set as the company parameter.

You can set any of the field names listed above with the transaction.

add_filter( 'gform_authorizenet_before_single_payment', 'set_additional_transaction_fields', 10, 4 );

function set_additional_transaction_fields( $transaction, $form_data, $config, $form ) {
  foreach ($form['fields'] as $field) {
    switch (strtolower($field->label)) {
      case 'customerid':
      case 'customer_id':
      case 'customer id':
        $transaction->cust_id = rgpost('input_' . $field->id);
        break;
      case 'company':
        $transaction->company = rgpost('input_' . $field->id);
        break;
    }
  }

  return $transaction;
}

If you'd like to add a field that is not on the list, e.g. a comments or instructions field, you would need to set a custom field using the setCustomField() method.

In the example below this is being done with a field called "comment" or "comments" from the form, and being set to a custom fieled named Comments before being sent to Authorize.Net.

add_filter( 'gform_authorizenet_before_single_payment', 'add_custom_transaction_data', 10, 4 );

function add_custom_transaction_data($transaction, $form_data, $config, $form) {
  foreach ($form['fields'] as $field) {
    switch (strtolower($field->label)) {
      case 'comment':
      case 'comments':
        $transaction->setCustomField('Comments', rgpost('input_' . $field->id));
        break;
    }
  }

  return $transaction;
}