OK. so we’re trying to force cancel ARB subscription id in authorize.net upon demotion. I think it would be awesome to have this an option in s2member.
Anyway, we’ve successfully been able to to get s2member to demote a user for any failed payments but have not been able to force authorize.net to cancel the ARB subscription. We’re going to try the following below. Can you let me know if this is the best way and/or is there a better way?
The following code is placed in our s2-hacks file.
Thanks for any insight you can provide.
/////////////
add_action('ws_plugin__s2member_during_auto_eot_system_during_demote', 'my_eot_hook_function');
function my_eot_hook_function($vars)
{
extract($vars);
$user = new WP_User($user_id); # Get the user's data again
//ATTEMPT TO RECEIVE FIRST DEBUGGING EMAIL
$terms = count($vars);
$ifusedMailArbMsg = '';
foreach ($vars as $field => $value)
{
$terms--;
$ifusedMailArbMsg .= $field . ' = ' . $value;
if ($terms)
{
$ifusedMailArbMsg .= " <br /> ";
}
}
$ifusedMailArbMsg .= 'This should be the end of the results after demotion and should be the last email sent out. Check the time sent. We should probably try and cancel out ARB in this function';
$headers1 = 'From: notifications@morningcoach.com' . "rn" ;
wp_mail('tech@morningcoach.com', 'fn test: my_eot_hook_function', $ifusedMailArbMsg , $headers1);
//TEMP REMOVED BELOW
//send_payment_failure_email($user_id);
//PROGRAMATICALLY CANCEL ARB
$request = array ("x_method" => "cancel", "x_subscription_id" => $subscription_id);
$response = c_ws_plugin__s2member_pro_authnet_utilities::authnet_arb_response ($request);
//ATTEMPT 2ND DEBUGGING EMAIL
$terms2 = count($response);
$response_str = '';
foreach ($response as $field => $value)
{
$terms2--;
$response_str .= $field . ' = ' . $value;
if ($terms2)
{
$response_str .= " <br /> ";
}
}
wp_mail('tech@morningcoach.com','result of forced cancellation in eot_hook fn',$response_str,$headers1);
}