@Aaron was nice enough to provide me some code to do basic Authorize & Capture CC processing.
I think I have finally figured out how the XML template works, but am struggling to understand the code related to the request and response.
Here is the code I have so far...
// Address to send Credit Card Request to Authorize.net $url = "https://apitest.authorize.net/xml/v1/request.api"; try{ $ch = curl_init(); if ($ch === FALSE){ throw new Exception('failed to initialize'); }else{ // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false ); $content = curl_exec($ch); $content = str_replace('xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $content);
$PaymentResponse = new SimpleXMLElement($content);
if ($content === FALSE){ throw new Exception(curl_error($ch), curl_errno($ch)); curl_close($ch); }else{ echo '$PaymentResponse = ' . $PaymentResponse; exit(); } } }catch(Exception $e){ trigger_error(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR); } // End script. exit();
Questions:
1.) Do all of the cURL statements above just send the Request?
2.) What is the purpose of these two lines?
$content = curl_exec($ch); $content = str_replace('xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $content);
3.) If the cURL statements in #1 above are just sending the Request using a POST, then why are we assigning the results of curl_exec to a variable?
4.) What does this code do?
$PaymentResponse = new SimpleXMLElement($content); if ($content === FALSE){ throw new Exception(curl_error($ch), curl_errno($ch)); curl_close($ch); }else{ echo '$PaymentResponse = ' . $PaymentResponse; exit(); }
Any help in helping me understand how this code works would be *greatly* appreciated so I can start using Authorize.net to make some $$$ for both of us!!
Thanks,
Sally
04-13-2017 08:25 AM
These questions are more related to programming in PHP than using our API. We suggest engaging an Authorize.Net Certified Developer with expertise in PHP who could assist.
Richard
04-17-2017 09:49 AM