mallen Posted March 29, 2013 Share Posted March 29, 2013 I am trying to record a part of this string. Should I format this some other way? 1,1,1,some text here,ABCD,Y,55678759949,FGRTUD <<<string $split = explode(',', $xml->directResponse[6]); $txnid = $split[6]; $txnid should equal '55678759949' but it doesn't like that format for some reason. If I put $txnid ="1234"; my page will save it with that value. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 29, 2013 Share Posted March 29, 2013 $string = "1,1,1,some text here,ABCD,Y,55678759949,FGRTUD"; $split = explode(',', $string); $txnid = $split[6]; echo $txnid; //--> 55678759949 your problem is ? Quote Link to comment Share on other sites More sharing options...
mallen Posted March 29, 2013 Author Share Posted March 29, 2013 Thanks Actually the string comes from a XML reply <directResponse>1,1,1,some text here,ABCD,Y,55678759949,FGRTUD</directResponse> If I echo $xml->directResponse I will get 1,1,1,some text here,ABCD,Y,55678759949,FGRTUD I need $txnid to hold the value of 55678759949 Quote Link to comment Share on other sites More sharing options...
Barand Posted March 29, 2013 Share Posted March 29, 2013 $split = explode(',', $xml->directResponse); $txnid = $split[6]; echo $txnid; //--> 55678759949 Quote Link to comment Share on other sites More sharing options...
mallen Posted March 29, 2013 Author Share Posted March 29, 2013 (edited) $split = explode(',', $xml->directResponse[6]); $txnid = $split[6]; echo $txnid; //I don't need to echo it. I tried that also tried this. I need to assign the value to $txnid. If I hard code a value in there like $txnid = "123456" my shopping cart will save it like that. Anything else will fail. So maybe the value needs a function around it. $txnid = "55678759949" ; //shopping cart will use it and save it $txnid = $split[6]; // doesn't work maybe something like $txnid = " .$split[6] . "; Edited March 29, 2013 by mallen Quote Link to comment Share on other sites More sharing options...
Barand Posted March 29, 2013 Share Posted March 29, 2013 try casting it as string $split = explode(',', (string)$xml->directResponse); $txnid = $split[6]; echo $txnid; Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 30, 2013 Share Posted March 30, 2013 (edited) What do you get when you DO echo it? or better yet, use var_dump? Edited March 30, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
mallen Posted April 1, 2013 Author Share Posted April 1, 2013 I get NULL. Since $xml->directResponse is in a different method but the same class would this make a difference? Quote Link to comment Share on other sites More sharing options...
mallen Posted April 1, 2013 Author Share Posted April 1, 2013 I have a variable scope problem. I need to be able to access $xml in the process() method. class AuthorizeNet extends GatewayFramework implements GatewayModule { var $cards = array("visa", "mc"); var $status = array("1" => "CHARGED","4" => "PENDING"); public $xml; public $splitted; public $txnstatus; 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 = $splitted[0]; if ($status == "2" || $status == "4"){ $message = $xml->messages->message->code; $code = $splitted[0]; 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($xml->messages->message->code,'authnet_error',MYCART_TRXN_ERR); var_dump($xml->messages->message->code); return; } var_dump($xml->directResponse[6]);echo "\n<br />\n"; $splitted = explode(',', $xml->directResponse[0]); //var_dump($this->$splitted);echo "\n<br />\n"; //echo var_dump($this->$splitted[6]);echo "\n<br />\n"; $txnid = $splitted[6]; var_dump($txnid);echo "\n<br />\n"; $txnstatus = $xml->messages->resultCode; / $Mycart->Order->transaction($txnid,$txnstatus); } function build () { $Order = $this->Order; $xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY, AuthnetXML::USE_DEVELOPMENT_SERVER); $xml->createCustomerProfileTransactionRequest(array( )); echo "Response: " . $xml->messages->message->code . "<br><br>"; echo "Code: " . $xml->messages->resultCode . "<br><br>"; echo "Text: " . $xml->messages->message->text . "<br><br>"; $splitted = explode(',', $xml->directResponse[0]); echo "Direct Code: " . $splitted[0] . "<br><br>"; echo "Dir Response: " . $xml->directResponse. "<br><br>"; echo "TXID: " . $splitted[6] . "<br><br>"; //Successful //echo "Direct Response: " . $xml->directResponse[0] . "<br><br>"; echo "Transaction ID: " . $splitted[6] . "<br><br>"; var_dump($splitted[6]); echo "Raw request: " . $xml . "<br><br>"; //echo "Raw response: " . $response->customerProfileId . "<br><br>"; return $xml;//end function } function send ($message) { // $url = $this->url();//added $url = 'https://apitest.authorize.net/xml/v1/request.api'; $url = apply_filters('mycart_authorize_net_url',$url); } } // END class AuthorizeNet Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 1, 2013 Share Posted April 1, 2013 function AuthorizeNet ($xml) { parent::__construct(); $this->setup('login','password','testmode'); $this->xml = $xml; }Then use $this->xml Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.