Duplicate Transactions with Authorize Net Plugin for Gravity Forms

Are you having a problem with customers refreshing the form and submitting duplicate transactions with the Authorize Net Gravity Forms plugin?

NOTE: This post was updated on Nov 5, 2018 to reflect the deprecation of a hook.

Several things are going on including the plugin sends a unique invoice number if you don’t supply one. This one feature completely nullifies the built in duplicate transaction check by Authorize.net because a unique invoice number is recognized as a unique transaction regardless of the other fields. So if possible, include a unique invoice number for the transaction. But if not, try this.

Put this in your functions.php file in your theme.

add_filter('gform_authorizenet_transaction_pre_capture','increase_duplicate_window',10,5);
function increase_duplicate_window( $transaction, $form_data, $config, $form, $entry){
  $transaction->duplicate_window = '28800'; // max window of 8 hours
  $transaction->invoice_num = date('ymd').'_'.$form_data['email'];// replace unique number
  return $transaction;
}
add_filter('gform_authorizenet_validation_message','add_duplicate_transaction_message',10,5);
function add_duplicate_transaction_message($error_message, $validation_result, $post, $response, $type ){
  if ($type == 'aim' && $response->response_reason_code == 11){
  return 'This looks like a duplicate transaction. If this transaction should be submitted, either try again in 8 hours or contact us for assistance.';
}
}

This creates an 8 hour window for duplicate transaction blocking by Authorize.net (8 hours in seconds). Lower accordingly to suit your needs. This is the max number of seconds allowed.

It also replaces the unique invoice number with one that is only unique for the day and for that customer using a combination of the date and email.

Should you wish to allow the same customer (email) to submit a different form within your window, you need to use something unique to the form like a form id. So you might set the transaction invoice num like this:

$transaction->invoice_num = $form[‘id’].’-‘.date(‘d’).’_’.$form_data[’email’];// replace unique number
NOTE: I have changed the date to only use the day number because of the character limit (see below).

It also adds a duplicate transaction error message to the standard messages returned. (The plugin doesn’t have a specific message for duplicates. Apparently because they never have any… )

Please note there is a 20 character limit to the invoice number so your concatenated data will likely be truncated to 20 characters.

Also, this will not work well for transactions occurring just before midnight as the change in day resets the filter.  If you expect this to be an issue, you need to play around with the date portion of the string to work with your window.