Would you like to send the phone number of users filling out your payment form to Authorize.net? By default, WPForms already gives you options to send through the customer’s name, email address, and address from the Authroize.net tab inside the Payment settings.
In this tutorial, we’ll walk you through how to send the phone number with each transaction using a custom PHP snippet.
Creating Your Payment Form
Note: You’ll need an Elite license level to access the Authorize.net payment method.
To begin, we’ll create a new payment form and add our fields to this form. In the form, we’ll also include the Phone field that we’ll use to capture the user’s phone number.
Once we’ve created the form, we’ll set the Payments tab to process Authorize.net transactions. If you need assistance creating an Authorize.net form, please check out this useful documentation.
Mapping the Fields
Next, we’ll map our Name, Email, and Address fields to send through this information with each form submission.
To do this, go to Payments » Authorize.net from inside the form builder. Next, toggle the Enable Authorize.Net payments option to the on position.
Once you’ve enabled this option, go ahead and map over the appropriate fields and provide the payment description and any conditional logic you may want.
For this tutorial, we will not be using the Enable Conditional Logic feature, so this will remain disabled.
Adding the Snippet
Now, it’s time to add the snippet to our site. If you need any assistance with how and where to add custom snippets, please check out this tutorial.
/*
* Include a phone number with Authorize.Net args.
*
* @link https://wpforms.com/developers/how-to-send-the-phone-number-to-authorize-net/
*/
function wpf_dev_authorize_net_process_payment_single_add_phone_to_args( $args, $process ) {
// Replace 26 in $process->fields[3] to an id of your phone field.
if ( isset( $process->fields[3][ 'value' ] ) ) {
$args[ 'phone' ] = $process->fields[3][ 'value' ];
}
return $args;
}
add_filter( 'wpforms_authorize_net_process_payment_single_args', 'wpf_dev_authorize_net_process_payment_single_add_phone_to_args', 10, 2 );
/**
* Set the phone number on customer billing information.
*
* @link https://wpforms.com/developers/how-to-send-the-phone-number-to-authorize-net/
*/
function wpf_dev_authorize_net_process_transaction_add_phone_to_transaction( $transaction, $args ) {
$bill_to = $transaction->getBillTo();
if ( is_null( $bill_to ) ) {
$bill_to = new netauthorizeapicontractv1CustomerAddressType();
}
$phone = $args[ 'phone' ];
$bill_to->setPhoneNumber( $phone );
$transaction->setBillTo( $bill_to );
return $transaction;
}
add_filter( 'wpforms_authorize_net_process_transaction', 'wpf_dev_authorize_net_process_transaction_add_phone_to_transaction', 10, 2 );
This snippet will look for the field ID that is set for the phone number. In this case, the field ID for our Phone field is 3. It will then store that number and process this through in the next function to setPhoneNumber in the billing information of the transaction.
You’ll need to update the field ID to match your own ID for the Phone field. If you need help finding your ID number, please check out this tutorial.
Now, when the transactions are processed, you’ll easily see that the phone number is now part of the customer’s billing information.
Frequently Asked Questions
These are answers to some of the top questions we see about sending the phone number field’s value to Authorize.Net.
Q: Why isn’t this snippet isn’t working for me?
A: If you’re not seeing the phone number on your transactions, please make sure you’ve updated the ID inside fields[
3][ 'value' ]
.
That’s it! You’ve now learned how to add phone number field value to Authorize.Net payments.
Next, would you also like to send an invoice number to Authorize.Net? Be sure to check out our tutorial on how to send an invoice number through Authorize.Net payments.
Related
Filter References: