Home / Archive / MemberPress: Add Address Fields to Authorize.net
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Add Address Fields to Authorize.net

By default, the user’s address data collected through MemberPress registration forms are not sent to Authorize.net.

Adding this code snippet will include the data users add to address fields on registration and send it to Authorize.net. The user’s address data can be then used within Authorize.net’s invoice system and records.

This code snippet will work for both recurring payments and one-time payments.

Code Preview
php
<?php
function add_address_to_recurring( $args, $txn, $sub ) {
  $user = new MeprUser( $txn->user_id );
  if ( $user->address_is_set() ) {
    $addr = $user->full_address( false );
    $args['subscription']['billTo']['address'] = $addr['mepr-address-one'] . ( isset($addr['mepr-address-two'] ) ? ' ' . $addr['mepr-address-two'] : '' );
    $args['subscription']['billTo']['city']    = $addr['mepr-address-city'];
    $args['subscription']['billTo']['state']   = $addr['mepr-address-state'];
    $args['subscription']['billTo']['zip']     = $addr['mepr-address-zip'];
    $args['subscription']['billTo']['country'] = $addr['mepr-address-country'];
  }
  return $args;
}
add_filter( 'mepr_authorize_create_subscription_args', 'add_address_to_recurring', 11, 3 );
function add_address_to_oneoff( $args, $txn ) {
  $user = new MeprUser( $txn->user_id );
  if ( $user->address_is_set() ) {
    $addr = $user->full_address( false );
    $args['billTo']['address'] = $addr['mepr-address-one'] . (isset($addr['mepr-address-two']) ? ' ' . $addr['mepr-address-two'] : '');
    $args['billTo']['city']    = $addr['mepr-address-city'];
    $args['billTo']['state']   = $addr['mepr-address-state'];
    $args['billTo']['zip']     = $addr['mepr-address-zip'];
    $args['billTo']['country'] = $addr['mepr-address-country'];
  }
  return $args;
}
add_filter( 'mepr_authorize_payment_args', 'add_address_to_oneoff', 11, 2 );
add_filter( 'mepr_authorize_auth_card_args', 'add_address_to_oneoff', 11, 2 );

Comments

Add a Comment