How to Send an Invoice Number Through to Authorize.net Payments

Introduction

Would you like to include the invoice number from your WPForms to any Authorize.net payment? Authorize.net will accept certain metadata they already have mapped to their payment API. In this tutorial, we’ll show you how to send through a payment invoice number inside the Authorize.net payments.

Creating your Authorize.net form

In order to set up your form to accept Authorize.net payments, please review this documentation.

create the form first to send the invoice through to Authorize.net

Adding thee snippet to send an invoice number

Once your form is set up to accept these payments, you can now copy and paste this code snippet to your site.

In our example below, we added a Numbers (fields[6]) form field that contains the invoice number.

/*
 * Include an invoice number into the set of Authorize.Net args.
 *
 * @link  https://wpforms.com/developers/how-to-send-an-invoice-number-through-to-authorize-net-payments
 * 
 * @param array                        $args    Single payment arguments.
 * @param \WPFormsAuthorizeNet\Process $process WPForms Authorize.Net Process object.
 *
 * @return array
 */
function wpf_dev_authorize_net_process_payment_single_add_invoice_to_args( $args, $process ) {
	// Replace 6 in $process->fields[6] to an id of your invoice field.
	if ( isset( $process->fields[6]['value'] ) ) {
		$args['invoice'] = $process->fields[6]['value'];
	}
	return $args;
}
add_filter( 'wpforms_authorize_net_process_payment_single_args', 'wpf_dev_authorize_net_process_payment_single_add_invoice_to_args', 10, 2 );

/**
 * Set the transaction order invoice number.
 *
 * @link  https://wpforms.com/developers/how-to-send-an-invoice-number-through-to-authorize-net-payments
 */

function wpf_dev_authorize_net_process_transaction_add_invoice_to_transaction( $transaction, $args ) {
	if ( ! isset( $args['invoice'] ) ) {
		return $transaction;
	}

	$order = $transaction->getOrder();
	if ( is_null( $order ) ) {
		$order = new \net\authorize\api\contract\v1\OrderType();
	}

	$order->setInvoiceNumber( $args['invoice'] );

	$transaction->setOrder( $order );

	return $transaction;
}

add_filter( 'wpforms_authorize_net_process_transaction', 'wpf_dev_authorize_net_process_transaction_add_invoice_to_transaction', 10, 2 );

In the first code snippet, we’re using the code to grab our invoice number so the API will know what field we want to pass through as the invoice number. Please remember to update this field ID to match the field ID of your form.

And that’s it, when you Authorize.net payments are sent through WPForms, they will now include the invoice number.

Now you can pass invoice through to Authorize.net

Would you like to also learn how to send the address through to Authorize.net? Check out our tutorial on How to Send an Address Through to Authorize.net Payments.

Filter References:

FAQ

Q: What if I don’t have an invoice number?

A: If you don’t know the invoice number you could use a Smart Tag to generate a unique ID into a Hidden Field and then pass that number through to Authorize.net. Just follow this tutorial.