0

我正在尝试为我的实时 auth.net 电子商务购物车设置静默响应。来自 Auth.net 的 Silent Post 正在发生,但我没有得到任何数据。我写了一个快速脚本,只是为了记录交易的响应,这样我就可以看到 auth.net 发送了什么。

$f = fopen('log.txt', 'a');

fwrite($f, 'new request: ');
fwrite($f, date('Y-m-d H:i'));
fwrite($f, ' ' . $_SERVER['REQUEST_METHOD']. ' ');
fwrite($f, ' ' . $_SERVER['QUERY_STRING']. ' ');
fwrite($f, ' ' . $_SERVER['REQUEST_URI']. ' ');

fwrite($f, print_r(http_get_request_headers(),1));
fwrite($f, print_r($_GET,1));

简单的甜蜜,应该给我一个结果吧?注意我添加的 GET 打印,因为这是结果集:

 new request: 2011-12-06 14:54 GET      /authSilentResponse/ Array (
     [Accept] => */*
     [Host] => myhost.mydomain.com
     [Connection] => Close ) Array ( )

因此,我收到的不是所有内容都告诉我的帖子,而是 GET 请求...

任何人都知道为什么这不会作为带有数据的 POST 来通过?

4

2 回答 2

0

您的帐户中一定存在一些错误配置。Silent Post 不会向您发送获取数据。只需按照指示发布即可。您可能已经检查过了,但以防万一:

  1. 如果您不使用该功能,请检查是否未设置默认中继响应 URL
  2. 检查以确保您的日志条目对应于实际事务。我们有时会遇到“坏人”对我们无声的帖子网址进行 ping 操作。出于这个原因,我们添加了对 GET 请求的检查并删除它们
  3. 尝试自己发布到您的静默网址并打印_r($_POST)。确保它有效。
  4. 在 Auth.net 接口中添加 MD5 哈希,运行一个事务,看看你是否得到了值。
于 2011-12-06T21:57:42.977 回答
0

我认为您在某处做错了,因为 Silent Post 总是使用 POST 请求提交交易结果。试试我写的代码,看看它是否更适合你。如果是这样,您可以将您的代码与它进行比较,看看潜在问题在哪里。

这是可用于测试的修改版本:

<?php
// Get the subscription ID if it is available. 
// Otherwise $subscription_id will be set to zero.
$subscription_id = (int) $_POST['x_subscription_id'];

// Check to see if we got a valid subscription ID.
// If so, do something with it.
if ($subscription_id)
{
    // Get the response code. 1 is success, 2 is decline, 3 is error
    $response_code = (int) $_POST['x_response_code'];

    // Get the reason code. 8 is expired card.
    $reason_code = (int) $_POST['x_response_reason_code'];

    if ($response_code == 1)
    {
        // Approved!

        // Some useful fields might include:
        // $authorization_code = $_POST['x_auth_code'];
        // $avs_verify_result  = $_POST['x_avs_code'];
        // $transaction_id     = $_POST['x_trans_id'];
        // $customer_id        = $_POST['x_cust_id'];

        $result = 'approved';
    }
    else if ($response_code == 2)
    {
        // Declined

        $result = 'declined';
    }
    else if ($response_code == 3 && $reason_code == 8)
    {
        // An expired card

        $result = 'expired';
    }
    else 
    {
        // Other error

        $result = 'error';
    }

    $f = fopen('log.txt', 'a');

    fwrite($f, 'new request: ');
    fwrite($f, date('Y-m-d H:i'));
    fwrite($f, ' ' . $_SERVER['REQUEST_METHOD']. "\n\n");
    fwrite($f, ' ' . $_SERVER['QUERY_STRING']. "\n\n");
    fwrite($f, ' ' . $_SERVER['REQUEST_URI']. "\n\n");

    fwrite($f, ' ' . $result. "\n\n");

    fwrite($f, print_r(http_get_request_headers(),1));
    fwrite($f, print_r($_REQUEST,1));
}
?>

您可以使用此表单对其进行测试:

<form action="http://www.yourdomain.com/silent-post.php" method="post">
    <input type="hidden" name="x_response_code" value="1"/>
    <input type="hidden" name="x_response_subcode" value="1"/>
    <input type="hidden" name="x_response_reason_code" value="1"/>
    <input type="hidden" name="x_response_reason_text" value="This transaction has been approved."/>
    <input type="hidden" name="x_auth_code" value=""/>
    <input type="hidden" name="x_avs_code" value="P"/>
    <input type="hidden" name="x_trans_id" value="1821199455"/>
    <input type="hidden" name="x_invoice_num" value=""/>
    <input type="hidden" name="x_description" value=""/>
    <input type="hidden" name="x_amount" value="9.95"/>
    <input type="hidden" name="x_method" value="CC"/>
    <input type="hidden" name="x_type" value="auth_capture"/>
    <input type="hidden" name="x_cust_id" value="1"/>
    <input type="hidden" name="x_first_name" value="John"/>
    <input type="hidden" name="x_last_name" value="Smith"/>
    <input type="hidden" name="x_company" value=""/>
    <input type="hidden" name="x_address" value=""/>
    <input type="hidden" name="x_city" value=""/>
    <input type="hidden" name="x_state" value=""/>
    <input type="hidden" name="x_zip" value=""/>
    <input type="hidden" name="x_country" value=""/>
    <input type="hidden" name="x_phone" value=""/>
    <input type="hidden" name="x_fax" value=""/>
    <input type="hidden" name="x_email" value=""/>
    <input type="hidden" name="x_ship_to_first_name" value=""/>
    <input type="hidden" name="x_ship_to_last_name" value=""/>
    <input type="hidden" name="x_ship_to_company" value=""/>
    <input type="hidden" name="x_ship_to_address" value=""/>
    <input type="hidden" name="x_ship_to_city" value=""/>
    <input type="hidden" name="x_ship_to_state" value=""/>
    <input type="hidden" name="x_ship_to_zip" value=""/>
    <input type="hidden" name="x_ship_to_country" value=""/>
    <input type="hidden" name="x_tax" value="0.0000"/>
    <input type="hidden" name="x_duty" value="0.0000"/>
    <input type="hidden" name="x_freight" value="0.0000"/>
    <input type="hidden" name="x_tax_exempt" value="FALSE"/>
    <input type="hidden" name="x_po_num" value=""/>
    <input type="hidden" name="x_MD5_Hash" value="A375D35004547A91EE3B7AFA40B1E727"/>
    <input type="hidden" name="x_cavv_response" value=""/>
    <input type="hidden" name="x_test_request" value="false"/>
    <input type="hidden" name="x_subscription_id" value="365314"/>
    <input type="hidden" name="x_subscription_paynum" value="1"/>
    <input type="submit"/>
</form>
于 2011-12-06T21:52:55.707 回答