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 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 35
  1. #16
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Sorry I tried to edit my last reply. I don't get any response from the dump, just this inside the page as expected where is displays there errors. "The content-type specified is not supported."

  2. #17
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    That's still not correct, you need to do this in the send method not the process method:
    PHP Code:
    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);
            
    var_export($response);
            return new 
    XMLdata($response);
        } 
    We need to capture the $response before the XMLData gets it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  3. #18
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    This is the HTML I got back.
    Code:
     '<?xml version="1.0" encoding="utf-8"?><ErrorResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><messages><resultCode>Error</resultCode><message><code>E00002</code><text>The content-type specified is not supported.</text></message></messages></ErrorResponse>'

  4. #19
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    My thought is it might be because $xml->createCustomerProfileTransactionRequest
    which is in the build() function is what is actually getting sent. What do you think?

  5. #20
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Going through the XMLData class, you can recursively pick off by just specifying the name. So to get an error, you can check if it contains an item called ErrorResponse, or pick out what you need from the code. A simple check would be:
    PHP Code:
    if (!empty($Response->getElement('ErrorResponse')))
    {
        
    // There's an error here.  You can pick it out using getElementContent('text'), or evaluate each 'code' to see what it was

    If its not empty, than you have according to the text on the github link, a createCustomerProfileTransactionResponse item when you fetch from getElement[Content]. You can get the code or the directResponse from that.
    So:
    PHP Code:
    if (!empty($Response->getElement('ErrorResponse'))
    {
        
    // construct your message box with the value of $Response->getElementContent('text')
    }
    else if (!empty(
    $Response->getElement('createCustomerProfileTransactionResponse')))
    {
       
    // this has something back, create a message box with the value of $Response->getElementContent('text');
    }
    else
    {
        
    // some other problem has occurred for which I don't have a definition to create, or there is no definition to work with

    That answer what you're looking for?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  6. #21
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Something like this?

    PHP Code:
        function process () {
            global 
    $Mycart;
            
    $message $this->build();
            
    $Response $this->send($message);
            
    $status $Response->getElementContent('directResponse'); //or messages, resultCode, responseCode, code, directResponse, transaction
            
            
    if ($status == "2" || $status == "3"){ 
        
                
    $message $Response->getElementContent('text');//code, text,  messages, message, responseCode
                
    $code $Response->getElementContent('code');//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;
                }
                
            
                if (!empty(
    $Response->getElement('ErrorResponse')))
                {
                
    // There's an error here.  You can pick it out using getElementContent('text'), or evaluate each 'code' to see what it was
                
    }

                if (!empty(
    $Response->getElement('ErrorResponse'))
                {
                    
                    new 
    MycartError($Response->getElementContent('text'),'authnet_error',MYCART_TRXN_ERR,
                    array(
    'code'=>$code));
                    return;
                }
                else if (!empty(
    $Response->getElement('createCustomerProfileTransactionResponse')))
                {
                   
                 new 
    MycartError($Response->getElementContent('text'),'authnet_error',MYCART_TRXN_ERR,
                    array(
    'code'=>$code));
                    return;
                }
                else
                {
                
                 { 
                    new 
    MycartError(__("There is some other error.","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);

        } 

  7. #22
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    No, according to the result you posted here, there is no direct response on an error.
    PHP Code:
    function process () {
        global 
    $Mycart;
        
    $message $this->build();
        
    $Response $this->send($message); 
        if (!empty(
    $Response->getElement('ErrorResponse'))
        {
            new 
    MyCartError($Response->getElementContent('text'), 'authnet_error'MYCART_TRXN_ERR, array('code' => $Response->getElementContent('code')));
            return 
    false;
        }
        else if (!empty(
    $Response->getElement('createCustomerProfileTransactionResponse'))
        {
            
    // perform your transaction here
        
    }
        else
        {
            new 
    MycartError(__("There is some other error.","Mycart"),'authnet_error',MYCART_TRXN_ERR);
            return 
    false;
        }

    What I cannot tell you is how the $txnid or status comes about so I cannot write that block. The documentation on the github link doesn't show a successful result with a transaction id or status associated with it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  8. #23
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks. I know I got alot going on here and its confusing. Authorize.net uses different APIs. My cart was using thier AIM version of the API. So I was trying to convert it to the CIM version. CIM uses XML. It gives back <directResponse> in the response to can see on line 71 here https://github.com/stymiee/Authorize...uthCapture.php I was getting back a response from the API it was telling me code E0002 "The content-type specified is not supported. The only supported content-types are text/xml and application/xml." Which tells me that the XML is maybe not sent in the right format. But you can see inthe build() function it just sends that block and Authorize.Net reads it and accepts it. If I echo $XML I will see the response. Are we sure that
    return new XMLdata($response);
    is reading the XML I sent?

  9. #24
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I also have a AuthnetXML class that is the one I got from github. It is the one that formats the XML and sends it using CURL to the API.

  10. #25
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    No, the xmlData() call you have is wrapping the response you get. The build constructs the message, and it passes it to the parent::send when it calls the $this->send.
    Actually, wait a sec no it doesn't. The build() doesn't return a result, so it doesn't populate the $message within the process() method. So the call to $Response = $this->send($message); is sending it NULL. Add a return $xml; to the end of the build() method.
    I thought the whole problem here is that you simply don't get the error messages showing; this is looking more like it doesn't work at sending the request in the first place.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  11. #26
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ok thanks. I think we are narrowing in on the problem. If I add return $xml; to the build() method nothing is returned to the screen.

    If I add echo "Raw request: " . $xml . "

    I get the XML output that is generated by AuthNetXML class.
    Code:
    Raw request:
    Class Parameters
    API Login ID	xxx
    Transaction Key	xxx
    Authnet Server URL	https://apitest.authorize.net/xml/v1/request.api
    Request XML
    XML:	
    
    <?xml version="1.0"?>
    <createCustomerProfileTransactionRequest>
      <merchantAuthentication>
        <name>xxx</name>
        <transactionKey>xxx</transactionKey>
      </merchantAuthentication>
      <transaction>
        <profileTransAuthCapture>
          <amount>10.95</amount>
          <tax>
            <amount>1.00</amount>
            <name>your state sales tax</name>
            <description>description state sales tax</description>
          </tax>
          <shipping>
            <amount>2.00</amount>
            <name>ground based shipping</name>
            <description>Ground based 5 to 10 day shipping</description>
          </shipping>
          <lineItems>
            <itemId>1</itemId>
            <name>widget</name>
            <description>description of widget</description>
            <quantity>18</quantity>
            <unitPrice>45.00</unitPrice>
          </lineItems>
          <lineItems>
            <itemId>2</itemId>
            <name>widget2</name>
            <description>description widget 2</description>
            <quantity>10</quantity>
            <unitPrice>85.00</unitPrice>
          </lineItems>
          <customerProfileId>129</customerProfileId>
          <customerPaymentProfileId>119</customerPaymentProfileId>
          <customerShippingAddressId>1203</customerShippingAddressId>
          <order>
            <invoiceNumber>INV26</invoiceNumber>
            <description>description of transaction</description>
            <purchaseOrderNumber>PON26</purchaseOrderNumber>
          </order>
          <taxExempt>false</taxExempt>
          <recurringBilling>false</recurringBilling>
          <cardCode>000</cardCode>
        </profileTransAuthCapture>
      </transaction>
    </createCustomerProfileTransactionRequest>
    
    Response XML
    XML:	
    
    <?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.,TO4,Y,21872,INV26,description of transaction,10.95,CC,auth_capture,2,Joe Smith,,128 Some Street,87452144,,someone@.com,Joe,Smith,,1128 Some Street,,1.00,,2.00,FALSE,PON26,F0F3EBE72C2,P,2,,,,,,,,,,,XXXX0015,MasterCard,,,,,,,,,,,,,,,,,12031425</directResponse>
    </createCustomerProfileTransactionResponse>

  12. #27
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    So that'll now come down to writing what goes into this block:
    PHP Code:
        else if (!empty($Response->getElement('createCustomerProfileTransactionResponse'))
        {
            
    // perform your transaction here
        

    Problem is I'm not sure where you get these from. The original code had things like status and transaction id in it, but the result you get back doesn't have that. Is there something useful in the directRespons that has the id information in it?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  13. #28
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    So to be clear I have two XML classes working. One is xml.php that had all the methods I posted before. It is the one I was using to search the XML reponse.

    The other is called AuthnetXML class and that is the one that is getting the response from Authrize.net

    PHP Code:
    $transaction $Response->getElement('transaction');
    $txnid $transaction['CHILDREN']['Id']['CONTENT'];//this I think is searching the XML tree
    $txnstatus $this->status[$status];//wordpress to store record of tranactions
    $Mycart->Order->transaction($txnid,$txnstatus);//wordpress to store record of tranactions 
    Here is the AuthnetXML class I got from github
    PHP Code:
    class AuthnetXMLException extends Exception {}

    class 
    AuthnetXML
    {
        const 
    USE_PRODUCTION_SERVER 0;
        const 
    USE_DEVELOPMENT_SERVER 1;

        const 
    EXCEPTION_CURL 10;

        private 
    $ch;
    private 
    $login;
        private 
    $response;
        private 
    $response_xml;
        private 
    $results;
        private 
    $transkey;
        private 
    $url;
        private 
    $xml;

    public function 
    __construct($login$transkey$test self::USE_PRODUCTION_SERVER)
    {
    $login trim($login);
            
    $transkey trim($transkey);
            if (empty(
    $login) || empty($transkey))
            {
                
    trigger_error('You have not configured your ' __CLASS__ '() login credentials properly.'E_USER_WARNING);
            }

            
    $this->login trim($login);
            
    $this->transkey trim($transkey);
            
    $test = (bool) $test;

            
    $subdomain = ($test) ? 'apitest' 'api';
            
    $this->url 'https://' $subdomain '.authorize.net/xml/v1/request.api';
    }

        
    /**
    * remove XML response namespaces
    * without this php will spit out warinings
    * @see http://community.developer.authorize.net/t5/Integration-and-Testing/ARB-with-SimpleXML-PHP-Issue/m-p/7128#M5139
    */
        
    private function removeResponseXMLNS($input)
        {
            
    // why remove them one at a time? all three aren't consistantly used in the response
            
    $input str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"','',$input);
            
    $input str_replace(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"','',$input);
            return 
    str_replace(' xmlns:xsd="http://www.w3.org/2001/XMLSchema"','',$input);
        }

    public function 
    __toString()
    {
    $output '';
            
    $output .= '<table summary="Authorize.Net Results" id="authnet">' "\n";
            
    $output .= '<tr>' "\n\t\t" '<th colspan="2"><b>Class Parameters</b></th>' "\n" '</tr>' "\n";
            
    $output .= '<tr>' "\n\t\t" '<td><b>API Login ID</b></td><td>' $this->login '</td>' "\n" '</tr>' "\n";
            
    $output .= '<tr>' "\n\t\t" '<td><b>Transaction Key</b></td><td>' $this->transkey '</td>' "\n" '</tr>' "\n";
            
    $output .= '<tr>' "\n\t\t" '<td><b>Authnet Server URL</b></td><td>' $this->url '</td>' "\n" '</tr>' "\n";
            
    $output .= '<tr>' "\n\t\t" '<th colspan="2"><b>Request XML</b></th>' "\n" '</tr>' "\n";
            if (isset(
    $this->xml) && !empty($this->xml))
            {
                
    $dom = new DOMDocument('1.0');
                
    $dom->preserveWhiteSpace false;
                
    $dom->formatOutput true;
                
    $dom->loadXML(self::removeResponseXMLNS($this->xml));
                
    $outgoing_xml $dom->saveXML();

                
    $output .= '<tr><td>' "\n";
                
    $output .= 'XML:</td><td><pre>' "\n";
                
    $output .= htmlentities($outgoing_xml) . "\n";
                
    $output .= '</pre></td></tr>' "\n";
            }
            if (!empty(
    $this->response))
            {
                
    $dom = new DOMDocument('1.0');
                
    $dom->preserveWhiteSpace false;
                
    $dom->formatOutput true;
                
    $dom->loadXML(self::removeResponseXMLNS($this->response));
                
    $response_xml $dom->saveXML();

                
    $output .= '<tr>' "\n\t\t" '<th colspan="2"><b>Response XML</b></th>' "\n" '</tr>' "\n";
                
    $output .= '<tr><td>' "\n";
                
    $output .= 'XML:</td><td><pre>' "\n";
                
    $output .= htmlentities($response_xml) . "\n";
                
    $output .= '</pre></td></tr>' "\n";
            }
            
    $output .= '</table>';

            return 
    $output;
    }

    public function 
    __destruct()
        {
            if (isset(
    $this->ch))
            {
                
    curl_close($this->ch);
            }
        }

        public function 
    __get($var)
    {
    return 
    $this->response_xml->$var;
    }

    public function 
    __set($key$value)
    {
    trigger_error('You cannot set parameters directly in ' __CLASS__ '.'E_USER_WARNING);
    return 
    false;
    }

    public function 
    __call($api_call$args)
    {
    $this->xml = new SimpleXMLElement('<' $api_call '></' $api_call '>');
            
    $this->xml->addAttribute('xmlns''AnetApi/xml/v1/schema/AnetApiSchema.xsd');
    $merch_auth $this->xml->addChild('merchantAuthentication');
            
    $merch_auth->addChild('name'$this->login);
    $merch_auth->addChild('transactionKey'$this->transkey);

    $this->setParameters($this->xml$args[0]);
    $this->process();
    }

    private function 
    setParameters($xml$array)
    {
    if (
    is_array($array))
            {
                
    $first true;
                foreach (
    $array as $key => $value)
                {
                    if (
    is_array($value))
                    {
                        if(
    is_numeric($key))
                        {
                            if(
    $first === true)
                            {
                                
    $xmlx $xml;
                                
    $first false;
                            }
                            else
                            {
                                
    $parent $xml->xpath('parent::*');
                                
    $xmlx $parent[0]->addChild($xml->getName());
                            }
                        }
                        else
                        {
                            
    $xmlx $xml->addChild($key);
                        }
                        
    $this->setParameters($xmlx$value);
                    }
                    else
                    {
                        
    $xml->$key $value;
                    }
                }
            }
    }

    private function 
    process()
    {
    $this->xml $this->xml->asXML();

    $this->ch curl_init();
            
    curl_setopt($this->chCURLOPT_URL$this->url);
         
    curl_setopt($this->chCURLOPT_RETURNTRANSFER1);
         
    curl_setopt($this->chCURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
         
    curl_setopt($this->chCURLOPT_HEADER0);
         
    curl_setopt($this->chCURLOPT_POSTFIELDS$this->xml);
         
    curl_setopt($this->chCURLOPT_POST1);
         
    curl_setopt($this->chCURLOPT_SSL_VERIFYHOST2);
         
    curl_setopt($this->chCURLOPT_SSL_VERIFYPEERfalse);  
         
    curl_setopt($this->chCURLOPT_CAINFOdirname(__FILE__) . 'cert.pem');

            if((
    $this->response curl_exec($this->ch)) !== false)
            {
                
    $this->response_xml = @new SimpleXMLElement($this->response);

    curl_close($this->ch);
                unset(
    $this->ch);
                return;
    }
            throw new 
    AuthnetXMLException('Connection error: ' curl_error($this->ch) . ' (' curl_errno($this->ch) . ')'self::EXCEPTION_CURL);
    }

    public function 
    isSuccessful()
        {
            return 
    $this->response_xml->messages->resultCode == 'Ok';
        }

        public function 
    isError()
        {
            return 
    $this->response_xml->messages->resultCode != 'Ok';
        }


  14. #29
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    So what are you planning on using?
    The code you have so far constructs an instance of this AuthnetXML, but we cannot tell if it executes a process on it. For that you would need to provide the GatewayFramework::send method. As it sits currently,it looks like the context is to treat $message as a string, and simply push the XML to the client. That won't populate the data in the AuthnetXML, for that you need to call the AuthnetXML::process method. And even with that information since everything is using simplexml and __set, I cannot tell what is in it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  15. #30
    New Coder
    Join Date
    Mar 2013
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ok that is starting to make sense. Here is the gateway framework.

    PHP Code:
    /**
     * Gateway classes
     *
     * Generic prototype classes for local and remote payment systems
     
     * GatewayModule interface
     *
     
     **/
    interface GatewayModule {

        
    /**
         * Used for setting up event listeners
        
         **/
        
    public function actions();

        
    /**
         * Used for rendering the gateway settings UI
         *
        
         **/
        
    public function settings();

    }


    abstract class 
    GatewayFramework {

        var 
    $session false;        // The current shopping session ID
        
    var $Order false;            // The current customer's Order
        
    var $name false;            // The proper name of the gateway
        
    var $module false;        // The module class name of the gateway
        
    var $cards false;            // A list of supported payment cards
        
    var $secure true;            // Flag for requiring encrypted checkout process
        
    var $multi false;            // Flag to enable a multi-instance gateway
        
    var $baseop false;         // Base of operation setting
        
    var $precision 2;            // Currency precision
        
    var $settings = array();    // List of settings for the module

        
        
        
    function __construct () {
            global 
    $Mycart;
            
    $this->session $Mycart->Shopping->session;
            
    $this->Order = &MycartOrder();
            
    $this->module get_class($this);
            
    $this->settings $Mycart->Settings->get($this->module);
            if (!isset(
    $this->settings['label']) && $this->cards)
                
    $this->settings['label'] = __("Credit Card","Mycart");

            
    $this->baseop $Mycart->Settings->get('base_operations');
            
    $this->precision $this->baseop['currency']['format']['precision'];

            
    $this->_loadcards();
            if (
    $this->myorder()) $this->actions();
        }

        
        function 
    setupui ($module,$name) {
            if (!isset(
    $this->settings['label'])) $this->settings['label'] = $name;
            
    $this->ui = new ModuleSettingsUI('payment',$module,$name,$this->settings['label'],$this->multi);
            
    $this->settings();
        }


        function 
    setup () {
            
    $settings func_get_args();
            foreach (
    $settings as $name)
                if (!isset(
    $this->settings[$name]))
                    
    $this->settings[$name] = false;
        }

        
        function 
    myorder () {
            return (
    $this->Order->processor() == $this->module);
        }

        
        function 
    txnid () {
            return 
    mktime();
        }


        function 
    send ($data,$url,$port=false$curlopts = array()) {
            
    $connection curl_init();
            
    curl_setopt($connection,CURLOPT_URL,"$url".($port?":$port":""));
            
    curl_setopt($connectionCURLOPT_SSL_VERIFYPEER0);
            
    curl_setopt($connectionCURLOPT_SSL_VERIFYHOST0);
            
    curl_setopt($connectionCURLOPT_NOPROGRESS1);
            
    curl_setopt($connectionCURLOPT_VERBOSE1);
            
    curl_setopt($connectionCURLOPT_POST1);
            
    curl_setopt($connectionCURLOPT_POSTFIELDS$data);
            
    curl_setopt($connectionCURLOPT_TIMEOUTMYCART_GATEWAY_TIMEOUT);
            
    curl_setopt($connectionCURLOPT_USERAGENTMYCART_GATEWAY_USERAGENT);
            
    curl_setopt($connectionCURLOPT_REFERER"http://".$_SERVER['SERVER_NAME']);
            
    curl_setopt($connectionCURLOPT_FAILONERROR1);
            
    curl_setopt($connectionCURLOPT_RETURNTRANSFER1);

            if (!(
    ini_get("safe_mode") || ini_get("open_basedir")))
                
    curl_setopt($connectionCURLOPT_FOLLOWLOCATION,1);

            if (
    defined('MYCART_PROXY_CONNECT') && MYCART_PROXY_CONNECT) {
                
    curl_setopt($connectionCURLOPT_HTTPPROXYTUNNEL1);
                
    curl_setopt($connectionCURLOPT_PROXYMYCART_PROXY_SERVER);
                if (
    defined('MYCART_PROXY_USERPWD'))
                    
    curl_setopt($connectionCURLOPT_PROXYUSERPWDMYCART_PROXY_USERPWD);
            }

        
            
    curl_setopt($connectionCURLOPT_FRESH_CONNECT1);

            foreach (
    $curlopts as $key => $value)
                
    curl_setopt($connection$key$value);

            
    $buffer curl_exec($connection);
            if (
    $error curl_error($connection))
                new 
    MycartError($this->name.": ".$error,'gateway_comm_err',MYCART_COMM_ERR);
            
    curl_close($connection);

            return 
    $buffer;

        }

        
        function 
    encode ($data) {
            
    $query "";
            
    $data stripslashes_deep($data);
            foreach(
    $data as $key => $value) {
                if (
    is_array($value)) {
                    foreach(
    $value as $item) {
                        if (
    strlen($query) > 0$query .= "&";
                        
    $query .= "$key=".urlencode($item);
                    }
                } else {
                    if (
    strlen($query) > 0$query .= "&";
                    
    $query .= "$key=".urlencode($value);
                }
            }
            return 
    $query;
        }

        
        function 
    format ($data,$fieldclass = array('total'=>'total','shipping'=>'shipping','tax'=>'tax')) {
            
    $query '';
            
    $classes = array(
                
    'shipping' => 'mycart_cart_shipping',
                
    'tax' => 'mycart_cart_tax',
                
    'total' => 'mycart_cart_total',
            );

            foreach ((array)
    $data as $key => $value) {
                
    $class '';
                if (
    is_array($value)) $key $key.'[]';
                if (!
    is_array($value)) $value = array($value);

                
    $classtype array_search($key,$fieldclass);
                if (isset(
    $classes[$classtype])) $class " class=\"{$classes[$classtype]}\"";

                foreach((array)
    $value as $item)
                    
    $query .= '<input type="hidden" name="'.$key.'" value="'.esc_attr($item).'"'.$class.' />';
            }
            return 
    $query;
        }

        
        function 
    cards () {
            
    $accepted = array();
            if (!empty(
    $this->settings['cards'])) $accepted $this->settings['cards'];
            if (empty(
    $accepted) && is_array($this->cards)) $accepted array_keys($this->cards);
            
    $pcs Lookup::paycards();
            
    $cards = array();
            foreach (
    $accepted as $card) {
                
    $card strtolower($card);
                if (isset(
    $pcs[$card])) $cards[$card] = $pcs[$card];
            }
            return 
    $cards;
        }

        
        private function 
    _loadcards () {
            if (empty(
    $this->settings['cards'])) $this->settings['cards'] = $this->cards;
            if (
    $this->cards) {
                
    $cards = array();
                
    $pcs Lookup::paycards();
                foreach (
    $this->cards as $card) {
                    
    $card strtolower($card);
                    if (isset(
    $pcs[$card])) $cards[] = $pcs[$card];
                }
                
    $this->cards $cards;
            }
        }

    // END class GatewayFramework


    /**
     * GatewayModules class
     *
     * Gateway module file manager to load gateways that are active.
     *
     
    class GatewayModules extends ModuleLoader {

        var $selected = false;        // The chosen gateway to process the order
        var $secure = false;        // SSL-required flag

        /**
         * Initializes the shipping module loader
         *
         *
         *
         *
         * @return void Description...
         **/
        
    function __construct () {

            
    $this->path MYCART_GATEWAYS;

            
    // Get hooks in place before getting things started
            
    add_action('mycart_module_loaded',array(&$this,'properties'));

            
    $this->installed();
            
    $this->activated();

            
    add_action('mycart_init',array(&$this,'load'));
        }

        
    /**
         * Determines the activated gateway modules
         *
         * 
         * 
         *
         * @return array List of module names for the activated modules
         **/
        
    function activated () {
            global 
    $Mycart;
            
    $this->activated = array();
            
    $gateways explode(",",$Mycart->Settings->get('active_gateways'));
            foreach (
    $this->modules as $gateway)
                if (
    in_array($gateway->subpackage,$gateways))
                    
    $this->activated[] = $gateway->subpackage;

            return 
    $this->activated;
        }

        
    /**
         * Sets Gateway system settings flags based on activated modules
         *
         * @
         * @
         *
         * @param string $module Activated module class name
         * @return void
         **/
        
    function properties ($module) {
            if (!isset(
    $this->active[$module])) return;
            
    $this->active[$module]->name $this->modules[$module]->name;
            if (
    $this->active[$module]->secure$this->secure true;
        }

        
    /**
         * Loads all the installed gateway modules for the payments settings
         *
         * 
         * @
         *
         * @return void
         **/
        
    function settings () {
            
    $this->load(true);
        }

        
    /**
         * Initializes the settings UI for each loaded module
         *
         * 
         * 
         *
         * @return void Description...
         **/
        
    function ui () {
            foreach (
    $this->active as $package => &$module)
                
    $module->setupui($package,$this->modules[$package]->name);
        }

    //} // END class GatewayModules

    /**
     * PayCard classs
     *
     * Implements structured payment card (credit card) behaviors including
     * card number validation and extra security field requirements.
     *
     * 
     * 
     * @package mycart
     * @subpackage gateways
     **/
    class PayCard {

        var 
    $name;
        var 
    $symbol;
        var 
    $pattern false;
        var 
    $csc false;
        var 
    $inputs = array();

        function 
    __construct ($name,$symbol,$pattern,$csc=false,$inputs=array()) {
            
    $this->name $name;
            
    $this->symbol $symbol;
            
    $this->pattern $pattern;
            
    $this->csc $csc;
            
    $this->inputs $inputs;
        }

        function 
    validate ($pan) {
            
    $n preg_replace('/\D/','',$pan);
            return (
    $this->match($n) && $this->checksum($n));
        }

        function 
    match ($number) {
            if (
    $this->pattern && !preg_match($this->pattern,$number)) return false;
            return 
    true;
        }

        function 
    checksum ($number) {
            
    $code strrev($number);
            for (
    $i 0$i strlen($code); $i++) {
                
    $d intval($code[$i]);
                if (
    $i 1$d *= 2;
                
    $cs += $d 10;
                if (
    $d 9$cs += 1;
            }
            return (
    $cs 10 == 0);
        }




 
Page 2 of 3 FirstFirst 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
  •