Reply
Member
Posts: 1
Registered: ‎04-28-2014

ARB periodically failing after direct sale

We have created an online subscription process using Authorize.NET. Originally, we were creating the ARB to start today and then billing every month. This was a problem because when a user entered bad credit card data (zip/address match failure), Authorize.NET accepted the info and then did not process the initial transaction for 4-8 hours. We've verified this with phone support and they said we needed to create an initial sale for the first month and then setup an ARB for subsequent months. This we have done.

 

We now have a problem in that sometimes the subscription fails. The direct sale always goes through, and usually the subscription follow-up also goes through, but from time-to-time, the subscription fails. We've called Authorize.NET and they claim to see no attempt at creating a subscription during these periods, but the successful direct sale they can see. This is problematic for us as we are pushing a marketing campaign and concerned about users not being able to subscribe. I thought perhaps there was a timeout problem, so I set the subscription code to go in a loop for up to 25 attempts to create the follow-up subscription, but that has changed nothing. Authorize.NET still says they see no attempt at a subscription, only during these failed attempts.

 

We are using the authorize.net libraries downloaded from the site. Here is our code (note that the keys/user login is handled via global variables in a separate, secured file that allows switching between test/live mode):

 

//create transaction
$transaction = new AuthorizeNetAIM;
$transaction->setSandbox(AUTHORIZENET_SANDBOX);
$transaction->setFields(
	array(
	'amount' => $amount, 
	'card_num' => $arr['cardnumber'], 
	'exp_date' => $expirationDate,
	'first_name' => ucfirst($arr['billingfirstname']),
	'last_name' => ucfirst($arr['billinglastname']),
	'address' => ($arr['billingaddress']?$arr['billingaddress']:$arr['address']),
	'city' => ($arr['billingcity']?$arr['billingcity']:$arr['city']),
	'state' => ($arr['billingstate']?$arr['billingstate']:$arr['state']),
	'zip' => ($arr['billingzip']?$arr['billingzip']:$arr['zip']),
	'email' => $arr['email'],
	'card_code' => $arr['cvv'],
	)
);
//print_r($transaction);
$response = $transaction->authorizeAndCapture();
if (!$response->approved)
	return $response->response_reason_text;
$transactionId = $response->transaction_id;
$authcode = $response->authorization_code;


//create follow up subscription
$subscription_id = '';
$maxtries = 25;
$tries = 0;

while(!$subscription_id && $tries<$maxtries) {
	$tries++;
	//subscription
	$subscription = new AuthorizeNet_Subscription; 
	$subscription->name = $modx->getOption('subscriptions.anet_charge_desc'); 
	$subscription->intervalLength = ($_POST['paymentfrequency']=='year'?12:1);
	$subscription->intervalUnit = "months"; 
	$subscription->startDate = $startDate; 
	$subscription->totalOccurrences = 9999;
	$subscription->amount = $amount;
	$subscription->creditCardCardNumber = $arr['cardnumber']; 
	$subscription->creditCardExpirationDate= $expirationDate;
	$subscription->creditCardCardCode = $arr['cvv']; 
	$subscription->billToFirstName = ucfirst($arr['firstname']);
	$subscription->billToLastName = ucfirst($arr['lastname']);
	$subscription->billToAddress = ($arr['billingaddress']?$arr['billingaddress']:$arr['address']);
	$subscription->billToCity = ($arr['billingcity']?$arr['billingcity']:$arr['city']);
	$subscription->billToState = ($arr['billingstate']?$arr['billingstate']:$arr['state']);
	$subscription->billToZip = ($arr['billingzip']?$arr['billingzip']:$arr['zip']);
	$subscription->email = $arr['email'];
	//print_r($subscription);
	$request = new AuthorizeNetARB; 
	$response = $request->createSubscription($subscription); 
	//print_r($response);
	$subscription_id = $response->getSubscriptionId();
	//echo '</pre>';
}

 

Most of the time, this code works fine. Periodically, the subscription code runs through the 25 time limit and never retrieves a subscription ID. I have started logging the serialized $response variable in hopes that it will provide some answer, but the fact that authorize.net does not see anything on their end is troubling.

 

Thanks for any help you can provide.

Expert
Posts: 4,525
Registered: ‎03-08-2010

Re: ARB periodically failing after direct sale

Can you log the web traffic too? cause if it not getting authorize.net then $response probably be empty.