authorizeUser=$user; $this->authorizeTransactionKey=$key; $this->authorizeTesting=$testing; } //setup unique user id,ip used, and users email //this data is used for reference from authorize.net admin and fraud decetion features @ authorize.net function trackUser($userUnique,$userIp,$userEmail){ $this->mAuthorize['x_cust_id']=$userUnique; $this->mAuthorize['x_customer_ip']=$userIp; $this->mAuthorize['x_email']=$userEmail; $this->mAuthorize['x_email_customer']='TRUE'; $this->mAuthorize['trackUser']=true; } //add user's data function customerData($firstName,$lastName,$company,$address,$city,$state,$zip,$country,$phone){ $this->mAuthorize['x_first_name']=$firstName; $this->mAuthorize['x_last_name']=$lastName; $this->mAuthorize['x_address']=$address; $this->mAuthorize['x_city']=$city; $this->mAuthorize['x_state']=$state; $this->mAuthorize['x_zip']=$zip; $this->mAuthorize['x_country']=$country; if(!empty($phone)){ $this->mAuthorize['x_phone']=$phone; } if(!empty($company)){ $this->mAuthorize['x_company']=$company; } $this->mAuthorize['customerData']=true; } function paymentData($amount){ $this->mAuthorize['x_amount']=$amount; $this->mAuthorize['paymentData']=true; } //invoice id , details , and promo code function invoiceData($invoiceId,$invoiceDetails,$invoicePromo='0000'){ $this->mAuthorize['promoCode']=$invoicePromo; $this->mAuthorize['x_invoice_num']=$invoiceId; $this->mAuthorize['x_description']=$invoiceDetails; $this->mAuthorize['invoiceData']=true; } //add users cc data //cc#, exp, csv code, is business account function creditCardData($ccNumber,$ccExpire,$ccCode,$ccBusiness=''){ $this->mAuthorize['x_card_num']=$ccNumber; $this->mAuthorize['x_exp_date']=$ccExpire; $this->mAuthorize['x_card_code']=$ccCode; $this->mAuthorize['x_method']='CC'; if(!empty($ccBusiness)){ $this->mAuthorize['x_customer_organization_type']=$ccBusiness ; } $this->mAuthorize['x_type']='AUTH_CAPTURE'; $this->mAuthorize['paymentData']=true; } // function prepareRequest(){ //add account / request configs $this->mAuthorize['x_login']="{$this->authorizeUser}"; $this->mAuthorize['x_tran_key']="{$this->authorizeTransactionKey}"; $this->mAuthorize['x_version']=$this->authorizeVersion; $this->mAuthorize['x_delim_data']='TRUE'; $this->mAuthorize['x_delim_char']=$this->delimiter; $this->mAuthorize['x_relay_response']='FALSE'; $this->mAuthorize['x_encap_char']=''; $this->mAuthorize['x_url']='FALSE'; if($this->authorizeTesting){ $this->mAuthorize['x_test_request']='TRUE'; print_r($this->mAuthorize); } //clear / prepare transaction data $this->transactionData=''; //loop through mAuthorize array and create request data foreach($this->mAuthorize as $item => $value) { $this->transactionData.="$item=".urlencode($value)."&"; } $this->transactionData=rtrim($this->transactionData,"& "); $this->mAuthorize['prepared']=true; } function sendRequest(){ //setup curl connection $ch = curl_init($this->gateway); curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1) curl_setopt($ch, CURLOPT_POSTFIELDS, $this->transactionData); // use HTTP POST to send form data curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. ### //setup raw response //if you want to do something different, no worries rawData is the actual untouched response $this->rawResponse=urldecode(curl_exec($ch)); //send request and get results $curlError=curl_errno($ch); curl_close($ch); return $curlError; } function getResponse($error=0){ //make responseData Array $responseData=explode($this->delimiter,$this->rawResponse); //setup various response code arrays //AVS Result Code $avsResult=array(); $avsResult['A'] = 'Address (Street) matches, ZIP does not'; $avsResult['B'] = 'Address information not provided'; $avsResult['E'] = 'Address check error'; $avsResult['G'] = 'Non-U.S. Card Issuing Bank'; $avsResult['N'] = 'No Match on Address (Street) or ZIP'; $avsResult['P'] = 'Address Check not applicable for this transaction'; $avsResult['R'] = 'Retry – Time out'; $avsResult['S'] = 'Card not supported'; $avsResult['U'] = 'Address information is unavailable'; $avsResult['W'] = '9 digit ZIP matches, Address (Street) does not'; $avsResult['X'] = 'Address (Street) and 9 digit ZIP match'; $avsResult['Y'] = 'Address (Street) and 5 digit ZIP match'; $avsResult['Z'] = '5 digit ZIP matches, Address (Street) does not'; //Card Code (CVV2/CVC2/CID) Response Code $cardCodeResult=array(); $cardCodeResult['M'] = 'Match'; $cardCodeResult['N'] = 'No Match'; $cardCodeResult['P'] = 'Not Processed'; $cardCodeResult['S'] = 'Should have been present'; $cardCodeResult['U'] = 'Issuer unable to process request'; //Cardholder Authentication Verification Value (CAVV) Response Code $cardHolderResult=array(); $cardHolderResult['0']= 'Not validated'; $cardHolderResult['1']= 'Failed validation'; $cardHolderResult['2']= 'Passed validation'; $cardHolderResult['3']= 'Validation could not be performed (issuer attempt incomplete)'; $cardHolderResult['4']= 'Validation could not be performed (issuer system error)'; $cardHolderResult['5']= 'Reserved for future use'; $cardHolderResult['6']='Reserved for future use'; $cardHolderResult['7']='Failed validation – issuer available (U.S.-issued card/non-U.S acquirer)'; $cardHolderResult['8']='Passed validation – issuer available (U.S.-issued card/non-U.S. acquirer)'; $cardHolderResult['9']='Failed validation – issuer unavailable (U.S.-issued card/non-U.S. acquirer)'; $cardHolderResult['A'] = 'Passed validation – issuer unavailable (U.S.-issued card/non-U.S. acquirer)'; $cardHolderResult['B'] = 'Passed validation, information only, no liability shift'; //primary response code $responseCode=array(); $responseCode['1'] = 'Approved'; $responseCode['2'] = 'Declined'; $responseCode['3'] = 'Error'; $responseCode['4'] = 'Held For Review'; $responseCode['curl'] = 'Server Error'; //start micah love //setup response keys $responseKeys=array ( "Response Code", "Response Subcode", "Response Reason Code", "Response Reason Text", "Approval Code", "AVS Result Code", "Transaction ID", "Invoice Number", "Description", "Amount", "Method", "Transaction Type", "Customer ID", "Cardholder First Name", "Cardholder Last Name", "Company", "Billing 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 Amount", "Duty Amount", "Freight Amount", "Tax Exempt Flag", "PO Number", "MD5 Hash", "Card Code (CVV2/CVC2/CID) Response Code", "Cardholder Authentication Verification Value (CAVV) Response Code" ); // add additional keys for reserved fields and merchant defined fields for ($i=0; $i<=27; $i++) { array_push($responseKeys, 'Reserved Field '.$i); } $i=0; while (sizeof($responseKeys) < sizeof($responseData)) { array_push($responseKeys, 'Merchant Defined Field '.$i); $i++; } // combine the keys and values arrays into the $this->transactionResponse array. This // can be done with the array_combine() function instead if you are using // php 5. for ($i=0; $itransactionResponse["$responseKeys[$i]"] = ''.$responseData[$i].''; } //end micah - :) thanks //check for curl error if($error>0){ $this->transactionResponse['Response Code']='curl'; } //if we have a valid transaction i wasted alot of time typing if(intval($this->transactionResponse['Response Code'])==1){ /*to check your transaction do $var=$object->makeRequest(); if($var!==true) if your request failed at any point it will return false */ $this->transactionResponse['Response Code']=true; }else{ /*dang theres and error, but at least i didn't write for nothing instead of true we'll return the various error messages */ $this->transactionResponse['Response Code']=(!empty($responseCode[$this->transactionResponse['Response Code']])) ? $responseCode[$this->transactionResponse['Response Code']] : $responseCode['2']; $this->transactionResponse['AVS Result Code']=(!empty($avsResult[$this->transactionResponse['AVS Result Code']])) ? $avsResult[$this->transactionResponse['AVS Result Code']] : $this->transactionResponse['AVS Result Code']; $this->transactionResponse['Card Code (CVV2/CVC2/CID) Response Code']=(!empty($cardCodeResult[$this->transactionResponse['Card Code (CVV2/CVC2/CID) Response Code']])) ? $cardCodeResult[$this->transactionResponse['Card Code (CVV2/CVC2/CID) Response Code']] : $this->transactionResponse['Card Code (CVV2/CVC2/CID) Response Code']; $this->transactionResponse['Cardholder Authentication Verification Value (CAVV) Response Code']=(!empty($cardHolderResult[$this->transactionResponse['Cardholder Authentication Verification Value (CAVV) Response Code']])) ? $cardHolderResult[$this->transactionResponse['Cardholder Authentication Verification Value (CAVV) Response Code']] : $this->transactionResponse['Cardholder Authentication Verification Value (CAVV) Response Code']; return false; } return $this->transactionResponse['Response Code']; } function validateRequest(){ //make sure request is prepared if(!$this->mAuthorize['prepared']){ $this->prepareRequest(); } $valid=true; /*check there are required calls if so check them*/ if(!empty($this->requiredCalls)){ $requiredArray=explode('|',$this->requiredCalls); foreach($requiredArray as $index){ $valid=($this->mAuthorize[$index]!==true) ? false : $valid ; if($this->authorizeTesting && !$valid){ print 'empty call @ '.$index; } } } /*if everythings ok so far lets make sure we have all required information*/ if($valid==true){ //setup array to check if value is required $allowedEmpty=explode("|",$this->allowedEmpty); foreach($this->mAuthorize as $index=>$value){ if(in_array($index,$allowedEmpty)) { continue; } $valid=(empty($this->mAuthorize[$index])) ? false : $valid ; if($this->authorizeTesting && !$valid){ print 'empty index @ '.$index; } } } //return requests valid status return $valid; } function makeRequest(){ $this->prepareRequest(); $requestStatus=$this->validateRequest(); // echo $requestStatus; if($requestStatus==true){ $errors=$this->sendRequest(); $requestStatus=$this->getResponse($errors); //debugging if($this->authorizeTesting){ print("
---
processed transaction data
---
") ; print_r($this->transactionResponse); print("
---
raw transaction data
---
") ; print_r($this->rawResponse); print("
---
curl error
---
") ; print_r($errors); } }elseif($this->authorizeTesting){ print 'not valid'; } return $requestStatus; } } ?>