Jump to content

mallen

Members
  • Posts

    316
  • Joined

  • Last visited

Everything posted by mallen

  1. What about this part. $message = $Response->getElementContent('code');// messages, message, responseCode $code = $Response->getElementContent('resultCode'); Should it be like this? I am not sure where its failing. $message = $Response->xml->getElementContent('code');// messages, message, responseCode $code = $Response->xml->getElementContent('resultCode');
  2. What do the dots represent here? $response = parent::send($message,$url);
  3. The status must not be getting a value. Yet it will show error "E00002" which means "The only supported content-types are text/xml and application/xml" But the XML sends the data successfully. I hope someone can help me with this I have been struggling a couple weeks.
  4. When I echo, $Status is coming back NULL and $Response is NULL but if I echo the transaction it shows successful and I see it in the merchant interfacce. The error I get in the error message areas is "Authorize.net:malformed"
  5. This is the part of the response XML. I need to be able to get the code as the response and the transaction number. The is retrieved by the getElement <?xml version="1.0" encoding="utf-8"?> <createCustomerProfileTransactionResponse> <messages> <resultCode>Ok</resultCode> <message> <code>I00001</code> <text>Successful.</text> </message> </messages> <directResponse>1,1,1,This transaction has been approved.,MY6ACN,Y,2186330627,INV10,description of transaction,10.95,CC,auth_capture,2,Joe,Smith,,128 Place,New York,NY,33874,,65447488,,joes@somedomain.com,Joe,Smith,,128 Place,New York,NY,33874,,65447488,,1.00,,2.00,FALSE,PON10,BE55E61FD13711C10,P,2,,,,,,,,,,,XXXX0015,MasterCard,,,,,,,,,,,,,,,,,12031425,100.0.0.1]]></directResponse> </createCustomerProfileTransactionResponse>
  6. I wrote it over now using this code. It is sending data to Authorize.Net. Sure its hard coded info for now but I will try to change that later. Now I need to incorporate that response code to my site. I can get the error box to display that default hard coded error" by leaving the values of the status array empty. That getElement is using another class that allow you to search the XML for things such as ID, code or whatever. Any thing like echo $xml->messages->resultCode; is just outputs at the top of the page. The value of $message is always empty for it displays the default error. If I can fing away to get the vlaues for echo $xml->messages->resultCode; echo $xml->messages->message->code; into the error message field it would be great. I echo these and get the values. require('/../../core/model/XML.php'); require('config.inc.php'); require('AuthnetXML.class.php'); class AuthorizeNet extends GatewayFramework implements GatewayModule { var $cards = array("visa", "mc", "amex", "disc", "jcb", "dc"); var $status = array("" => "CHARGED","" => "PENDING"); function AuthorizeNet () { parent::__construct(); $this->setup('login','password','testmode'); } function actions () { add_action('mycart_process_order',array(&$this,'process')); } function process () { global $Mycart; $message = $this->build(); $Response = $this->send($message); //$status = $Response->getElementContent('responseCode'); $status = $Response->getElementContent('directResponse'); //$status = $Response->getElementContent('resultCode'); //$status = $Response->getElementContent('code'); if ($status == "E00027" || $status == "") { $message = $Response->getElementContent('messages'); //$message = "yo"; //added //$message = $Response->getElementContent('responseCode'); //$message = $Response->getElementContent('message'); //$message = $Response->getElementContent('text'); //$code = $Response->getElementContent('code'); //var_dump($Response); //var_dump($message); //var_dump($Response->getElementContent('messages')); if (empty($message)) { new MycartError(__("A configuration error occurred while processing this transaction. Please contact the site administrator.","Mycart"),'authnet_error',MYCART_TRXN_ERR); return; } new MycartError($message,'authnet_error',MYCART_TRXN_ERR, array('code'=>$code)); return; } //$transaction = $Response->getElement('Transaction'); $transaction = $Response->getElement('Transaction'); $txnid = $transaction['CHILDREN']['Id']['CONTENT']; $txnstatus = $this->status[$status]; $Mycart->Order->transaction($txnid,$txnstatus); } function build () { $Order = $this->Order; $xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY, AuthnetXML::USE_DEVELOPMENT_SERVER); $xml->createCustomerProfileTransactionRequest(array( 'transaction' => array( 'profileTransAuthCapture' => array( 'amount' => '10.95', 'tax' => array( 'amount' => '1.00', 'name' => state sales tax', 'description' => 'state sales tax' ), 'shipping' => array( 'amount' => '2.00', 'name' => 'ground based shipping', 'description' => 'Ground based 5 to 10 day shipping' ), 'lineItems' => array( 0 => array( 'itemId' => '1', 'name' => 'widget', 'description' => 'wiget1', 'quantity' => '18', 'unitPrice' => '45.00' ), 1 => array( 'itemId' => '2', 'name' => 'desk', 'description' => 'widget 2', 'quantity' => '10', 'unitPrice' => '85.00' ) ), 'customerProfileId' => '129', 'customerPaymentProfileId' => '119', 'customerShippingAddressId' => '120', 'order' => array( 'invoiceNumber' => 'INV10', 'description' => 'description of transaction', 'purchaseOrderNumber' => 'PON10' ), 'taxExempt' => 'false', 'recurringBilling' => 'false', 'cardCode' => '000' ) ), 'extraOptions' => '<![CDATA[x_customer_ip=100.0.0.1]]>' )); echo $xml->messages->resultCode; echo $xml->messages->message->code; //echo "Raw request: " . $xml . "<br><br>"; //$response = send_xml_request($xml); //echo "Raw response: " . $response . "<br><br>"; //$parsedresponse = parse_api_response($response); //if ("Ok" == $parsedresponse->messages->resultCode) { // echo "customerProfileId <b>" // . htmlspecialchars($parsedresponse->customerProfileId) // . "</b> was successfully created.<br><br>"; //} //echo "<br><a href=index.php?customerProfileId=" //. urlencode($parsedresponse->customerProfileId) //. ">Continue</a><br>"; } function send ($message) { $url = 'https://apitest.authorize.net/xml/v1/request.api' ; $response = parent::send($message,$url); return new XMLdata($response); } function response ($buffer) { //added to test error $_ = new stdClass(); list($_->code, $_->subcode, $_->reasoncode, $_->reason, $_->authcode, $_->avs, $_->transactionid, $_->invoicenum, $_->description, $_->amount, $_->method, $_->type, $_->customerid, $_->firstname, $_->lastname, $_->company, $_->address, $_->city, $_->state, $_->zip, $_->country, $_->phone, $_->fax, $_->email, $_->ship_to_first_name, $_->ship_to_last_name, $_->ship_to_company, $_->ship_to_address, $_->ship_to_city, $_->ship_to_state, $_->ship_to_zip, $_->ship_to_country, $_->tax, $_->duty, $_->freight, $_->taxexempt, $_->ponum, $_->md5hash, $_->cvv2code, $_->cvv2response) = explode(",",$buffer); return $_; } function settings () { $this->ui->cardmenu(0,array( 'name' => 'cards', 'selected' => $this->settings['cards'] ),$this->cards); $this->ui->text(1,array( 'name' => 'login', 'value' => $this->settings['login'], 'size' => '16', 'label' => __('Enter your AuthorizeNet Login ID.','Mycart') )); $this->ui->password(1,array( 'name' => 'password', 'value' => $this->settings['password'], 'size' => '24', 'label' => __('Enter your AuthorizeNet Password or Transaction Key.','Mycart') )); $this->ui->checkbox(1,array( 'name' => 'testmode', 'checked' => $this->settings['testmode'], 'label' => __('Enable test mode','Mycart') )); } } // END class AuthorizeNet
  7. Ok I tried this and was able to get an error code back from Authorize.net said format was not correct. require('/../../core/model/XML.php'); / class AuthorizeNet extends GatewayFramework implements GatewayModule { var $cards = array("visa", "mc", "amex", "disc", "jcb", "dc"); var $status = array("" => "CHARGED","" => "PENDING"); function AuthorizeNet () { parent::__construct(); $this->setup('login','password','testmode'); } function actions () { add_action('mycart_process_order',array(&$this,'process')); } function process () { global $Mycart; $message = $this->build(); $Response = $this->send($message); $status = $Response->getElementContent('responseCode'); if ($status == "" || $status == "") { $message = $Response->getElementContent('messages'); $code = $Response->getElementContent('code'); if (empty($message)) { new MycartError(__("A configuration error occurred while processing this transaction. Please contact the site administrator.","Mycart"),'authnet_error',MYCART_TRXN_ERR); return; } new MycartError($message,'authnet_error',MYCART_TRXN_ERR, array('code'=>$code)); return; } $transaction = $Response->getElement('Transaction'); $txnid = $transaction['CHILDREN']['Id']['CONTENT']; $txnstatus = $this->status[$status]; $Mycart->Order->transaction($txnid,$txnstatus); } function build () { $Order = $this->Order; $_ = array('<?xml version="1.0" encoding="utf-8"?>'."\n"); $_[] = '<EngineDocList>'; $_[] = '<DocVersion DataType="String">1.0</DocVersion>'; $_[] = '<EngineDoc>'; $_[] = '<ContentType DataType="String">OrderFormDoc</ContentType>'; $_[] = '<createCustomerProfileTransactionRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">'; $_[] = '<merchantAuthentication DataType="String">'; $_[] = '<name DataType="String" >xxx</name>'; $_[] = '<transactionKey DataType="String" >xxx</transactionKey>'; $_[] = '</merchantAuthentication>'; $_[] = '<Transaction>'; $_[] = '<profileTransAuthCapture>'; $_[] = '<amount DataType="String" >10.95</amount>'; $_[] = '<tax>'; $_[] = '<amount DataType="String" >1.00</amount>'; $_[] = '<name>state sales tax</name>'; $_[] = '<description DataType="String" >descstate sales tax</description>'; $_[] = '</tax>'; $_[] = '<lineItems>'; $_[] = '<lineItem>'; $_[] = '<itemId DataType="String" >1</itemId>'; $_[] = '<name DataType="String" >widget 5</name>'; $_[] = '<description DataType="String" >desc of widgt 5</description>'; $_[] = '<quantity DataType="String" >2</quantity>'; $_[] = '<unitPrice DataType="String" >5.00</unitPrice>'; $_[] = '</lineItem>'; $_[] = '<lineItem>'; $_[] = '<itemId DataType="String">2</itemId>'; $_[] = '<name DataType="String" >widget 6</name>'; $_[] = '<description DataType="String" >desccrition widget 6</description>'; $_[] = '<quantity DataType="String" >1</quantity>'; $_[] = '<unitPrice>8.00</unitPrice>'; $_[] = '</lineItem>'; $_[] = '</lineItems>'; $_[] = '<customerProfileId DataType="String" >129</customerProfileId>'; $_[] = '<customerPaymentProfileId DataType="String" >119</customerPaymentProfileId>'; $_[] = '<customerShippingAddressId DataType="String" >120</customerShippingAddressId>'; $_[] = '<order>'; $_[] = '<invoiceNumber DataType="String" >INV000005</invoiceNumber>'; $_[] = '<description DataType="String" >description of transaction</description>'; $_[] = '<purchaseOrderNumber DataType="String" >PONUM000005</purchaseOrderNumber>'; $_[] = '</order>'; $_[] = '<taxExempt>false</taxExempt>'; $_[] = '<recurringBilling>false</recurringBilling>'; $_[] = '<cardCode DataType="String" >000</cardCode>'; $_[] = '</profileTransAuthCapture>'; $_[] = '</transaction>'; //$_[] = '<extraOptions><![CDATA[x_customer_ip=100.0.0.1]]></extraOptions>'; $_[] = '</createCustomerProfileTransactionRequest>'; return join("\n",$_); //echo $transaction; } function send ($message) { $url = 'https://apitest.authorize.net/xml/v1/request.api' ; $response = parent::send($message,$url); return new XMLdata($response); } function response ($buffer) { //added to test error $_ = new stdClass(); list($_->code, $_->subcode, $_->reasoncode, $_->reason, $_->authcode, $_->avs, $_->transactionid, $_->invoicenum, $_->description, $_->amount, $_->method, $_->type, $_->customerid, $_->firstname, $_->lastname, $_->company, $_->address, $_->city, $_->state, $_->zip, $_->country, $_->phone, $_->fax, $_->email, $_->ship_to_first_name, $_->ship_to_last_name, $_->ship_to_company, $_->ship_to_address, $_->ship_to_city, $_->ship_to_state, $_->ship_to_zip, $_->ship_to_country, $_->tax, $_->duty, $_->freight, $_->taxexempt, $_->ponum, $_->md5hash, $_->cvv2code, $_->cvv2response) = explode(",",$buffer); return $_; } function settings () { $this->ui->cardmenu(0,array( 'name' => 'cards', 'selected' => $this->settings['cards'] ),$this->cards); $this->ui->text(1,array( 'name' => 'login', 'value' => $this->settings['login'], 'size' => '16', 'label' => __('Enter your AuthorizeNet Login ID.','Mycart') )); $this->ui->password(1,array( 'name' => 'password', 'value' => $this->settings['password'], 'size' => '24', 'label' => __('Enter your AuthorizeNet Password or Transaction Key.','Mycart') )); $this->ui->checkbox(1,array( 'name' => 'testmode', 'checked' => $this->settings['testmode'], 'label' => __('Enable test mode','Mycart') )); } } // END class AuthorizeNet ?> And when I echoed the data I could see the values but it wan't sening inthe correct format. So chaned it to this and used CURL. require('/../../core/model/XML.php'); class AuthorizeNet extends GatewayFramework implements GatewayModule { var $cards = array("visa", "mc", "amex", "disc", "jcb", "dc"); var $status = array("" => "CHARGED","" => "PENDING"); function AuthorizeNet () { parent::__construct(); $this->setup('login','password','testmode'); } function actions () { add_action('mycart_process_order',array(&$this,'process')); } function process () { global $Mycart; $message = $this->build(); $Response = $this->send($message); $status = $Response->getElementContent('responseCode'); if ($status == "" || $status == "") { $message = $Response->getElementContent('messages'); //$message = $Response->getElementContent('text'); $code = $Response->getElementContent('code'); if (empty($message)) { new MycartError(__("A configuration error occurred while processing this transaction. Please contact the site administrator.","Mycart"),'authnet_error',MYCART_TRXN_ERR); return; } new MycartError($message,'authnet_error',MYCART_TRXN_ERR, array('code'=>$code)); return; } $transaction = $Response->getElement('Transaction'); $txnid = $transaction['CHILDREN']['Id']['CONTENT']; $txnstatus = $this->status[$status]; $Mycart->Order->transaction($txnid,$txnstatus); } function build () { $Order = $this->Order; $xml = ' <?xml version="1.0" encoding="UTF-8"?> <createCustomerProfileTransactionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> <merchantAuthentication> <name>xxx</name> <transactionKey>xxx</transactionKey> </merchantAuthentication> <Transaction> <profileTransAuthCapture> <amount>10.95</amount> <tax> <amount>1.00</amount> <name>state sales tax</name> <description>descstate sales tax</description> </tax> <lineItems> <lineItem> <itemId>1</itemId> <name>widget 5</name> <description>desc of widgt 5</description> <quantity>2</quantity> <unitPrice>5.00</unitPrice> </lineItem> <lineItem> <itemId>2</itemId> <name>widget 6</name> <description>desccrition widget 6</description> <quantity>1</quantity> <unitPrice>8.00</unitPrice> </lineItem> </lineItems> <customerProfileId>1294</customerProfileId> <customerPaymentProfileId>119</customerPaymentProfileId> <customerShippingAddressId>1203</customerShippingAddressId> <order> <invoiceNumber >INV000005</invoiceNumber> <description>description of transaction</description> <purchaseOrderNumber>PONUM000005</purchaseOrderNumber> </order> <taxExempt>false</taxExempt> <recurringBilling>false</recurringBilling> <cardCode>000</cardCode> </profileTransAuthCapture> </transaction> </createCustomerProfileTransactionRequest>'; $url = "https://apitest.authorize.net/xml/v1/request.api"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_MUTE, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); echo $xml; echo $message; } function send ($message) { $url = 'https://apitest.authorize.net/xml/v1/request.api' ; $response = parent::send($message,$url); return new XMLdata($response); } function response ($buffer) { //added to test error $_ = new stdClass(); list($_->code, $_->subcode, $_->reasoncode, $_->reason, $_->authcode, $_->avs, $_->transactionid, $_->invoicenum, $_->description, $_->amount, $_->method, $_->type, $_->customerid, $_->firstname, $_->lastname, $_->company, $_->address, $_->city, $_->state, $_->zip, $_->country, $_->phone, $_->fax, $_->email, $_->ship_to_first_name, $_->ship_to_last_name, $_->ship_to_company, $_->ship_to_address, $_->ship_to_city, $_->ship_to_state, $_->ship_to_zip, $_->ship_to_country, $_->tax, $_->duty, $_->freight, $_->taxexempt, $_->ponum, $_->md5hash, $_->cvv2code, $_->cvv2response) = explode(",",$buffer); return $_; } function settings () { $this->ui->cardmenu(0,array( 'name' => 'cards', 'selected' => $this->settings['cards'] ),$this->cards); $this->ui->text(1,array( 'name' => 'login', 'value' => $this->settings['login'], 'size' => '16', 'label' => __('Enter your AuthorizeNet Login ID.','Mycart') )); $this->ui->password(1,array( 'name' => 'password', 'value' => $this->settings['password'], 'size' => '24', 'label' => __('Enter your AuthorizeNet Password or Transaction Key.','Mycart') )); $this->ui->checkbox(1,array( 'name' => 'testmode', 'checked' => $this->settings['testmode'], 'label' => __('Enable test mode','Mycart') )); } } // END class AuthorizeNet ?> Again not in the correct format.
  8. I tried another approach. With my shopping cart is another API that uses XML so I adapted that code. It is returning error: Fatal error: Call to undefined method AuthorizeNet::url() require('/../../core/model/XML.php'); require('config.inc.php'); require('AuthnetXML.class.php'); class AuthorizeNet extends GatewayFramework implements GatewayModule { var $cards = array("visa", "mc", "amex", "disc", "jcb", "dc"); var $status = array("I0001" => "CHARGED","2" => "PENDING"); function AuthorizeNet () { parent::__construct(); $this->setup('login','password','testmode'); } function actions () { add_action('mycart_process_order',array(&$this,'process')); } function process () { global $Mycart; $message = $this->build(); $Response = $this->send($message); $status = $Response->getElementContent('responseCode'); if ($status == "I00001" || $status == "I00002") { $message = $Response->getElementContent('code'); $code = $Response->getElementContent('code'); if (empty($message)) { new MycartError(__("A configuration error occurred while processing this transaction. Please contact the site administrator.","Mycart"),'hsbc_transaction_error',MYCART_TRXN_ERR); return; } new MycartError($message,'hsbc_transaction_error',MYCART_TRXN_ERR, array('code'=>$code)); return; } $transaction = $Response->getElement('directResponse'); $txnid = $transaction['CHILDREN']['Id']['CONTENT']; $txnstatus = $this->status[$status]; $Mycart->Order->transaction($txnid,$txnstatus); } function build () { $Order = $this->Order; $_ = array('<?xml version="1.0" encoding="utf-8"?>'."\n"); $_[] = '<createCustomerProfileTransactionRequest>'; $_[] = '<merchantAuthentication>'; $_[] = '<name>xxxx</name>'; $_[] = '<transactionKey>xxxx</transactionKey>'; $_[] = '</merchantAuthentication>'; $_[] = '<Transaction>'; $_[] = '<profileTransAuthCapture>'; $_[] = '<amount>10.95</amount>'; $_[] = '<tax>'; $_[] = '<amount>1.00</amount>'; $_[] = '<name>state sales tax</name>'; $_[] = '<description>descstate sales tax</description>'; $_[] = '</tax>'; $_[] = '<lineItems>'; $_[] = '<lineItem>'; $_[] = '<itemId>1</itemId>'; $_[] = '<name>widget 5</name>'; $_[] = '<description>desc of widgt 5</description>'; $_[] = '<quantity>2</quantity>'; $_[] = '<unitPrice>5.00</unitPrice>'; $_[] = '</lineItem>'; $_[] = '<lineItem>'; $_[] = '<itemId>2</itemId>'; $_[] = '<name>widget 6</name>'; $_[] = '<description>desccrition widget 6</description>'; $_[] = '<quantity>1</quantity>'; $_[] = '<unitPrice>8.00</unitPrice>'; $_[] = '</lineItem>'; $_[] = '</lineItems>'; $_[] = '<customerProfileId>129</customerProfileId>'; $_[] = '<customerPaymentProfileId>119</customerPaymentProfileId>'; $_[] = '<customerShippingAddressId>120</customerShippingAddressId>'; $_[] = '<order>'; $_[] = '<invoiceNumber>INV000005</invoiceNumber>'; $_[] = '<description>description of transaction</description>'; $_[] = '<purchaseOrderNumber>PONUM000005</purchaseOrderNumber>'; $_[] = '</order>'; $_[] = '<taxExempt>false</taxExempt>'; $_[] = '<recurringBilling>false</recurringBilling>'; $_[] = '<cardCode>000</cardCode>'; $_[] = '</profileTransAuthCapture>'; $_[] = '</transaction>'; $_[] = '<extraOptions><![CDATA[x_customer_ip=100.0.0.1]]></extraOptions>'; $_[] = '</createCustomerProfileTransactionRequest>'; return join("\n",$_); } function send ($message) { $url = $this->url(); $response = parent::send($message,$url); return new XMLdata($response); } function response ($buffer) { //added to test error $_ = new stdClass(); list($_->code, $_->subcode, $_->reasoncode, $_->reason, $_->authcode, $_->avs, $_->transactionid, $_->invoicenum, $_->description, $_->amount, $_->method, $_->type, $_->customerid, $_->firstname, $_->lastname, $_->company, $_->address, $_->city, $_->state, $_->zip, $_->country, $_->phone, $_->fax, $_->email, $_->ship_to_first_name, $_->ship_to_last_name, $_->ship_to_company, $_->ship_to_address, $_->ship_to_city, $_->ship_to_state, $_->ship_to_zip, $_->ship_to_country, $_->tax, $_->duty, $_->freight, $_->taxexempt, $_->ponum, $_->md5hash, $_->cvv2code, $_->cvv2response) = explode(",",$buffer); return $_; } function settings () { $this->ui->cardmenu(0,array( 'name' => 'cards', 'selected' => $this->settings['cards'] ),$this->cards); $this->ui->text(1,array( 'name' => 'login', 'value' => $this->settings['login'], 'size' => '16', 'label' => __('Enter your AuthorizeNet Login ID.','Mycart') )); $this->ui->password(1,array( 'name' => 'password', 'value' => $this->settings['password'], 'size' => '24', 'label' => __('Enter your AuthorizeNet Password or Transaction Key.','Mycart') )); $this->ui->checkbox(1,array( 'name' => 'testmode', 'checked' => $this->settings['testmode'], 'label' => __('Enable test mode','Mycart') )); } } // END class AuthorizeNet Here is the included file. It will allow you to search the XML for values such as the ID and transaction. /** * Generates a searchable document object model from valid XML * * Usage: $XML = new xmlQuery($source); * * $source can be another xmlQuery DOM object or a string of XML markup * * The xmlQuery object uses several helper methods to find data in the * parsed document object model (DOM). Each method takes a selector argument * that can be used to filter the returned results. {@see xmlQuery::parsequery()} * * The helper methods will contextually return different result structures based * on the query and the structure of the target DOM. The primary search methods * include: * $xmlQuery->tag() to find and filter the DOM to a specific set of tags * $xmlQuery->content() to return the content in a tag (or tags) * $xmlQuery->attr() to return a specific attribute (or all attributes) from a tag (or tags) * * The $xmlQuery->each() method can be used to iterate through the DOM nodes that * match the provided selector argument: while($xmlQuery->each()) { … } * * @author Rockethemes.net, leoSr * @since 1.1 * @package mycart * @subpackage XML **/ class xmlQuery { var $dom = array(); var $_loop = false; function __construct ($data=false) { if (!is_array($data)) $this->parse($data); else $this->dom =& $data; return true; } /** * Parses a string of XML-markup into a structured document object model * * $DOM['_a'] Attributes * $DOM['_c'] Child nodes * $DOM['_v'] Content value * $DOM['_p'] Recursive entries * * XML markup parsing and resulting DOM structure and insert functions by leoSr: * http://mysrc.blogspot.com/2007/02/php-xml-to-array-and-backwards.html * * @author Rockethemes.net, leoSr * @since 1.1 * * @param string $markup String of XML markup * @return boolean **/ function parse (&$markup) { $markup = $this->clean($markup,true); $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parse_into_struct($parser, $markup, $vals, $index); xml_parser_free($parser); $data = array(); $working = &$data; foreach ($vals as $r) { $t = $r['tag']; switch ($r['type']) { case 'open': if ( isset( $working[$t] ) ) { if ( isset( $working[$t][0] ) ) $working[$t][] = array(); else $working[$t] = array( $working[$t], array() ); $cv = &$working[$t][count( $working[$t] )-1]; } else $cv = &$working[$t]; if ( isset( $r['attributes'] ) ) { foreach ( $r['attributes'] as $k => $v ) $cv['_a'][$k] = $this->clean($v); } $cv['_c'] = array(); $cv['_c']['_p'] = &$working; $working = &$cv['_c']; break; case 'complete': if ( isset( $working[$t] ) ) { // same as open if ( isset( $working[$t][0] ) ) $working[$t][] = array(); else $working[$t] = array( $working[$t], array() ); $cv = &$working[$t][count( $working[$t] )-1]; } else $cv = &$working[$t]; if ( isset( $r['attributes'] ) ) { foreach ($r['attributes'] as $k => $v) $cv['_a'][$k] = $this->clean($v); } $cv['_v'] = isset( $r['value'] ) ? $this->clean($r['value']) : ''; break; case 'close': $working = &$working['_p']; break; } } $this->remove_p($data); $this->dom = $data; return true; } /** * Encode and decode characters mis-handled by the XML parser * * @author Rockethemes.net * @since 1.1.6 * * @param string $markup The markup to encode/decode * @param boolean $encode True to encode the markup, omit to decode (default) * @return string The encoded/decoded markup **/ function clean (&$markup,$encode=false) { if (!is_string($markup)) return $markup; $entities = array('&' => '__amp__','<br>' => '__br__'); if ($encode) { $markup = html_entity_decode($markup); $markup = str_replace(array_keys($entities),array_values($entities),$markup); return $markup; } $markup = str_replace(array_values($entities),array_keys($entities),$markup); return $markup; } /** * Removes recursive results in the tree * * @author Rockethemes.net, leoSr * @since 1.1 * * @param array $data A branch of data in the tree * @return void **/ private function remove_p (&$data) { foreach ($data as $k => $v) { if ($k === '_p') unset($data[$k]); elseif (is_array($data[$k])) $this->remove_p($data[$k]); } } /** * Uses recursion to generate XML-markup from the DOM * * @author Rockethemes.net, leoSr * @since 1.1 * * @return string XML markup **/ function markup ($data=false, $depth=0, $tag='', $selfclosing = array('area','base','basefont','br','hr','input','img','link','meta'), $xhtml = true) { if (!$data) $data = $this->dom; $_=array(); foreach ($data as $element=>$r) { if (isset($r[0])) { $_[]=$this->markup($r, $depth, $element, $selfclosing); } else { if ($tag) $element=$tag; $sp=str_repeat("\t", $depth); $_[] = "$sp<$element"; if (isset($r['_a'])) { foreach ($r['_a'] as $at => $av) $_[] = ' '.$at.'="'.($av).'"'; } if (in_array($element,$selfclosing)) { $_[] = ($xhtml)?" />\n":">\n"; continue; } $_[] = ">".((isset($r['_c'])) ? "\n" : ''); if (isset($r['_c'])) $_[] = $this->markup($r['_c'], $depth+1,'',$selfclosing); elseif (isset($r['_v'])) $_[] = ($r['_v']); $_[] = (isset($r['_c']) ? $sp : '')."</$element>\n"; } } return implode('', $_); } /** * Adds a new element to the data tree as a child of the $target element * * @author Rockethemes.net, leoSr * @since 1.1 * * @param mixed $target The target element to attach the new element to * @param array $element A structured element created with xmlQuery::element() * @return boolean **/ function &add ($target,$element) { $true = true; $working = $element; $element = key($working); if ($target !== false) { if (is_array($target)) $node = &$target; else $found =& $this->search($target); if (empty($found)) return false; $node =& $found[0]; if (!isset($node['_c'])) $node['_c'][$element] =& $working[$element]; elseif (isset($node['_c'][$element])) { if (!isset($node['_c'][$element][0])) { $_ = $node['_c'][$element]; $node['_c'][$element] = array($_); } $node['_c'][$element][] =& $working[$element]; } else $node['_c'][$element] =& $working[$element]; return $true; } else $this->dom[$element] =& $working[$element]; return $true; } /** * Creates a structured element for addition to the DOM * * When creating children to attach with an element, use * this method to create the child elements and pass them in * with the $children parameter. * * @author Rockethemes.net * @since 1.1 * * @param string $name The tag name of the new element * @param array $attrs (optional) An associative array of attribute name/value pairs * @param string $content (optional) String contents of the element * @param array $children (optional) Child xmlQuery::element generated elements * @return array The structured element **/ function &element ($name,$attrs=array(),$content=false,$children=array()) { $_ = array(); $_[$name] = array(); if (!empty($attrs) && is_array($attrs)) $_[$name]['_a'] = $attrs; if ($content) $_[$name]['_v'] = $content; if (!empty($children)) foreach ($children as $childname => $child) $_[$name]['_c'][$childname] = $child; return $_; } /** * Finds a tag element in the DOM * * @author Rockethemes.net * @since 1.1 * * @param mixed $tag (optional) Tag to find * @return xmlQuery The matching tags **/ function tag ($tag=false) { if (!$tag) return new xmlQuery(reset($this->dom)); $found = $this->find($tag); if (!empty($found)) return new xmlQuery($found); return false; } /** * Gets a specific element from a list of matching elements * * @author Rockethemes.net * @since 1.1 * * @param int $index (optional) Element number to retreive * @return xmlQuery The specified element **/ function get ($index=0) { if (isset($this->dom[$index])) return new xmlQuery($this->dom[$index]); return false; } /** * Get name of the first container node in the DOM * * @author Rockethemes.net * @since 1.1 * * @return string|boolean The name of the container node or false if none found **/ function context () { reset($this->dom); $context = key($this->dom); if (empty($context)) return false; else return $context; } /** * Iterate through each of the results in the current DOM * * @author Rockethemes.net * @since 1.1 * * @return boolean True if a node exists, false if not **/ function each () { if (!$this->_loop) { $this->_loop = true; return new xmlQuery(array(current($this->dom))); } $next = next($this->dom); if ($next) return new xmlQuery(array($next)); reset($this->dom); $this->_loop = false; return false; } /** * Gets the content (or contents) of a tag * * @author Rockethemes.net * @since 1.1 * * @param mixed $tag (optional) Tag to find * @return string|array A string of a single value or an array of strings for each matching value **/ function content ($tag=false) { if (!$tag) return count($this->dom) == 1 && !empty($this->dom[0]['_v'])?$this->dom[0]['_v']:false; $found = $this->find($tag); if (isset($found['_v'])) $found = array($found); $_ = array(); foreach ($found as $entry) $_[] = $entry['_v']; if (count($_) == 1) return $_[0]; else return $_; } /** * Gets an attribute (or attributes) of a tag * * @author Rockethemes.net * @since 1.1 * * @param string $attr (optional) Attribute to retrieve * @param mixed $tag (optional) Tag to find * @return string|array A single attribute value or an array of attribute values **/ function attr ($tag=false,$attr=false) { if (!is_string($attr)) $attr = false; if (!$tag) { $dom = (count($this->dom) == 1)?$this->dom[0]:$this->dom; if (!isset($dom['_a'])) return false; if (!$attr) return $dom['_a']; return (isset($dom['_a'][$attr]))?$dom['_a'][$attr]:false; } $found = $this->find($tag); if (isset($found['_a'])) $found = array($found); $_ = array(); foreach ($found as $entry) { if (!empty($entry['_a'])) { if (!$attr) $_[] = $entry['_a']; if (isset($entry['_a'][$attr])) $_[] = $entry['_a'][$attr]; } } if (count($_) == 1) return $_[0]; else return $_; return false; } /** * Recursively find elements in the DOM matching the query * * Finds elements that match a specifically formatted * query string to select elements {@see xmlQuery::parsequery()} * * @author Rockethemes.net * @since 1.1 * * @param array $query Search query * @param array $dom (optional) The DOM to search, defaults to the DOM of this instance * @return array DOM array structure **/ private function find ($query,&$dom=false) { if (!$dom) $dom = &$this->dom; if (!is_array($dom)) $dom = array($dom); if (is_string($query)) $query = $this->parsequery($query); $patterns = $this->patterns(); extract($patterns); $results = array(); // Iterate through the query sets foreach ($query as $i => $q) { $operator = false; $_ = array(); // Iterate through each target of the query set foreach ($q as $target) { if (is_string($target) && preg_match("/$delimiters/",$target)) { // Target is an operator, skip to next target $operator = $target; continue; } if (is_array($target)) { $tag = isset($target[0])?$target[0]:false; $subselect = isset($target[1])?$target[1]:false; $attributes = isset($target[2])?$target[2]:false; } else $tag = $target; if ($operator !== false) { // Operator detected for this target $last = count($_)-1; switch ($operator) { case " ": // Branch search case ">": // Child search foreach ($_ as $in => $r) { $entry = array($in => $r); $found = &$this->search($tag,$attributes,$entry); if (!empty($found)) $_[$in] = $found[0]; } break; case "+": // Next sibling search // Format a recursive query $r_query = array($i => array($target)); $found = &$this->find($r_query,$dom); $nexts = array(); foreach ($found as $n => $f) if ($f == $_[$last]) $nexts[] = $found[$n+1]; array_splice($_,$last,1,$nexts); break; } $operator = false; continue; } // Recursive dom search for the tag and any attributes $found = $this->search($tag,$attributes,$dom); $_ = array_merge($_,$found); } if (!empty($subselect)) { // Subselect detected // Post process this target's search results list($selector,$filter) = $subselect; switch ($selector) { case "first": $_ = $_[0]; break; case "last": $_ = $_[count($_)-1]; break; case "even": $_ = self::array_key_filter($_,array(&$this,'_filter_even')); break; case "odd": $_ = self::array_key_filter($_,array(&$this,'_filter_odd')); break; case "eq": $_ = isset($_[$filter])?$_[$filter]:false; case "gt": $_ = self::array_key_filter($_,array(&$this,'_filter_gt'),$filter); break; case "lt": $_ = self::array_key_filter($_,array(&$this,'_filter_lt'),$filter); break; } } // Save the results from this query target // into the total result list $results = array_merge($results,$_); } return $results; } /** * Recursively searches the DOM for matching tag/attributes * * @author Rockethemes.net * @since 1.1 * * @param string $tag The tag name to search for * @param array $attributes (optional) The attribute criteria * @param array $dom (optional) The DOM to search * @param boolean $recursive (optional) Turn on/off recursive searching * @return array List of matching elements **/ private function search ($tag,$attributes=array(),&$dom=false,$recursive=true) { if (!$dom) $dom = &$this->dom; if (!is_array($dom)) $dom = array($dom); $_ = array(); // Iterate through the elements of the DOM and find matches foreach($dom as $key => &$element) { $match = false; if ($recursive) { if (isset($element['_c']) && !empty($element['_c'])) { // Search child elements/nodes first $found = &$this->search($tag,$attributes,$element['_c']); $_ = array_merge($_,$found); } elseif (count($element) > 0 && isset($element[0])) { // Search a collection of a single tag foreach ($element as $b => $branch) { $entry = array($b => $branch); $found = &$this->search($tag,$attributes,$entry,true); $_ = array_merge($_,$found); } } } if ($key !== $tag) continue; // Matched tag already, if attribute search is set check that those match too if (empty($attributes)) $match = true; else foreach ($attributes as $attr => $search) // Match attributes if (isset($element['_a']) && isset($element['_a'][$search[1]]) && !isset($search[3]) || isset($element['_a']) && isset($element['_a'][$search[1]]) && $this->match($element['_a'][$search[1]],$search[2],$search[3])) $match = true; if (!$match) return; // Element matched, save it to our results // If this is a branch, append the branch entries as individual results if (count($element) > 0 && isset($element[0])) $_ = array_merge($_,&$element); else $_[] =& $element; } return $_; } /** * Parses XML query selectors * * Examples: * tagname:first[attribute=value],secondtag > childtag * * Match nexttag preceded by previoustag: * previoustag + nexttag * * Attribute Matching * attribute=value (exact match) * attribute!=value (not equal) * attribute*=alu (contains 'alu') * attribute~=value (contains word) * attribute^=val (starts with) * attribute$=lue (ends with) * * @author Rockethemes.net * @since 1.1 * * @param string $query Formatted query string * @return array Structured query usable by find() **/ function parsequery ($query) { $patterns = $this->patterns(); extract($patterns); $queries = preg_split("/\s*,\s*/",$query,-1); foreach ($queries as &$query) { $query = preg_split("/\s*($delimiters)\s*/",$query,-1,PREG_SPLIT_DELIM_CAPTURE); foreach ($query as $i => &$q) { if (!preg_match("/^($tags)(?:$subselects)?((?:$attrs)*)$/",$q,$_)) continue; $q = array($_[1]); if (!empty($_[2])) { $q[1] = array($_[2],$_[3]); } if (!empty($_[4])) { preg_match_all("/$attrs/",$_[4],$a,PREG_SET_ORDER); $q[2] = $a; } } } return $queries; } /** * Returns a set of query patterns for centralized reference * * @author Rockethemes.net * @since 1.1 * * @return array Defined patterns **/ private function patterns () { $_ = array( 'tags' => '[\w0-9\.\-_]+', 'subselects' => '\\w+)(?:\((.+?)\))?', 'ops' => array( 'contains' => '\*=', 'containsword' => '~=', 'startswith' => '\^=', 'endswith' => '\$=', 'equal' => '=', 'notequal' => '!=' ), 'delimiters' => '[>\+ ]' ); $_['attrs'] = "\[(\w+)(".join('|',$_['ops']).")?(\w+)?\]"; return $_; } /** * Compares a source string with a search string using a given operation * * @author Rockethemes.net * @since 1.1 * * @param string $source The source to compare * @param string $op The operation to use * @param string $search The search string * @return boolean **/ private function match ($source,$op,$search) { switch ($op) { case "=": return ($source == $search); break; case "!=": return ($source != $search); break; case "*=": return (strpos($source,$search) !== false); break; case "~=": $words = explode(" ",$source); return (in_array($search,$words)); break; case "^=": return (substr_compare($source,$search,0,strlen($search)) == 0); break; case "$=": return (substr_compare($source,$search,strlen($search)*-1) == 0); break; } return false; } /** * Helper filter to find odd-number index array elements * * @author Rockethemes.net * @since 1.1 * * @param string $key Value of array index * @return boolean **/ private function _filter_odd ($key) { return ($key & 1); } /** * Helper filter to find even-number index array elements * * @author Rockethemes.net * @since 1.1 * * @param string $key Value of array index * @return boolean **/ private function _filter_even ($key) { return (!($key & 1)); } /** * Helper filter to find array indexes greater than a specified amount * * @author Rockethemes.net * @since 1.1 * * @param string $key Value of array index * @param string $value Value of array entry * @param string $filter The comparison amount * @return boolean **/ private function _filter_gt ($key,$value,$filter) { return ($key > $filter); } /** * Helper filter to find array indexes less than a specified amount * * @author Rockethemes.net * @since 1.1 * * @param string $key Value of array index * @param string $value Value of array entry * @param string $filter The comparison amount * @return boolean **/ private function _filter_lt ($key,$value,$filter) { return ($key < $filter); } /** * Uses a callback to filter arrays based on key/value pairs * * @author Rockethemes.net * @since 1.1 * * @param array $array The source array * @param array $callback The callback function name * @param string $filter The filter amount * @return array The filtered array **/ private static function array_key_filter ($array, $callback, $filter=false) { $_ = array(); foreach ($array as $key => $value) if (call_user_func($callback,$key,$value,$filter)) $_[$key] = $value; return $_; } } /** * DEPRECATED!! * * XMLdata * Reads XML data into associative arrays and outputs them back to valid XML * * Credits for the parsing, markup and insert functions: * http://mysrc.blogspot.com/2007/02/php-xml-to-array-and-backwards.html * * Adapted by Jon Davis, August 21, 2008 * Navigation functions developed by Jon Davis, August 21, 2008 */ class XMLdata { var $data = array(); function XMLdata ($data=false) { if (!is_array($data)) $this->parse($data); else $this->data = $data; return true; } /** * parse() * Parses a string of XML markup into an associative array */ function parse (&$string) { $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parse_into_struct($parser, $string, $vals, $index); xml_parser_free($parser); $data = array(); $working = &$data; foreach ($vals as $r) { $t=$r['tag']; if ($r['type'] == 'open') { if (isset($working[$t])) { if (isset($working[$t][0])) $working[$t][] = array(); else $working[$t]=array($working[$t], array()); $cv = &$working[$t][count($working[$t])-1]; } else $cv = &$working[$t]; if (isset($r['attributes'])) { foreach ($r['attributes'] as $k => $v) $cv['ATTRS'][$k] = $v; } $cv['CHILDREN'] = array(); $cv['CHILDREN']['_p'] = &$working; $working = &$cv['CHILDREN']; } elseif ($r['type']=='complete') { if (isset($working[$t])) { // same as open if (isset($working[$t][0])) $working[$t][] = array(); else $working[$t] = array($working[$t], array()); $cv = &$working[$t][count($working[$t])-1]; } else $cv = &$working[$t]; if (isset($r['attributes'])) { foreach ($r['attributes'] as $k => $v) $cv['ATTRS'][$k] = $v; } $cv['CONTENT'] = (isset($r['value']) ? $r['value'] : ''); } elseif ($r['type'] == 'close') { $working = &$working['_p']; } } $this->remove_p($data); $this->data = $data; return true; } /** * remove_p() * Removes recursive results in the tree */ private function remove_p(&$data) { foreach ($data as $k => $v) { if ($k === '_p') unset($data[$k]); elseif (is_array($data[$k])) $this->remove_p($data[$k]); } } /** * markup() * Uses recursion to build and returns XML-markup */ function markup ($data=false, $depth=0, $forcetag='') { if (!$data) $data = $this->data; $res=array('<?xml version="1.0" encoding="utf-8"?>'."\n"); foreach ($data as $tag=>$r) { if (isset($r[0])) { $res[]=$this->markup($r, $depth, $tag); } else { if ($forcetag) $tag=$forcetag; $sp=str_repeat("\t", $depth); $res[] = "$sp<$tag"; if (isset($r['ATTRS'])) { foreach ($r['ATTRS'] as $at => $av) $res[] = ' '.$at.'="'.htmlentities($av).'"'; } $res[] = ">".((isset($r['CHILDREN'])) ? "\n" : ''); if (isset($r['CHILDREN'])) $res[] = $this->markup($r['CHILDREN'], $depth+1); elseif (isset($r['CONTENT'])) $res[] = htmlentities($r['CONTENT']); $res[] = (isset($r['CHILDREN']) ? $sp : '')."</$tag>\n"; } } return implode('', $res); } /** * insert() * Inserts a new element into the data tree */ function insert ($element, $pos) { $working = array_slice($this->data, 0, $pos); $working[] = $element; $this->data = array_merge($working, array_slice($this->data, $pos)); } /** * add() * Adds a new element to the data tree as a child of the $target element */ function &add ($element,$target=false,$attrs=array(),$content=false) { $working = array(); $working[$element] = array(); if (!empty($attrs) && is_array($attrs)) $working[$element]['ATTRS'] = $attrs; if ($content) $working[$element]['CONTENT'] = $content; if ($target) { if (is_array($target)) $node = &$target; else $node =& $this->search($target,false,true); if (!isset($node['CHILDREN'])) $node['CHILDREN'][$element] = $working[$element]; else $node['CHILDREN'][$element] = $working[$element]; return $node['CHILDREN'][$element]; } else $this->data[$element] = $working[$element]; return $this->data[$element]; } /** * getRootElement() * Returns the root element of the tree */ function getRootElement () { reset($this->data); return current($this->data); } /** * getElementContent() * Searches the tree for the target $element and returns * the contents (the value between the tags) */ function getElementContent ($element) { $found = $this->search($element); if (!empty($found)) return $found[0]['CONTENT']; else return false; } /** * getElementAttrs() * Searches the tree for the target $element and returns * an associative array of attribute names and values (<tag attribute="value">) */ function getElementAttrs ($element) { $found = $this->search($element); if (!empty($found)) return $found[0]['ATTRS']; else return false; } /** * getElementAttr() * Searches the tree for the target $element and returns * value of a specific attribute for a specific element tag (<tag attribute="value">) */ function getElementAttr ($element,$attr) { $found = $this->search($element); if (!empty($found)) return $found[0]['ATTRS'][$attr]; else return false; } /** * getElement() * Searches the tree for the target $element and returns * an array of the element attributes, content and any children */ function getElement ($element) { $found = $this->search($element); if (!empty($found)) return $found[0]; else return false; } /** * getXMLElement() * Searches the tree for the target $element and returns * an array of the element attributes, content and any children */ function getXMLElement ($element) { $found = $this->search($element); if (!empty($found)) return new XMLdata($found[0]); else return false; } /** * getElements() * Searches the tree for the target $element and returns * an indexed array with each indice including matched elements * as associative arrays including the element attribtues, content * and any children */ function getElements($element) { return $this->search($element); } /** * search() * Helper function to perform recursive searches in the tree * for a $target and returns the structure */ private function search ($target,&$dom=false,$ref=false) { if (!$dom) $dom = &$this->data; if (!is_array($dom)) $dom = array($dom); $results = array(); foreach($dom as $key => &$element) { if (is_array($element) && $key == $target && $ref) return $element; if (is_array($element) && $key == $target) array_push($results,$element); if (isset($element['CHILDREN'])) { $found = &$this->search($target,$element['CHILDREN'],$ref); if ($ref) return $found; else $results += $found; } } return $results; } }
  9. This is the included XML class I am using. Maybe I can pull from here? https://github.com/stymiee/Authorize.Net-XML/blob/master/AuthnetXML.class.php Line 205 $this->response_xml = @new SimpleXMLElement($this->response); or line 216 return $this->response_xml->messages->resultCode == 'Ok';
  10. Well I thought it was fixed. It doesn't get the XML response back. I can echo it so I know its there. It just sends the values to Authorize.net The "charged" or "pending" status is just for local record keeping. If I leave both of those blank it still sends the data. So I need to revise the code to get that response code. What about reformatting this original function? Not sure what this is doing. function response ($buffer) { $_ = new stdClass(); list($_->code, $_->subcode, $_->reasoncode, $_->reason, $_->authcode, $_->avs, $_->transactionid, $_->invoicenum, $_->description, $_->amount, $_->method, $_->type, $_->customerid, $_->firstname, $_->lastname, $_->company, $_->address, $_->city, $_->state, $_->zip, $_->country, $_->phone, $_->fax, $_->email, $_->ship_to_first_name, $_->ship_to_last_name, $_->ship_to_company, $_->ship_to_address, $_->ship_to_city, $_->ship_to_state, $_->ship_to_zip, $_->ship_to_country, $_->tax, $_->duty, $_->freight, $_->taxexempt, $_->ponum, $_->md5hash, $_->cvv2code, $_->cvv2response) = explode(",",$buffer); return $_; }
  11. I tried something like this $i = 1; foreach($Order->Cart->contents as $Item) { $lineItems[] = array ( 'lineItem' => array( 'itemId' => $i++, 'name' => $Item->name, 'quantity' => $Item->quantity, 'unitPrice' => number_format($Item->unitprice,$this->precision,'.','')//format to 1.00 ) ); } $xml->createCustomerProfileTransactionRequest(array( 'transaction' => array( 'profileTransAuthCapture' => array( 'amount' => $Order->Cart->Totals->total ), 'lineItems' => $lineItems, //changed this line 'customerProfileId' => '135', 'customerPaymentProfileId' => '186', 'customerShippingAddressId' => '120', 'order' => array( 'invoiceNumber' => 'IN8', 'description' => 'description of transaction', 'purchaseOrderNumber' => 'PO4' ), 'taxExempt' => 'false', 'recurringBilling' => 'false', 'cardCode' => '000' ) ); But it outputs this. There should only be one opening <lineItems> and one closing </lineItems> I am getting cose. <lineItems> <lineItem> <itemId>1</itemId> <name>widget name</name> <quantity>3</quantity> <unitPrice>5.00</unitPrice> </lineItem> </lineItems> <lineItems> <lineItem> <itemId>2</itemId> <name>widget 2 name</name> <quantity>4</quantity> <unitPrice>6.00</unitPrice> </lineItem> </lineItems>
  12. Any other ideas I could try?
  13. Ok it was a simple fix. Everything depends on this response code. code == '1' it creates the account and saves the order with "charged" as status. code == '4' creates the account and saves it with "pending" as status. The problem was the new codes are I001 and something else for pending. So it never was either one of these. I fooled it by leaving the code value for the pending transaction and it worked. I just need to find out what the corresponding code is for a pending transaction.
  14. Below are two blocks of code. The first one is the original. The second one is my revised version. I am working on a shopping cart. This is the gateway to interact with Authorize.net. Its working but now I have to fine tune it. The first hurdle is getting the response code back from Authorize.net. echo $xml->messages->resultCode; will give me the code I need and print it on screen. Since the cart is not getting the response code, it fails to record the purchase and save the order in the database. It sends the XML but the two parts don't speak to each other. Original code: class AuthorizeNet extends GatewayFramework implements GatewayModule { var $cards = array("visa", "mc", "amex", "disc", "jcb", "dc"); var $liveurl = 'https://secure.authorize.net/gateway/transact.dll'; var $testurl = 'https://secure.authorize.net/gateway/transact.dll'; function AuthorizeNet () { parent::__construct(); $this->setup('login','password','testmode'); } function actions () { add_action('mycart_process_order',array(&$this,'process')); } function process () { $transaction = $this->build(); $Response = $this->send($transaction); if ($Response->code == '1') { // success $this->Order->transaction($this->txnid($Response),'CHARGED'); return; } elseif ($Response->code == '4') { // flagged for merchant review or risk management $this->Order->transaction($this->txnid($Response),'PENDING'); return; } else $this->error($Response); } function txnid ($Response) { if (empty($Response->transactionid)) return parent::txnid(); return $Response->transactionid; } function error ($Response) { return new MycartError($Response->reason,'authorize_net_error',MYCART_TRXN_ERR, array('code'=>$Response->reasoncode)); } function build () { $Order = $this->Order; $_ = array(); // Options $_['x_test_request'] = ($this->settings['testmode'] == "on")?"TRUE":"FALSE"; // Set "TRUE" while testing $_['x_login'] = $this->settings['login']; $_['x_password'] = $this->settings['password']; $_['x_Delim_Data'] = "TRUE"; $_['x_Delim_Char'] = ","; $_['x_Encap_Char'] = ""; $_['x_version'] = "3.1"; $_['x_relay_response'] = "FALSE"; $_['x_type'] = "AUTH_ONLY"; //= "AUTH_CAPTURE"; $_['x_method'] = "CC"; $_['x_email_customer'] = "FALSE"; $_['x_merchant_email'] = $this->settings['merchant_email']; // Required Fields $_['x_amount'] = $Order->Cart->Totals->total; $_['x_customer_ip'] = $_SERVER["REMOTE_ADDR"]; $_['x_fp_sequence'] = mktime(); $_['x_fp_timestamp'] = time(); // $_['x_fp_hash'] = hash_hmac("md5","{$_['x_login']}^{$_['x_fp_sequence']}^{$_['x_fp_timestamp']}^{$_['x_amount']}",$_['x_password']); // Customer Contact $_['x_first_name'] = $Order->Customer->firstname; $_['x_last_name'] = $Order->Customer->lastname; $_['x_email'] = $Order->Customer->email; $_['x_phone'] = $Order->Customer->phone; // Billing $_['x_card_num'] = $Order->Billing->card; $_['x_exp_date'] = date("my",$Order->Billing->cardexpires); $_['x_card_code'] = $Order->Billing->cvv; $_['x_address'] = $Order->Billing->address; $_['x_city'] = $Order->Billing->city; $_['x_state'] = $Order->Billing->state; $_['x_zip'] = $Order->Billing->postcode; $_['x_country'] = $Order->Billing->country; // Shipping $_['x_ship_to_first_name'] = $Order->Customer->firstname; $_['x_ship_to_last_name'] = $Order->Customer->lastname; $_['x_ship_to_address'] = $Order->Shipping->address; $_['x_ship_to_city'] = $Order->Shipping->city; $_['x_ship_to_state'] = $Order->Shipping->state; $_['x_ship_to_zip'] = $Order->Shipping->postcode; $_['x_ship_to_country'] = $Order->Shipping->country; // Transaction $_['x_freight'] = $Order->Cart->Totals->shipping; $_['x_tax'] = $Order->Cart->Totals->tax; // Line Items $i = 1; foreach($Order->Cart->contents as $Item) { $_['x_line_item'][] = ($i++)."<|>".substr($Item->name,0,31)."<|>".((sizeof($Item->options) > 1)?" (".substr($Item->option->label,0,253).")":"")."<|>".(int)$Item->quantity."<|>".number_format($Item->unitprice,$this->precision,'.','')."<|>".(($Item->tax)?"Y":"N"); } return $this->encode($_); } function send ($data) { if ($this->settings['testmode'] == "on") $url = $this->testurl; else $url = $this->liveurl; $url = apply_filters('mycart_authorize_net_url',$url); return $this->response(parent::send($data,$url)); } function response ($buffer) { $_ = new stdClass(); list($_->code, $_->subcode, $_->reasoncode, $_->reason, $_->authcode, $_->avs, $_->transactionid, $_->invoicenum, $_->description, $_->amount, $_->method, $_->type, $_->customerid, $_->firstname, $_->lastname, $_->company, $_->address, $_->city, $_->state, $_->zip, $_->country, $_->phone, $_->fax, $_->email, $_->ship_to_first_name, $_->ship_to_last_name, $_->ship_to_company, $_->ship_to_address, $_->ship_to_city, $_->ship_to_state, $_->ship_to_zip, $_->ship_to_country, $_->tax, $_->duty, $_->freight, $_->taxexempt, $_->ponum, $_->md5hash, $_->cvv2code, $_->cvv2response) = explode(",",$buffer); return $_; } function settings () { $this->ui->cardmenu(0,array( 'name' => 'cards', 'selected' => $this->settings['cards'] ),$this->cards); $this->ui->text(1,array( 'name' => 'login', 'value' => $this->settings['login'], 'size' => '16', 'label' => __('Enter your AuthorizeNet Login ID.','Mycart') )); $this->ui->password(1,array( 'name' => 'password', 'value' => $this->settings['password'], 'size' => '24', 'label' => __('Enter your AuthorizeNet Password or Transaction Key.','Mycart') )); $this->ui->checkbox(1,array( 'name' => 'testmode', 'checked' => $this->settings['testmode'], 'label' => __('Enable test mode','Mycart') )); } } // END class AuthorizeNet New version of code: See the build() function. It sends the XML which sends the data to Authorize.net require('config.inc.php'); require('AuthnetXML.class.php'); class AuthorizeNet extends GatewayFramework implements GatewayModule { var $cards = array("visa", "mc", "amex", "disc", "jcb", "dc"); function AuthorizeNet () { parent::__construct(); $this->setup('login','password','testmode'); } function actions () { add_action('mycart_process_order',array(&$this,'process')); } function process () { $transaction = $this->build(); $Response = $this->send($transaction); if ($Response->code == '1') { // success $this->Order->transaction($this->txnid($Response),'CHARGED'); return; } elseif ($Response->code == '4') { // flagged for merchant review or risk management $this->Order->transaction($this->txnid($Response),'PENDING'); return; } else $this->error($Response); } function build () { $Order = $this->Order; $i = 1; foreach ($Order->Cart->contents as $Item) { $lineItems[] = array ( 'itemId' => $i++, 'name' => $Item->name, 'quantity' => $Item->quantity, 'unitPrice' => number_format($Item->unitprice,$this->precision,'.','') ); } $whatIWant = '\'lineItems\' = ' . var_export($lineItems, 1) ; $xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY, AuthnetXML::USE_DEVELOPMENT_SERVER); $xml->createCustomerProfileTransactionRequest(array( 'transaction' => array( 'profileTransAuthCapture' => array( 'amount' => $Order->Cart->Totals->total, 'tax' => array( 'amount' => '1.00', 'name' => 'state sales tax', 'description' => 'Desc state sales tax' ), 'lineItems' => array( 0 => array( 'itemId' => '1', 'name' => 'widget 1', 'description' => 'Description of widget 1', 'quantity' => '2', 'unitPrice' => '5.00' ), 1 => array( 'itemId' => '2', 'name' => 'widget 2', 'description' => 'Description of widget 2', 'quantity' => '1', 'unitPrice' => '5.00' ) ), 'customerProfileId' => '129', 'customerPaymentProfileId' => '119', 'customerShippingAddressId' => '120', 'order' => array( 'invoiceNumber' => 'INV', 'description' => 'description of transaction', 'purchaseOrderNumber' => 'P03' ), 'taxExempt' => 'false', 'recurringBilling' => 'false', 'cardCode' => '000' ) ), ) ); echo $xml->messages->resultCode; echo $xml->messages->message->code; echo $xml; echo $xml->validationMode; } function send ($data) { if ($this->settings['testmode'] == "on") $url = $this->testurl; else $url = $this->liveurl; $url = apply_filters('mycart_authorize_net_url',$url); return $this->response(parent::send($data,$url)); } function settings () { $this->ui->cardmenu(0,array( 'name' => 'cards', 'selected' => $this->settings['cards'] ),$this->cards); $this->ui->text(1,array( 'name' => 'login', 'value' => $this->settings['login'], 'size' => '16', 'label' => __('Enter your AuthorizeNet Login ID.','Mycart') )); $this->ui->password(1,array( 'name' => 'password', 'value' => $this->settings['password'], 'size' => '24', 'label' => __('Enter your AuthorizeNet Password or Transaction Key.','Mycart') )); $this->ui->checkbox(1,array( 'name' => 'testmode', 'checked' => $this->settings['testmode'], 'label' => __('Enable test mode','Mycart') )); } } // END class AuthorizeNet I need to find a way for it to use the value of echo $xml->messages->resultCode
  15. $whatIWant = '\'lineItems\' = ' . htmlspecialchars_decode(var_export($lineItems, 1),ENT_QUOTES) ; Tried this
  16. I have tried $whatIWant = '\'lineItems\' = ' . html_entity_decode(var_export($lineItems, 1)) ;
  17. I have tried this also. $whatIWant = '\'lineItems\' = ' . htmlentities(var_export($lineItems, 1)) ;
  18. Yes it wants it just like this. Sorry had a couple typos. See post #3 for what it should look like for the items. I have used a hard coded version before and have successfully submitted the XML. <transaction>'lineItems' = array ( 0 => array ( 'itemId' => '1', 'name' => 'Some Widget', 'quantity' => '1', 'unitPrice' => '1', ),
  19. Sorry maybe my previous post was not clear. Its returning the XML and showing that line items. Its just the formatting of the > that I need fixed. <?xml version="1.0"?> <createCustomerProfileTransactionRequest> <merchantAuthentication> <name>xxx</name> <transactionKey>xxx</transactionKey> </merchantAuthentication> <transaction>'lineItems' = array ( 0 => array ( 'itemId' => 1, 'name' => 'Some Widget', 'quantity' => '1', 'unitPrice' => 1, ), )</transaction> Should be returned as: <?xml version="1.0"?> <createCustomerProfileTransactionRequest> <merchantAuthentication> <name>xxx</name> <transactionKey>xxx</transactionKey> </merchantAuthentication> <transaction>'lineItems' = array ( 0 => array ( 'itemId' => 1, 'name' => 'Some Widget', 'quantity' => '1', 'unitPrice' => 1, ), )</transaction>
  20. Its converting the > symbol to => I tried htmlspecialchars($whatIWant,ENT_COMPAT, 'UTF-8') and htmlspecialchars($whatIWant, ENT_QUOTES, 'UTF-8')
  21. <?xml version="1.0"?> <createCustomerProfileTransactionRequest> <merchantAuthentication> <name>xxx</name> <transactionKey>xxx</transactionKey> </merchantAuthentication> <transaction>'lineItems' = array ( 0 => array ( 'itemId' => 1, 'name' => 'Some Widget', 'quantity' => '1', 'unitPrice' => 1, ), )</transaction> The error is : The element 'transaction' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' cannot contain text.
  22. <?xml version="1.0"?> <createCustomerProfileTransactionRequest> <merchantAuthentication> <name>xxx</name> <transactionKey>xxx</transactionKey> </merchantAuthentication> <transaction>'lineItems' = array ( 0 => array ( 'itemId' => 1, 'name' => 'Some Widget', 'quantity' => '1', 'unitPrice' => 1, ), )</transaction> The error is : The element 'transaction' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' cannot contain text.
  23. I edited this line adding \ ran and echoed the results outside of the main script and it looked correct. So that's a start. $whatIWant = '\'lineItems\' = ' . var_export($lineItems, 1) ; I am getting an error when I process the script saying text is not allowed. It seems to not like the echo$whatIWant inthe middle of the script.
  24. $i = 1; foreach($Order->Cart->contents as $Item) { $lineItems[] = array ( 'itemId' => $i++, 'name' => $Item->name, 'quantity' => $Item->quantity, 'unitPrice' => $Item->unitprice ); } $whatIWant = 'lineItems = ' . var_export($lineItems, 1) $xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY, AuthnetXML::USE_DEVELOPMENT_SERVER); $xml->createCustomerProfileTransactionRequest(array( 'transaction' => array( 'profileTransAuthCapture' => array( 'amount' => '10.95', 'tax' => array( 'amount' => '1.00', 'name' => 'state sales tax', 'description' => 'your state sales tax' ), 'shipping' => array( 'amount' => '2.00', 'name' => 'ground based shipping', 'description' => 'Ground based 5 to 10 day shipping' ), echo $whatIWant; ), 'customerProfileId' => '345', 'customerPaymentProfileId' => '675', 'customerShippingAddressId' => '453', 'order' => array( 'invoiceNumber' => 'INV000001', 'description' => 'description of transaction', 'purchaseOrderNumber' => '000001' ), 'taxExempt' => 'false', 'recurringBilling' => 'false', 'cardCode' => '000' ) ), 'extraOptions' => '<![CDATA[x_customer_ip=100.0.0.1]]>' )); Like this?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.