ExpirationDate=preg_replace("/[^0-9]/","",$this->ExpirationDate); if(strlen($this->ExpirationDate)<4) $this->ExpirationDate="0".$this->ExpirationDate; if(strlen($this->ExpirationDate)!=4) $error[]="Invalid date. Required format: MMYY"; if(!$error) { if($this->Test) $url=$this->_test_url; else $url=$this->_live_url; $authnet_values = array ( "x_login" => $this->AuthNetLoginID, "x_version" => "3.1", "x_delim_char" => "|", "x_delim_data" => "TRUE", "x_url" => "FALSE", "x_type" => $this->TransactionType, "x_method" => "CC", "x_tran_key" => $this->AuthNetTransactionKey, "x_relay_response" => "FALSE", "x_card_num" => ereg_replace("[^0-9]","",$this->CardNumber), "x_exp_date" => $this->ExpirationDate, "x_description" => $this->Description, "x_duplicate_window" => $this->DuplicateWindow, "x_amount" => $this->Amount, "x_invoice_num" => $this->InvoiceNumber, "x_first_name" => $this->FirstName, "x_last_name" => $this->LastName, "x_address" => $this->Address, "x_city" => $this->City, "x_state" => $this->State, "x_country" => $this->Country, "x_zip" => $this->Zip, "x_phone" => $this->Phone, "x_email" => $this->Email, "x_email_customer" => "FALSE", "SpecialCode" => $this->Custom, "x_cust_id" => $this->CustomerID, "x_merchant_email" => $this->MerchantReceiptEmail, "x_card_code" => $this->SecurityCode, "x_trans_id" => $this->TransactionID ); if($this->Test) $authnet_values["x_test_request"]="TRUE"; else $authnet_values["x_test_request"]="FALSE"; foreach($authnet_values as $key => $value) $params[]=$key."=".urlencode($value); //connect and send the request $ch = curl_init($url); 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, implode("&",$params )); // use HTTP POST to send form data $resp = curl_exec($ch); //execute post and get results curl_close ($ch); $this->LastRequest=implode("&",$params); $this->LastResponse = $resp; //parse the response $response_parts=explode("|",$resp); if($response_parts[0]==1) //approved { $this->ApprovalCode=$response_parts[4]; $this->TransactionID=$response_parts[6]; $this->ResponseReason="The transaction has been approved."; $ok=true; } else //declined { switch($response_parts[2]) { case 5: $this->ResponseReason="A valid amount is required."; break; case 6: $this->ResponseReason="The credit card number is invalid."; break; case 7: $this->ResponseReason="The credit card expiration date is invalid."; break; case 8: $this->ResponseReason="The credit card has expired."; break; case 11: $this->ResponseReason="A duplicate transaction has been submitted."; break; case 12: $this->ResponseReason="An authorization code is required but not present."; break; case 13: $this->ResponseReason="The merchant API login ID is invalid or the account is inactive."; break; case 15: $this->ResponseReason="The transaction ID is invalid."; break; case 16: $this->ResponseReason="The transaction was not found."; break; case 17: $this->ResponseReason="The merchant does not accept this type of credit card."; break; case 27: $this->ResponseReason="The transaction resulted in an AVS mismatch. The address provided does not match billing address of cardholder."; break; case 28: $this->ResponseReason="The merchant does not accept this type of credit card."; break; case 36: $this->ResponseReason="The authorization was approved, but settlement failed."; break; case 37: $this->ResponseReason="The credit card number is invalid."; break; case 42: $this->ResponseReason="There is missing or invalid information in a required field."; break; case 47: $this->ResponseReason="The amount requested for settlement may not be greater than the original amount authorized."; break; case 48: $this->ResponseReason="This processor does not accept partial reversals."; break; case 50: $this->ResponseReason="This transaction is awaiting settlement and cannot be refunded."; break; case 51: $this->ResponseReason="The sum of all credits against this transaction is greater than the original transaction amount."; break; case 52: $this->ResponseReason="The transaction was authorized, but the client could not be notified; the transaction will not be settled."; break; case 55: $this->ResponseReason="The sum of credits against the referenced transaction would exceed the original debit amount."; break; default: $this->ResponseReason="The transaction has been declined."; break; } } } if($error) $this->LastError=$error; return($ok); } } ?>