如何使用AuthnetARB类为Authorize.net设置自动重复计费(ARB)

时间:2014-02-20 15:11:34

标签: authorize.net authorize.net-arb

我能够使用该课程为使用以下信用卡付款设置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";
}

然而,这不起作用。它没有尝试将其作为echeck处理,而是尝试将其作为信用卡处理。既然它不能失败。我的问题是:我如何强制将其作为echeck而不是信用处理?

1 个答案:

答案 0 :(得分:1)

我已经离我很近了。我无法在任何地方找到这个答案,所以我想在这里分享我的困境并回答。我只需要为true函数指定createAccount(),它告诉班级它是eCheck。愚蠢的我在网上搜索而不只是搜索类文件...无论如何,这是以防万一其他人也这样做。

$subscription->createAccount(true);