Intereting Posts
как передать параметры с использованием маршрута в Zend Framework 2? Сортировка 3-мерного массива на 2-м уровне в зависимости от значений 3-го уровня Как установить постоянную ссылку в своем блоге в соответствии с датой и названием публикации? ошибка синтаксиса – ошибка синтаксиса, неожиданный T_NS_SEPARATOR Как минимизировать JS или CSS на лету Предварительная обработка Javascript перед загрузкой на клиентскую машину Symofny2 Получите список доступных логических имен контроллеров Определите минимальные и максимальные значения всех столбцов CSV эхо-информация пользователя, не работающая в Codeigniter file_get_contents получать файлы cookie Как я могу переписать мой PHP и MySQL для группировки моего списка HTML равными значениями столбцов? Сброс PHP mysqli_result Отключить налоги программно для определенной роли пользователя Fecebook Messenger Bot на PHP не всегда отвечает пользователю Я использую fopen или curl для загрузки XML-файла с указанием URL-адреса в PHP

Получить идентификатор транзакции заказа от authorize.net Авторизовать AIM

Я создаю настраиваемый плагин отчетов 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 для плагина Woocommerce, поэтому генерируется идентификатор транзакции.

Я хочу включить это в мой экспорт .csv. Как мне это сделать? Я попытался посмотреть в файлах плагина и заметил, что идентификатор транзакции был $response_array[6] но не может понять, как его вернуть. Если кто-то может показать мне, как использовать API Authorize.net и получить идентификатор транзакции, который был бы потрясающим! Заранее спасибо!

EDIT: Вот что я до сих пор. Я добавил PHP-код для подключения, но, похоже, не может вывести идентификатор транзакции заказа. Кстати, «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; 

EDIT 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 $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; 

EDIT 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|||||||||||||||||||||||||||||| 

До того, как была строка с буквой, но я заменил ее для целей безопасности. Считаете ли вы, что это может произойти, потому что я не устанавливаю номер cc или платежный адрес?

Строка ответа, возвращаемая 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 идентификатор транзакции – 2230582188 . В нашем массиве, который является седьмым элементом, мы можем его использовать:

 $transaction_id = $response_array[6]; 

Вот демонстрация, показывающая, что вы это делаете.