spivurno
8/3/2016 - 5:11 PM

GP Unique ID // Gravity Perks // Generate Unique ID for Auth.net

GP Unique ID // Gravity Perks // Generate Unique ID for Auth.net

<?php
/**
 * GP Unique ID // Gravity Perks // Generate Unique ID for Auth.net
 * WARNING: This will create gaps in the sequence if authorization fails.
 */
add_filter( 'gform_authorizenet_transaction_pre_capture', 'gpui_set_unique_transaction_id', 10, 4 );
function gpui_set_unique_transaction_id( $transaction, $form_data, $config, $form ) {

	$target_form_id = 1; // update "1" to your form ID
	$target_field_id = 1; // update "1" to your field ID

	if( $form['id'] == $target_form_id && is_callable( 'gp_unique_id' ) ) {
		$uid = gp_unique_id()->get_sequential_unique_id( $form['id'], $target_field_id );
		$transaction->invoice_num = $uid;
		$_POST[ "input_{$target_field_id}" ] = $uid;
	}

	return $transaction;
}