From 48b4fd92ba7d5f874a7daf8fa341c9cb1bd9e220 Mon Sep 17 00:00:00 2001 From: Charles Scott Date: Tue, 24 May 2016 11:44:32 -0400 Subject: [PATCH] Split into two scripts one for Test and the toher for Production --- glmAuthNetRelay/AuthNetRelayProduction.php | 117 ++++++++++++++++++ ...{AuthNetRelay.php => AuthNetRelayTest.php} | 41 +++--- glmAuthNetRelay/debug.txt | 10 +- 3 files changed, 148 insertions(+), 20 deletions(-) create mode 100644 glmAuthNetRelay/AuthNetRelayProduction.php rename glmAuthNetRelay/{AuthNetRelay.php => AuthNetRelayTest.php} (68%) diff --git a/glmAuthNetRelay/AuthNetRelayProduction.php b/glmAuthNetRelay/AuthNetRelayProduction.php new file mode 100644 index 0000000..a6fed36 --- /dev/null +++ b/glmAuthNetRelay/AuthNetRelayProduction.php @@ -0,0 +1,117 @@ + 'https://secure.authorize.net/gateway/transact.dll', + 'Test' => 'https://test.authorize.net/gateway/transact.dll' +); + +// Post URL selection +$post_url = $PostURLs[$processingMode]; + +// Log request array +if ($debug) { + $debugFile = fopen("debug.txt", "w"); + fwrite($debugFile, "\n\n\nDate: ".date('m/d/Y h:i:s')."\n\nSubmitted Array\n".print_r($_REQUEST,1)); +} + +// Create Post string +$post_string = ''; +$sep = ''; +foreach($_REQUEST as $k=>$v) { + $post_string .= $sep.$k.'='.urlencode($v); + $sep = '&'; +} + +// log Post String +if ($debug) { + fwrite($debugFile, "\n\nPost String\n".$post_string); +} + +// Setup curl request +$curl_request = curl_init($post_url); +curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_string); +curl_setopt($curl_request, CURLOPT_HEADER, 0); +curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); +curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); + +// Check if we need to verify the peer connection to Authorize.net +if ($VERIFY_PEER) { + curl_setopt($curl_request, CURLOPT_CAINFO, $certPEM); +} else { + curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); +} + +// If this is an XML request then set curl opt header to text/xml +if (preg_match('/xml/',$post_url)) { + curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); +} + +// Send request +$response = curl_exec($curl_request); + +// Return response string directly back to calling site +echo $response; + +// Log any error and response string +if ($debug) { + + if ($curl_error = curl_error($curl_request)) { + fwrite($debugFile, "\n\nCURL ERROR\n$curl_error\n\n"); + } + + fwrite($debugFile, "\n\nResponse\n".print_r($response,1)); + fclose($debugFile); +} + + diff --git a/glmAuthNetRelay/AuthNetRelay.php b/glmAuthNetRelay/AuthNetRelayTest.php similarity index 68% rename from glmAuthNetRelay/AuthNetRelay.php rename to glmAuthNetRelay/AuthNetRelayTest.php index b0db168..d36b413 100644 --- a/glmAuthNetRelay/AuthNetRelay.php +++ b/glmAuthNetRelay/AuthNetRelayTest.php @@ -1,41 +1,52 @@ FALSE [x_encap_char] => | [x_test_request] => 1 - [x_amount] => 121 - [x_card_num] => 6011000000000013 + [x_amount] => 48 + [x_card_num] => 4007000000027 [x_card_code] => 123 [x_exp_date] => 2/2017 [x_first_name] => John @@ -35,7 +35,7 @@ Array Post String -x_version=3.1&x_delim_char=%2C&x_delim_data=TRUE&x_relay_response=FALSE&x_encap_char=%7C&x_test_request=1&x_amount=121&x_card_num=6011000000000013&x_card_code=123&x_exp_date=2%2F2017&x_first_name=John&x_last_name=Smith&x_address=120+E.+Lake+St.%2C+Apt+2&x_city=Petoskey&x_state=MI&x_zip=49770&x_country=US&x_invoice_num=13d1d7e29e8f27ab7e8f&x_description=Star+Line+Mackinaw+City+-+Event+Tickets&x_email=info%40gaslightmedia.com&x_email_customer=&x_phone=231-487-0692&x_type=AUTH_CAPTURE&x_login=44pvQ8D7d&x_tran_key=8rj6ME772K9Pe9pJ +x_version=3.1&x_delim_char=%2C&x_delim_data=TRUE&x_relay_response=FALSE&x_encap_char=%7C&x_test_request=1&x_amount=48&x_card_num=4007000000027&x_card_code=123&x_exp_date=2%2F2017&x_first_name=John&x_last_name=Smith&x_address=120+E.+Lake+St.%2C+Apt+2&x_city=Petoskey&x_state=MI&x_zip=49770&x_country=US&x_invoice_num=13d1d7e29e8f27ab7e8f&x_description=Star+Line+Mackinaw+City+-+Event+Tickets&x_email=info%40gaslightmedia.com&x_email_customer=&x_phone=231-487-0692&x_type=AUTH_CAPTURE&x_login=44pvQ8D7d&x_tran_key=8rj6ME772K9Pe9pJ Response -|3|,|1|,|6|,|(TESTMODE) The credit card number is invalid.|,|000000|,|P|,|0|,|13d1d7e29e8f27ab7e8f|,|Star Line Mackinaw City - Event Tickets|,|121.00|,|CC|,|auth_capture|,||,|John|,|Smith|,||,|120 E. Lake St., Apt 2|,|Petoskey|,|MI|,|49770|,|US|,|231-487-0692|,||,|info@gaslightmedia.com|,||,||,||,||,||,||,||,||,||,||,||,||,||,|288538B103D9FFE0FF6607363386F536|,||,||,||,||,||,||,||,||,||,||,||,||,|XXXX0013|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,|| \ No newline at end of file +|1|,|1|,|1|,|(TESTMODE) This transaction has been approved.|,|000000|,|P|,|0|,|13d1d7e29e8f27ab7e8f|,|Star Line Mackinaw City - Event Tickets|,|48.00|,|CC|,|auth_capture|,||,|John|,|Smith|,||,|120 E. Lake St., Apt 2|,|Petoskey|,|MI|,|49770|,|US|,|231-487-0692|,||,|info@gaslightmedia.com|,||,||,||,||,||,||,||,||,||,||,||,||,||,|9EF4754875042B8F1C7304DED51DCBAC|,||,||,||,||,||,||,||,||,||,||,||,||,|XXXX0027|,|Visa|,||,||,||,||,||,||,||,||,||,||,||,||,||,||,||,|| \ No newline at end of file -- 2.17.1