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. Link to comment https://forums.phpfreaks.com/topic/276296-help-using-explode/ 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 ? Link to comment https://forums.phpfreaks.com/topic/276296-help-using-explode/#findComment-1421837 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 Link to comment https://forums.phpfreaks.com/topic/276296-help-using-explode/#findComment-1421838 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 Link to comment https://forums.phpfreaks.com/topic/276296-help-using-explode/#findComment-1421841 Share on other sites More sharing options...
mallen Posted March 29, 2013 Author Share Posted March 29, 2013 $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] . "; Link to comment https://forums.phpfreaks.com/topic/276296-help-using-explode/#findComment-1421843 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; Link to comment https://forums.phpfreaks.com/topic/276296-help-using-explode/#findComment-1421844 Share on other sites More sharing options...
Jessica Posted March 30, 2013 Share Posted March 30, 2013 What do you get when you DO echo it? or better yet, use var_dump? Link to comment https://forums.phpfreaks.com/topic/276296-help-using-explode/#findComment-1421881 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? Link to comment https://forums.phpfreaks.com/topic/276296-help-using-explode/#findComment-1422253 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 Link to comment https://forums.phpfreaks.com/topic/276296-help-using-explode/#findComment-1422295 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 Link to comment https://forums.phpfreaks.com/topic/276296-help-using-explode/#findComment-1422317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.