【问题标题】:Get order transaction ID from authorize.net Authorize AIM从 authorize.net 获取订单交易 ID Authorize AIM
【发布时间】:2015-07-08 00:19:25
【问题描述】:

我正在制作一个自定义的 woocommerce 报告插件,它将显示某些信息并将其作为 .csv 文件输出。我让它返回名称、公司名称、产品和金额等内容。我这样做是通过以下方式。

/**
 * Check if we need customer phone.
 */
case 'wc_settings_tab_customer_phone':
    array_push( $csv_values, self::customer_meta( get_the_ID(), '_billing_phone' ) );
break;

现在我正在使用 Authorize.net AIM Payment Gateway for Woocommerce 插件,因此会生成交易 ID。

我想将它包含在我的 .csv 导出文件中。我该怎么做呢?我尝试查看插件文件并注意到这是事务 ID $response_array[6] 但无法弄清楚如何返回它。如果有人能告诉我如何利用 Authorize.net API 并获得交易 ID,那就太棒了!提前致谢!

编辑:这是我到目前为止所得到的。我添加了要连接的 php 代码,但似乎无法提取订单交易 ID。顺便说一句,“x_login”和“x_tran_key”已经被取出,换成了“test123”。

    case 'wc_settings_tab_authorize_id':
    $post_url = "https://secure.authorize.net/gateway/transact.dll";

    $post_values = array(

        // the API Login ID and Transaction Key must be replaced with valid values
        "x_login"           => "test123",
        "x_tran_key"        => "test123",

        "x_version"         => "3.1",
        "x_delim_data"      => "TRUE",
        "x_delim_char"      => "|",
        "x_relay_response"  => "FALSE",
        // Additional fields can be added here as outlined in the AIM integration
        // guide at: http://developer.authorize.net
    );


    // This sample code uses the CURL library for php to establish a connection,
    // submit the post, and record the response.
    // If you receive an error, you may want to ensure that you have the curl
    // library enabled in your php configuration
    $request = curl_init($post_url); // initiate curl object
        curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
        curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
        curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
        curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
        $post_response = curl_exec($request); // execute curl post and store results in $post_response
        // additional options may be required depending upon your server configuration
        // you can find documentation on curl options at http://www.php.net/curl_setopt
    curl_close ($request); // close curl object

    // This line takes the response and breaks it into an array using the specified delimiting character
    $response_array = explode($post_values["x_delim_char"],$post_response);

    array_push( $csv_values, TransactionID() );
break;

编辑 2:实现 John 的代码

                    case 'wc_settings_tab_authorize_id':
                    $post_url = "https://secure.authorize.net/gateway/transact.dll";

                    $post_values = array(

                        // the API Login ID and Transaction Key must be replaced with valid values
                        "x_login"           => "test123",
                        "x_tran_key"        => "test123",

                        "x_version"         => "3.1",
                        "x_delim_data"      => "TRUE",
                        "x_delim_char"      => "|",
                        "x_relay_response"  => "FALSE",
                        // Additional fields can be added here as outlined in the AIM integration
                        // guide at: http://developer.authorize.net
                    );

                    // This sample code uses the CURL library for php to establish a connection,
                    // submit the post, and record the response.
                    // If you receive an error, you may want to ensure that you have the curl
                    // library enabled in your php configuration
                    $request = curl_init($post_url); // initiate curl object
                        curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
                        curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
                        curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
                        curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
                        $post_response = curl_exec($request); // execute curl post and store results in $post_response
                        // additional options may be required depending upon your server configuration
                        // you can find documentation on curl options at http://www.php.net/curl_setopt
                    curl_close ($request); // close curl object

                    $post_response = '1|1|1|This transaction has been approved.|4DHVNH|Y|2230582188|none|Test transaction for ValidateCustomerPaymentProfile.|0.00|CC|auth_only|none|John|Doe||123 Main St.|Bellevue|WA|98004|USA|800-555-1234|800-555-1234|email@example.com|||||||||0.00|0.00|0.00|FALSE|none|E440D094322A0D406E01EDF9CE871A4F||2|||||||||||XXXX1111|Visa||||||||||||||||';
                    $response_array = explode('|',$post_response);    
                    $transaction_id = $response_array[6];

                    array_push( $csv_values, $transaction_id );
                break;

