Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 35
  1. #1
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Editing a payment gateway

    I have this code. I am able to send the XML and process the payment to Authorize.net But I can't get it to give me status errors in the message box.

    PHP Code:
        var $cards = array("visa""mc");
        var 
    $status = array("1" => "CHARGED","4" => "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('messages');
            
            
            if (
    $status == "1" || $status == "4") { 
            
                 
    $message $Response->getElementContent('code');
                
    $code $Response->getElementContent('resultCode');
                
                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 = new AuthnetXML(AUTHNET_LOGINAUTHNET_TRANSKEYAuthnetXML::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(
                        
    => array(
                            
    'itemId' => '1',
                            
    'name' => 'vase',
                            
    'description' => 'widget 1',
                            
    'quantity' => '18',
                            
    'unitPrice' => '45.00'
                        
    ),
                        
    => array(
                            
    'itemId' => '2',
                            
    'name' => 'widget 2',
                            
    'description' => 'widget ',
                            
    'quantity' => '10',
                            
    'unitPrice' => '85.00'
                        
    )
                    ),
                    
    'customerProfileId' => '129',
                    
    'customerPaymentProfileId' => '119',
                    
    'customerShippingAddressId' => '120',
                    
    'order' => array(
                        
    'invoiceNumber' => 'INV13',
                        
    'description' => 'description of transaction',
                        
    'purchaseOrderNumber' => 'PON13'
                    
    ),
                    
    'taxExempt' => 'false',
                    
    'recurringBilling' => 'false',
                    
    'cardCode' => '000'
                
    )
            ),
         
            
        ));

     }    

        
        
        
    function 
    send ($message) {
            
    $url 'https://apitest.authorize.net/xml/v1/request.api' ;
            
    $url2 apply_filters('mycart_authorize_net_url',$url2);
            
    $response parent::send($message,$url2);
            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 

  • #2
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    What do these dots represent?

    PHP Code:
    $response parent::send($message,$url); 

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    That's the paamayim nekudotayim operator. And yes I'm dead serious.
    In non-hebrew speak, that's double colon which is the scope resolution operator. It dereferences a scope other than where you are, such as in this case you are going to the parent class to call the send message. This code you have was written for PHP 4.x version, but in 5.x there are two more scope resolutions which as self and static. It is also used when calling a static method.
    You'll need to clarify the problem itself on your OP. What message box are you referring to, something in the HTML? Do you know if you receive the error code's back from the initial communication?
    This here looks wrong: $url2 = apply_filters('mycart_authorize_net_url',$url2); . The problem is you are returning a result from apply_filters, but I don't know why the $url2 is used as the second argument. Typically with this type of behaviour (since the $url2 called as the second argument does not exist at that point), would indicate that this is a by-reference return result, and not one that returns. But I cannot confirm that is the case with what you have here.

    I would assume your actual problem is coming from here:
    PHP 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; 
    For the first one, I don't know what function __ is. _ is chained to getText, but __ doesn't exist in PHP. Presumably its an actual working function, but I don't know the purpose. Assuming its job is also similar to getText, there's not a lot of relevance to the problem at hand.
    The issue with the above is where does a new MyCartError go? From what I see, no where. It may be an extension of something which in turn is using a singleton which is hooked into something, but with the little information I see here it doesn't have a method of hooking into anything else.
    So what you need to do is start by verifying that you do reach this block when there is a problem with the transaction results:
    PHP Code:
            if ($status == "1" || $status == "4") { 
            
                 
    $message $Response->getElementContent('code');
                
    $code $Response->getElementContent('resultCode');
                
                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;
            } 
    Use simple prints or file logging. When you verify that you get down to that second mycarterror call, and the $message is as expected, than the problem is from the use of new MyCartError not going anywhere.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    mallen2 (03-26-2013)

  • #4
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you Fou-LU for replling. You are the first in over 120 views. Let me first say this is using WordPress.

    I tried to echo some of the values and also did var_dump() but they were NULL. The $URL2 part I accidentally left in there. I have tried may different things to get results.

    $status = $Response->getElementContent('messages'); always was empty so it printed that error "A configuration error occurred while processing this ...."

    The error messages get fed to MYCART_TRXN_ERR. That is what I referred to as the message box.

    There is a back end part of the store that tracks the purchases. Next to each one it lists if it was PENDING or PURCHASED and records the tranaction ID. I think $txnstatus = $this->status[$status]; this section saves the purchases. But as I have it now it just takes the values, sends them in XML to Authorize.Net and bypasses the whole system.

    How can I do file logging? What other ways can I get more errors or results to show?

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You can use the error_log function to log an error to a file (or any details you want). This is testing code though, so you can just print to the screen.
    In your send method before the return, issue a var_dump($response);. What's in there? If that turns up as a string of 0 length, issue a var_dump($this); and see what's in there instead.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    This is what I have now. I added the var_dump($Response) I had to leave the value of $status empty for it to print put anything.
    Code:
    object(XMLdata)#125 (1) { 
    ["data"]=> array(1) { 
    ["ErrorResponse"]=> array(2) 
    { ["ATTRS"]=> array(3) 
    { ["xmlns:xsi"]=> string(41) "http://www.w3.org/2001/XMLSchema-instance" ["xmlns:xsd"]=> string(32) "http://www.w3.org/2001/XMLSchema" ["xmlns"]=> string(39) "AnetApi/xml/v1/schema/AnetApiSchema.xsd" } ["CHILDREN"]=> array(1) 
    { ["messages"]=> array(1) 
    { ["CHILDREN"]=> array(2) 
    { ["resultCode"]=> array(1) 
    { ["CONTENT"]=> string(5) "Error" } ["message"]=> array(1) 
    { ["CHILDREN"]=> array(2) 
    { ["code"]=> array(1) 
    { ["CONTENT"]=> string(6) "E00002" } ["text"]=> array(1) 
    { ["CONTENT"]=> string(44) "The content-type specified is not supported." } } } } } } } } }

    PHP Code:
    require('/../../core/model/XML.php');
    require(
    'config.inc.php');
    require(
    'AuthnetXML.class.php');
    class 
    AuthorizeNet extends GatewayFramework implements GatewayModule {

        var 
    $cards = array("visa""mc");
        var 
    $status = array("1" => "CHARGED","" => "PENDING");
        var 
    $liveurl "https://apitest.authorize.net/xml/v1/request.api/"
        var 
    $secure true;

        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('directResponse'); //or messages, resultCode, responseCode, code, directResponse, transaction
            
            
    if ($status == "" ){  //made empty to throw error
        
                
    $message $Response->getElementContent('code');// messages, message, responseCode
                
    $code $Response->getElementContent('resultCode');
                
                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));
                    
    var_dump($Response); //added
                    
    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 = new AuthnetXML(AUTHNET_LOGINAUTHNET_TRANSKEYAuthnetXML::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(
                        
    => array(
                            
    'itemId' => '1',
                            
    'name' => 'widget 1',
                            
    'description' => 'widget',
                            
    'quantity' => '18',
                            
    'unitPrice' => '45.00'
                        
    ),
                        
    => array(
                            
    'itemId' => '2',
                            
    'name' => 'widget',
                            
    'description' => 'widget 2',
                            
    'quantity' => '10',
                            
    'unitPrice' => '85.00'
                        
    )
                    ),
                    
    'customerProfileId' => '129',
                    
    'customerPaymentProfileId' => '119',
                    
    'customerShippingAddressId' => '120',
                    
    'order' => array(
                        
    'invoiceNumber' => 'INV23',
                        
    'description' => 'description of transaction',
                        
    'purchaseOrderNumber' => 'PON23'
                    
    ),
                    
    'taxExempt' => 'false',
                    
    'recurringBilling' => 'false',
                    
    'cardCode' => '000'
                
    )
            ),
        
            
        ));

     }    


        
        
    function 
    send ($message) {
           
            
    $url 'https://apitest.authorize.net/xml/v1/request.api';
            
    $url apply_filters('mycart_authorize_net_url',$url);
            
    $response parent::send($message,$url);
            return new 
    XMLdata($response);
        }

    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 
    $_;
        } 

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You're var_dump'n where you shouldn't be, hence the need to alter the code. That's not a big deal overall though.
    Can you drag that dump out from the HTML source please (or wrap it in <pre> tags). It's not easy to read it when everything is left justified.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    <pre>
    object(XMLdata)#125 (1) { ["data"]=> array(1) { ["ErrorResponse"]=> array(2) { ["ATTRS"]=> array(3) { ["xmlns:xsi"]=> string(41) "http://www.w3.org/2001/XMLSchema-instance" ["xmlns:xsd"]=> string(32) "http://www.w3.org/2001/XMLSchema" ["xmlns"]=> string(39) "AnetApi/xml/v1/schema/AnetApiSchema.xsd" } ["CHILDREN"]=> array(1) { ["messages"]=> array(1) { ["CHILDREN"]=> array(2) { ["resultCode"]=> array(1) { ["CONTENT"]=> string(5) "Error" } ["message"]=> array(1) { ["CHILDREN"]=> array(2) { ["code"]=> array(1) { ["CONTENT"]=> string(6) "E00002" } ["text"]=> array(1) { ["CONTENT"]=> string(44) "The content-type specified is not supported." } } } } } } } } }
    </pre>

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    No, not the pre-tags here, those would have to go around the output in your source.
    Better yet, use a var_export for the data. That will construct a variable that I can inspect.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #10
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Code:
     XMLdata::__set_state(array(
       'data' => 
      array (
        'ErrorResponse' => 
        array (
          'ATTRS' => 
          array (
            'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
            'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
            'xmlns' => 'AnetApi/xml/v1/schema/AnetApiSchema.xsd',
          ),
          'CHILDREN' => 
          array (
            'messages' => 
            array (
              'CHILDREN' => 
              array (
                'resultCode' => 
                array (
                  'CONTENT' => 'Error',
                ),
                'message' => 
                array (
                  'CHILDREN' => 
                  array (
                    'code' => 
                    array (
                      'CONTENT' => 'E00002',
                    ),
                    'text' => 
                    array (
                      'CONTENT' => 'The content-type specified is not supported.',
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    ))
    E00002 is a Authorize.net CIM response - The content-type specified is not supported. The only supported content-types are text/xml and application/xml.

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    That's okay though right? That's what you're trying to capture for the errors? I assume that you can get it to work properly, but the problem you're having is capturing the errors?
    You'll need to post the XMLData class. I don't know how it traverses this since its not actually XML, but you need to get into the messages/message/code and content blocks. You may need to check with the authorize.net api for what exactly it returns on the call; a schema would be handy assuming its xml.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #12
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ok. The XML that is sent to Authorize.net is correct because it gets entered into my account there. I think the problem is this class is reading that XML and that is where the translation problem is.

    PHP Code:
    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;
        }

        
        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;
        }


        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;
        }

        
        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]);
            }
        }

        
        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('', $_);
        }

        
        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;
        }

        
        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 $_;
        }

        
        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;
        }

        
        function get ($index=0) {
            if (isset($this->dom[$index]))
                return new xmlQuery($this->dom[$index]);
            return false;
        }

        
        function context () {
            reset($this->dom);
            $context = key($this->dom);
            if (empty($context)) return false;
            else return $context;
        }


        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;
        }

        
        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 $_;

        }

        
        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;
        }

        
        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;
        }


        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 $_;

        }

        
        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;
        }

        
        private function patterns () {
            $_ = array(
                'tags' => '[\w0-9\.\-_]+',
                'subselects' => '\:(\w+)(?:\((.+?)\))?',
                'ops' => array(
                    'contains' => '\*=',
                    'containsword' => '~=',
                    'startswith' => '\^=',
                    'endswith' => '\$=',
                    'equal' => '=',
                    'notequal' => '!='
                ),
                'delimiters' => '[>\+ ]'
            );
            $_['attrs'] = "\[(\w+)(".join('|',$_['ops']).")?(\w+)?\]";

            return $_;
        }

        
        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;
        }

        
        private function _filter_odd ($key) {
            return ($key & 1);
        }

        
        private function _filter_even ($key) {
            return (!($key & 1));
        }

        
        private function _filter_gt ($key,$value,$filter) {
            return ($key > $filter);
        }

        
        private function _filter_lt ($key,$value,$filter) {
            return ($key < $filter);
        }

        
        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 $_;
        }

    }



    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;
        }

    }

  • #13
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    See here on line 60 -72 that is what a sample response looks like. I have printed my XML response. So the message system just isn't interpreting this back.

    https://github.com/stymiee/Authorize...uthCapture.php

  • #14
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Lets go back to post #5.
    What is the results of modifying the send method and adding var_dump($response); before the return?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #15
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    If I do the var_dump() in this section

    PHP 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);
                    
    var_dump($Response);
                    return; 
    I get "The content-type specified is not supported."


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •