Gravity Forms Authorize.Net Add-On Custom Transaction Data
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:
- 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:
addressallow_partial_authamountauth_codeauthentication_indicatorbank_aba_codebank_acct_namebank_acct_numbank_acct_typebank_check_numberbank_namecard_codecard_numcardholder_authentication_valuecitycompanycountrycust_idcustomer_ipdelim_chardelim_datadescriptionduplicate_windowdutyecheck_typeemailemail_customerencap_charexp_datefaxfirst_namefooter_email_receiptfreightheader_email_receiptinvoice_numlast_nameline_itemloginmethodphonepo_numrecurring_billingrelay_responseship_to_addressship_to_cityship_to_companyship_to_countryship_to_first_nameship_to_last_nameship_to_stateship_to_zipsplit_tender_idstatetaxtax_exempttest_requesttran_keytrans_idtypeversionzipsolution_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;
}