编辑 3: 好的,这就是我目前拥有的(不包括 api 和事务密钥)。

    /**
    * Check for authorize.net transaction id.
    */
    case 'wc_settings_tab_authorize_id':
        $post_url = "https://secure.authorize.net/gateway/transact.dll";

        $post_values = array(

        // the API Login ID and Transaction Key must be replaced with valid values
        "x_login"           => "TEST",
        "x_tran_key"        => "TEST",

        "x_version"         => "3.1",
        "x_delim_data"      => "TRUE",
        "x_delim_char"      => "|",
        "x_relay_response"  => "FALSE",

        // Additional fields can be added here as outlined in the AIM integration
        // guide at: http://developer.authorize.net
        );

        // This sample code uses the CURL library for php to establish a connection,
        // submit the post, and record the response.
        // If you receive an error, you may want to ensure that you have the curl
        // library enabled in your php configuration
        $request = curl_init($post_url); // initiate curl object
        curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
        curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
        curl_setopt($request, CURLOPT_POSTFIELDS, http_build_query($post_values)); // use HTTP POST to send form data
        curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
        $post_response = curl_exec($request); // execute curl post and store results in $post_response

        // additional options may be required depending upon your server configuration
        // you can find documentation on curl options at http://www.php.net/curl_setopt
        curl_close ($request); // close curl object

        // This line takes the response and breaks it into an array using the specified delimiting character
        $response_array = explode($post_values["x_delim_char"],$post_response);
        $transaction_id = $response_array[6];

        array_push( $csv_values, $transaction_id );
    break;

仍然无法弄清楚为什么这不起作用。当我尝试返回$transaction_id 时,我得到了0 的值。当我尝试 $post_response 查看它返回的内容时,我得到了这个:

3|2|33|Credit card number is required.||P|0|||0.00|CC|auth_capture||||||||||||||||||||||||||THISISANALPHANUMERICNUMBER||||||||||||||||||||||||||||||

之前有一个字母数字字符串,但出于安全目的我将其替换了。您认为这可能是因为我没有设置抄送号码或帐单地址吗?

【问题讨论】:

  • 您解决了吗?如果没有,我有一个答案。
  • 嗨@john-conde,很抱歉这么晚才回复你。不,问题尚未解决,我很想听听您的意见。
  • 好的,我已经添加了答案并包含了一个演示

标签: php wordpress csv woocommerce authorize.net


【解决方案1】:

Authorize.Net 返回的响应字符串如下所示:

1|1|1|This transaction has been approved.|4DHVNH|Y|2230582188|none|Test transaction for ValidateCustomerPaymentProfile.|0.00|CC|auth_only|none|John|Doe||123 Main St.|Bellevue|WA|98004|USA|800-555-1234|800-555-1234|email@example.com|||||||||0.00|0.00|0.00|FALSE|none|E440D094322A0D406E01EDF9CE871A4F||2|||||||||||XXXX1111|Visa||||||||||||||||

这是由| 分隔的结果,这是您在此处设置的分隔符:

"x_delim_char"      => "|",

您使用explode() 正确拆分字符串:

$response_array = explode($post_values["x_delim_char"],$post_response);    

它为我们提供了一个名为$response_array 的数组中的数据。

在 Authorize.Net 的响应中,交易 ID 是2230582188。在我们的数组中,这是第七个元素,所以我们可以使用:

$transaction_id = $response_array[6];

Here is a demo showing you this works.

【讨论】:

  • 谢谢!我感觉它与“$response_array[6];”有关但我不知道如何使用它。
  • 如果要求不高的话。您能帮我将此代码与我现有的代码集成吗?我必须包括什么才能使它起作用?
  • 我不知道您的代码是如何工作的,但看起来 array_push( $csv_values, $response_array[6] ); 是您所需要的。
  • 如果有机会,请查看我的编辑。这是我目前拥有的。这对您来说是否正确?另外,你有paypal吗?我想给你捐款。过去一周我遇到了这个问题。
  • 删除$post_response = '1|1|1|This transaction has been approved.|4DHVNH|Y|2230582188|none|Test transaction for ValidateCustomerPaymentProfile.|0.00|CC|auth_only|none|John|Doe||123 Main St.|Bellevue|WA|98004|USA|800-555-1234|800-555-1234|email@example.com|||||||||0.00|0.00|0.00|FALSE|none|E440D094322A0D406E01EDF9CE871A4F||2|||||||||||XXXX1111|Visa||||||||||||||||'; 。这完全破坏了你的代码。否则你所拥有的一切都很好。无需捐款。很乐意提供帮助。
猜你喜欢
  • 1970-01-01
  • 2013-07-01
  • 2013-03-07
  • 2012-11-19
  • 2011-08-30
  • 1970-01-01
  • 2018-06-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多