Как настроить автоматическое повторное выставление счетов (ARB) для Authorize.net с использованием класса AuthnetARB
Я смог использовать класс для настройки ARB для платежей, произведенных с помощью кредитных карт, как показано ниже:
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";
}
Я изменил выше для использования echecks, как показано ниже:
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";
}
Однако это не сработало. Вместо того чтобы пытаться обработать его как чек, он попытался обработать его как кредитную карту. Так как это не могло, это не удалось. Мой вопрос: как я могу заставить это обрабатывать как чек вместо кредита?
1 ответ
Я был уже так близко. Я нигде не мог найти этот ответ, поэтому подумал, что поделюсь своей дилеммой и отвечу здесь. Мне нужно было только указать true
для createAccount()
функция, которая сообщает классу, что это eCheck. Глупый я искал во всем Интернете вместо того, чтобы просто искать файл класса... Во всяком случае, это здесь на случай, если кто-то еще сделает это.
$subscription->createAccount(true);