Как настроить автоматическое регулярное выставление счетов (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";
}

Однако это не сработало. Вместо того, чтобы пытаться обработать его как электронный чек, он попытался обработать его как кредитную карту. Поскольку он не мог, он потерпел неудачу. Мой вопрос: как заставить это обрабатывать как электронный чек вместо кредита?


person James    schedule 20.02.2014    source источник
comment
где вы взяли класс AuthnetARB?   -  person Francisco Corrales Morales    schedule 28.08.2014
comment
@FranciscoCorralesMorales На самом деле я не знаю. Я использую файлы, которые были у программиста до меня. Однако я всегда мог разместить файлы где-нибудь на сервере для скачивания. Я сделал Google имя файла, и он придумал несколько хитов. Однако я не уверен, что они являются источником файла, который у меня есть. Теперь есть API для ARB, но он доступен напрямую через Authorize.net. Документацию можно найти по адресу developer.authorize.net/api/arb, а пример кода — по адресу developer.authorize.net/downloads/samplecode . Дайте мне знать, если вам нужен файл, который у меня есть.   -  person James    schedule 29.08.2014
comment
Использовал библиотеку от Autorize.net, отлично работает!, спасибо!   -  person Francisco Corrales Morales    schedule 29.08.2014


Ответы (1)


Я был уже так близко. Я нигде не мог найти этот ответ, поэтому решил поделиться своей дилеммой и ответить здесь. Мне нужно было только указать true для функции createAccount(), которая сообщает классу, что это eCheck. Глупый я искал по всему Интернету, а не просто искал файл класса ... В любом случае, это здесь на случай, если кто-то еще сделает это.

$subscription->createAccount(true);
person James    schedule 20.02.2014