我正在制作一个自定义的woocommerce报告插件,它会显示某些信息并将其吐出为.csv。我有它返回的名称,公司名称,产品和金额。我这样做的方式如下。
javac -cp...
现在我正在使用Authorize.net AIM支付网关用于Woocommerce插件,因此生成了一个交易ID。
我想在我的.csv导出中包含它。我该怎么做呢?我试着查看插件文件并注意到这是事务ID /**
* 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 API并获得非常棒的交易ID!先谢谢!
$response_array[6]
编辑2:实施约翰的代码
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;
编辑3:好的,这就是我目前所拥有的(不包括api和事务密钥)。
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;
仍然无法弄清楚为什么这不起作用。当我尝试返回 /**
* 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
在有一个字母数字字符串之前,我出于安全目的替换了它。你认为这可能会发生,因为我没有设置cc编号或账单地址吗?
答案 0 :(得分: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];