Gravity forms: Authorize.net Invoice number

I was wondering If you knew how to add an invoice code to the forms in Authorize.net.

I check the authorize.net feed settings but they do not ask for an invoice code.Then, I started to do some research and found the hook gform_authorizenet_save_entry_id that could be used to create that invoice code.

Read More

The problem comes that there is no documentation about this hook. It was only mentioned as one of the updates. So, I’m creating a hidden field with an {entry_id} as a default value and trying to find a way to pass it as an Invoice Number.

Any help would be appreciated. Thanks 🙂

Update:

I was able to add a transaction code to the form using the following Snippet

//Adding the transaction code 
add_filter( 'gform_authorizenet_transaction_pre_capture', 'set_invoice_number', 10, 5 );
function set_invoice_number( $transaction, $form_data, $config, $form, $entry ) {
    if ( $form['id'] == 6 ) {

      // your submission ID format to be inserted into the hidden field
      $SubmissionID = 'RW-' . $entry['id'];

      $transaction->invoice_num = $SubmissionID;
    }
    return $transaction;
}

I got the invoice number to become “RW-” but the $entry[‘id’] is not printing anything

Related posts

2 comments

  1. You can assign an invoice number using an input field by adding this code to your theme’s functions.php file:

    add_filter('gform_authorizenet_transaction_pre_capture', 'set_invoice_number', 10, 4);
    function set_invoice_number($transaction, $form_data, $config, $form)
    {
          $transaction->invoice_num = rgpost('input_YOUR INPUT FIELD NUMBER HERE');
    }
    

    If the input field is the hidden field containing the form’s entry id that should accomplish what you’re wanting.

  2. I use the following code to append the “Form Name” to the invoice number passed to Authorize.net. I believe that the previous answer would work if the first field you create in each form was the “Invoice Number” field, but if you add the field later, or add it to your previously created forms, they wouldn’t all have the same field number so it may not work. This code will use the automatically generated unique invoice number and add the form name.
    i.e. Form Name: “Yearly Subscription” Auto Invioce Number: “1234567890”
    Info that Authorize.net receives: “1234567890-Yearly_Subscription”

    I have found that instead of adding custom functions to your theme file, it is better to build a custom plugin and add them there instead. This way if your theme updates, you won’t lose your functions. The code to create your plugin, along with the functions for your Authorize.net code is included below. Save this file as My_Custom_Functions_Plugin.php and upload it to your web host in the “wp-content/plugins/” folder and then activate it. Next time you need to add any customized functions, just add them at the end of this file.

    <?php
    
    /*
    
    Plugin Name: My_Custom_Functions_Plugin
    
     Plugin URL: http://WEBSITE
    
     Description: Custom Functions and Scripts for WEBSITE
    
     Version: 1.0.0
    
     Author: NAME
    
     Author URI: http://WEBSITE
    
    */
    
    
    
    // Functions for apending form name to authorize.net invoice
    
     add_filter( 'gform_authorizenet_transaction_pre_capture', 'invoice_num', 10, 4 );
    
     function invoice_num( $transaction, $form_data, $config, $form ) {       
    
     $transaction->invoice_num = uniqid() . '-' . rgar( $form_data, 'form_title' ); 
    
     gf_authorizenet()->log_debug( 'gform_authorizenet_transaction_pre_capture: ' . print_r( $transaction, 1 ) );
    
     return $transaction;}
    
    // End of Authorize.net Function
    
    
    
    // Add any additional Functions below this comment line to keep your themes functions.php file from getting overwritten on theme updates. Copy and paste this comment line before each function and give it a description to help keep you organized about what your function does 
    
    
    ?>
    

    Hope this helps!

Comments are closed.