Skip to content

Instantly share code, notes, and snippets.

@cartpauj
Last active June 20, 2020 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cartpauj/220884f8a69704b30c685e2ef3a5166c to your computer and use it in GitHub Desktop.
Save cartpauj/220884f8a69704b30c685e2ef3a5166c to your computer and use it in GitHub Desktop.
Force email to be sent to Authorize.net - MemberPress
<?php
// Some processors require email address to be sent
function mepr_array_swap($key1, $key2, $array) {
$newArray = array();
foreach($array as $key => $value) {
if ($key == $key1) {
$newArray[$key2] = $array[$key2];
} elseif ($key == $key2) {
$newArray[$key1] = $array[$key1];
} else {
$newArray[$key] = $value;
}
}
return $newArray;
}
function add_email_to_recurring($args, $txn, $sub) {
$user = new MeprUser($txn->user_id);
$args['subscription']['customer'] = array('email' => $user->user_email);
$args['subscription'] = mepr_array_swap('customer', 'billTo', $args['subscription']);
return $args;
}
add_filter('mepr_authorize_create_subscription_args', 'add_email_to_recurring', 11, 3);
function add_email_to_oneoff($args, $txn) {
$user = new MeprUser($txn->user_id);
$args['x_email'] = $user->user_email;
return $args;
}
add_filter('mepr_authorize_payment_args', 'add_email_to_oneoff', 11, 2);
add_filter('mepr_authorize_auth_card_args', 'add_email_to_oneoff', 11, 2);
@cartpauj
Copy link
Author

This code will work best in a plugin like Code Snippets. In a "run everywhere" snippet type.

@greggh
Copy link

greggh commented Sep 23, 2019

Is this still actually needed for the latest versions of Memberpress and its authorize.net integration?

@cartpauj
Copy link
Author

It's typically not required, but some processors force an email to be sent. If you get email errors at checkout, then this may be needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment