Home / Admin / Generate and Send Invoice Number to Authorize.Net
Duplicate Snippet

Embed Snippet on Your Site

Generate and Send Invoice Number to Authorize.Net

This snippet generates and sends a unique invoice number to Authorize.Net for completed payments in WPForms

<10
Code Preview
php
<?php
/*
 * 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
 */
 
function wpf_dev_authorize_net_process_payment_single_add_invoice_to_args( $args, $process ) {
     
    // Replace 20 in $process->fields[20] to an id of your invoice field.
    if ( isset( $process->fields[20][ 'value' ] ) ) {
         
        $args[ 'invoice' ] = $process->fields[20][ '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 );

Comments

Add a Comment