Authorize.net class





0
The class containing how to process transaction with authorize.net

<?php
        /*
                $objAuthorize = new Authorize();
                $objAuthorize->gatewayParam['x_login'] = "5P3wMJ7bkd5F";
                $objAuthorize->gatewayParam['x_tran_key'] = "78GXcav3867k4G4w";
                $objAuthorize->gatewayParam['x_version'] = "3.1";
                $objAuthorize->gatewayParam['x_test_request'] = "false";
                $objAuthorize->gatewayParam['x_delim_data'] = "true";
                $objAuthorize->gatewayParam['x_delim_char'] = "|";
                $objAuthorize->gatewayParam['m'] = "1";
                $objAuthorize->gatewayParam['x_first_name'] = "";
                $objAuthorize->gatewayParam['x_last_name'] = "";
                $objAuthorize->gatewayParam['x_company'] = "";
                $objAuthorize->gatewayParam['x_address'] = "";
                $objAuthorize->gatewayParam['x_city'] = "";
                $objAuthorize->gatewayParam['x_state'] = "";
                $objAuthorize->gatewayParam['x_zip'] = "";
                $objAuthorize->gatewayParam['x_country'] = "";
                $objAuthorize->gatewayParam['x_phone'] = "";
                $objAuthorize->gatewayParam['x_fax'] = "";
                $objAuthorize->gatewayParam['x_email'] = "";
                $objAuthorize->gatewayParam['x_ship_to_first_name'] = "";
                $objAuthorize->gatewayParam['x_ship_to_last_name'] = "";
                $objAuthorize->gatewayParam['x_ship_to_company'] = "";
                $objAuthorize->gatewayParam['x_ship_to_address'] = "";
                $objAuthorize->gatewayParam['x_ship_to_city'] = "";
                $objAuthorize->gatewayParam['x_ship_to_state'] = "";
                $objAuthorize->gatewayParam['x_ship_to_zip'] = "";
                $objAuthorize->gatewayParam['x_ship_to_country'] = "";
                $objAuthorize->gatewayParam['x_amount'] = "";
                $objAuthorize->gatewayParam['x_method'] = "CC";
                $objAuthorize->gatewayParam['x_type'] = "AUTH_CAPTURE";
                $objAuthorize->gatewayParam['x_card_num'] = "";
                $objAuthorize->gatewayParam['x_card_code'] = "";
                $objAuthorize->gatewayParam['x_exp_date'] = "";
                $objAuthorize->gatewayParam['x_currency_code'] = "USD";
                $objAuthorize->gatewayParam['x_relay_response'] = "false";
                $objAuthorize->gatewayParam['x_url'] = "false";

                $objAuthorize->Process();
        */

        class Authorize {
                public $gatewayParam = array(); // It is the parameter array need to pass
                public $gatewayURL = "https://secure.authorize.net/gateway/transact.dll"; // Default url for credit card authentication. Can be changed forcefully
                private $returnFromMerchant = array(); // Gateway return values will storing into the array
               
                // Function for process the credit card
                public function Process() {
                        /*
                                As the process will run under curl environment, so
                                first checking that curl is installed into the server or not
                        */

                        if(extension_loaded("curl")==true) {
                                // Storing the parameter with its value in the variable to post using carl
                                foreach($this->gatewayParam as $key => $val) {
                                        $PostData.= $key."=".urlencode($val)."&";
                                }
                                $PostData = substr($PostData,0,strlen($PostData)-1);
                                // Submitting the data using curl and returning after checking
                                $ch = curl_init($this->gatewayURL);
                                curl_setopt($ch, CURLOPT_HEADER, 0);
                                curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                                $buffer = curl_exec($ch);
                                curl_close($ch);
                                // Storing the return values into the array by exploding the data "|" character
                                $this->returnFromMerchant = explode("|",$buffer);
                        } else {
                                // If curl not isntalled then showing error message
                                return "CURL Error";
                        }
                }
               
                // Function to return the response code after the transaction
                public function ResponseCode() {
                        return $this->returnFromMerchant[0];
                }
               
                // Function to return the error code after non successful transaction
                public function ErrorCode() {
                        return $this->returnFromMerchant[2];
                }
               
                // Function to return the error text after non successful transaction
                public function ErrorText() {
                        return $this->returnFromMerchant[3];
                }
        }
?>
 

Subhasish Nag

Thanks,
--
Subhasish Nag
==============
Mobile: +91 9831581556

Comments

There are currently no comments for this snippet.

Voting

Votes Up


Votes Down