I was able to use the class to set up ARB for payments made with credit cards like below:
include_once('includes/AuthnetARB.class.php');
$total_payments = intval($_SESSION['total_payments']) - 1;
$start_date = date("Y-m-d", strtotime("+ ".($_SESSION['payment_type'] < "12" ? $_SESSION['payment_type'] : '1')." ".($_SESSION['payment_type'] == "12" ? 'year' : ($_SESSION['payment_type'] == "7" ? 'day' : 'month')).($total_payments > 1 ? 's' : '')));
$subscription = new AuthnetARB("[you-no-see]","[you-no-see]", false);
$subscription->setParameter('amount', number_format($total_cost, 2,'.',''));
$subscription->setParameter('cardNumber', str_replace(array(" ","-"),"",$_SESSION['CCNumber']));
$subscription->setParameter('expirationDate', "20".$_SESSION['CCExpireYear']."-".$_SESSION['CCExpireMonth']);
$subscription->setParameter('firstName', str_replace("&","",$billFname));
$subscription->setParameter('lastName', str_replace("&","",$billLname));
$subscription->setParameter('address', substr($billAddress,0,50));
$subscription->setParameter('city', $billCity);
$subscription->setParameter('state', $billState);
$subscription->setParameter('zip', $billZip);
$subscription->setParameter('email', $_SESSION['email']);
$subscription->setParameter('interval_unit', ($_SESSION['payment_type'] == "12" ? 'years' : ($_SESSION['payment_type'] == "7" ? 'days' : 'months')));
$subscription->setParameter('interval_length', ($_SESSION['payment_type'] == "12" ? '1' : $_SESSION['payment_type']));
$subscription->setParameter('totalOccurrences', $total_payments);
$subscription->setParameter('startDate', $start_date);
$subscription->setParameter('trialOccurrences', 0);
$subscription->setParameter('trialAmount', 0);
// Create the subscription
$subscription->createAccount();
if ($subscription->isSuccessful())
{
// Get the subscription ID
$subscription_id = $subscription->getSubscriberID();
$_SESSION['subscription_id'] = $subscription_id;
$result = mysql_query("UPDATE donations SET subscription_id='".mysql_real_escape_string($subscription_id)."', subscription_interval='".$_SESSION['total_payments']."', subscription_unit='".$_SESSION['payment_type']."' WHERE did=$did LIMIT 1");
echo mysql_error();
$auth->sendValues();
$recurring_message = "Your first payment has been made, and $total_payments payments of $".number_format($total_cost, 2,'.','')." ".strtolower(getPaymentTypeFromShort($_SESSION['payment_type']))." has been scheduled to start on ".date("m-d-Y", strtotime($start_date)).".\n\n";
}else{
$fd = popen("/usr/sbin/sendmail -t -f[email]","w");
fputs($fd, "To: [email]\n");
fputs($fd, "From: $billFname $billLname <".$_SESSION['email'].">\n");
fputs($fd, "Return-Path: <".$_SESSION['email'].">\n");
fputs($fd, "Subject: CMCC - Failed Recurring Transaction\n");
fputs($fd, "X-Mailer: PHP\n\n\n\n");
fputs($fd, "Client Name: $billFname $billLname");
fputs($fd, "Error: ".$subscription->getResponse()."\n");
fputs($fd, "Failed Transaction: $".number_format($total_cost, 2,'.','')." for ".$_SESSION['total_payments']." ".($_SESSION['payment_type'] == "12" ? 'year' : 'month')."(s)\n\n");
fputs($fd, print_r($subscription, true));
pclose($fd);
$error = array("title" => "Could not process order", "desc" => mysql_real_escape_string($auth->aDBErrors));
insertError($error);
foreach($auth->aErrors as $errMessage) {
$_SESSION['message'] .= "<font color=\"red\">$errMessage</font><br />";
}
$_SESSION['message'] = "<font color=\"red\">".$auth->aResponse['Response Reason Text']."</font>";
$recurring_message = "Future payments could not be set up.\n\n";
}
I altered the above for using echecks as below:
include_once('includes/AuthnetARB.class.php');
$total_payments = intval($_SESSION['total_payments']) - 1;
$start_date = date("Y-m-d", strtotime("+ ".($_SESSION['payment_type'] < "12" ? $_SESSION['payment_type'] : '1')." ".($_SESSION['payment_type'] == "12" ? 'year' : ($_SESSION['payment_type'] == "7" ? 'day' : 'month')).($total_payments > 1 ? 's' : '')));
$subscription = new AuthnetARB("[you-no-see]","[you-no-see]", false);
$subscription->setParameter('amount', number_format($total_cost, 2,'.',''));
$subscription->setParameter("routingNumber", $_SESSION['routing_num']);
$subscription->setParameter("accountNumber", $_SESSION['account_num']);
$subscription->setParameter("accountType", "checking");
$subscription->setParameter("bankNam", $_SESSION['bank_name']);
$subscription->setParameter("nameOnAccount", $shipName);
$subscription->setParameter('firstName', str_replace("&","",$billFname));
$subscription->setParameter('lastName', str_replace("&","",$billLname));
$subscription->setParameter('email', $_SESSION['email']);
$subscription->setParameter('interval_unit', ($_SESSION['payment_type'] == "12" ? 'years' : ($_SESSION['payment_type'] == "7" ? 'days' : 'months')));
$subscription->setParameter('interval_length', ($_SESSION['payment_type'] == "12" ? '1' : $_SESSION['payment_type']));
$subscription->setParameter('totalOccurrences', $total_payments);
$subscription->setParameter('startDate', $start_date);
$subscription->setParameter('trialOccurrences', 0);
$subscription->setParameter('trialAmount', 0);
// Create the subscription
$subscription->createAccount();
if ($subscription->isSuccessful())
{
// Get the subscription ID
$subscription_id = $subscription->getSubscriberID();
$_SESSION['subscription_id'] = $subscription_id;
$result = mysql_query("UPDATE donations SET subscription_id='".mysql_real_escape_string($subscription_id)."', subscription_interval='".$_SESSION['total_payments']."', subscription_unit='".$_SESSION['payment_type']."' WHERE did=$did LIMIT 1");
echo mysql_error();
$auth->sendValues();
$recurring_message = "Your first payment has been made, and $total_payments payments of $".number_format($total_cost, 2,'.','')." ".strtolower(getPaymentTypeFromShort($_SESSION['payment_type']))." has been scheduled to start on ".date("m-d-Y", strtotime($start_date)).".\n\n";
}else{
$fd = popen("/usr/sbin/sendmail -t -f[email]","w");
fputs($fd, "To: [email]\n");
fputs($fd, "From: $billFname $billLname <".$_SESSION['email'].">\n");
fputs($fd, "Return-Path: <".$_SESSION['email'].">\n");
fputs($fd, "Subject: CMCC - Failed Recurring Transaction\n");
fputs($fd, "X-Mailer: PHP\n\n\n\n");
fputs($fd, "Client Name: $billFname $billLname");
fputs($fd, "Error: ".$subscription->getResponse()."\n");
fputs($fd, "Failed Transaction: $".number_format($total_cost, 2,'.','')." for ".$_SESSION['total_payments']." ".($_SESSION['payment_type'] == "12" ? 'year' : 'month')."(s)\n\n");
fputs($fd, print_r($subscription, true));
pclose($fd);
$error = array("title" => "Could not process order", "desc" => mysql_real_escape_string($auth->aDBErrors));
insertError($error);
foreach($auth->aErrors as $errMessage) {
$_SESSION['message'] .= "<font color=\"red\">$errMessage</font><br />";
}
$_SESSION['message'] = "<font color=\"red\">".$auth->aResponse['Response Reason Text']."</font>";
$recurring_message = "Future payments could not be set up.\n\n";
}
However, this did not work. Instead of trying to process it as an echeck, it tried processing it as a credit card. Since it could not it failed. My question is: How do I force this to process as an echeck instead of credit?
I was already so close. I could not find this answer anywhere, so thought I'd share my dilemma and answer here. I needed only to specify true
for the createAccount()
function which tells the class that it is an eCheck. Silly me was searching all over the web instead of just searching the class file... Anyway, this is here in case someone else does that too.
$subscription->createAccount(true);