Set Authorize.net Transaction Invoice Number

Code

Filename: gpuid-set-authorize-net-invoice-number.php

<?php
/**
 * Gravity Perks // Unique ID // Set Authorize.net Transaction Invoice Number
 * https://gravitywiz.com/documentation/gp-unique-id/
 *
 * This snippet sets the Authorize.net transaction invoice number using the unique ID generated by the Unique ID field.
 */
add_filter( 'gform_authorizenet_transaction_pre_capture', 'gpui_set_unique_transaction_id', 10, 5 );
function gpui_set_unique_transaction_id( $transaction, $form_data, $config, $form ) {

	// Update "123" to the form ID
	$target_form_id = 123;
	// Update "4" to the Unique ID field ID
	$unique_id_field_id = 4;

	if ( $form['id'] == $target_form_id && is_callable( 'gp_unique_id' ) ) {
		foreach ( $form['fields'] as $field ) {
			if ( $field->id == $unique_id_field_id ) {
				$uid                                    = gp_unique_id()->get_unique( $form['id'], $field );
				$transaction->invoice_num               = $uid;
				$_POST[ "input_{$unique_id_field_id}" ] = $uid;
			}
		}
	}
	return $transaction;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.