method = "CC"; //the default is for credit card responses $this->url = "https://secure.authorize.net/gateway/transact.dll"; //"https://certification.authorize.net/gateway/transact.dll"; $this->username = Privy::$a_n_u; $this->password = Privy::$a_n_p; $this->tran_key = Privy::$a_n_k; $this->version = "3.1"; $this->type = "AUTH_ONLY"; $this->test_mode = FALSE; $this->prior_trans_id = ''; } // function authorizenet() function process(&$field_err) { if(Config::$location == 'local') { //return(TRUE); } $data = $this->get_data(); //get the data to send //echo "
$data
"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$this->url); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $this->return_string = curl_exec($ch); curl_close ($ch); //echo $this->return_string; $response_array = explode( '|', $this->return_string ); //$response_array = array(1,0,0,1,1,1,1,1); // for testing comment all curl lines and above response_array line and uncomment this $this->response_code = $response_array[0]; $this->response_reason_code = $response_array[2]; $this->response_reason_text = $response_array[3]; $this->approval_code = $response_array[4]; $this->avs_code = $response_array[5]; $this->trans_id = $response_array[6]; $this->cvv2_code = $response_array[38]; if( $this->response_code == 1 ) { $this->payment_amount = $this->amount; return true; //if the process was successful } else { $this->set_error_msg($field_err); // SETS $this->error_msg; // USED TO DISPLAY TO CUSTOMER return false; } } function get_data() { global $authorizenet_login, $authorizenet_password, $authorizenet_test_mode; // x_duplicate_window is # of seconds that a dupe gets declined $data = "x_login=" . urlencode($this->username) . "&x_password=" . urlencode($this->password) . "&x_tran_key=" . urlencode($this->tran_key) . "&x_version=" . urlencode($this->version) . "&x_trans_id=" . urlencode($this->prior_trans_id) . // USED IN CAPTURE ONLY "&x_delim_data=" . "TRUE" . "&x_delim_char=" . "|" . "&x_duplicate_window=" . "8" . "&x_email_customer=" . "FALSE" . "&x_email=" . urlencode($this->email) . "&x_address=" . urlencode($this->address) . "&x_city=" . urlencode($this->city) . "&x_state=" . urlencode($this->state) . "&x_zip=" . urlencode($this->zip) . "&x_country=" . urlencode($this->country) . "&x_phone=" . urlencode($this->phone) . "&x_type=" . urlencode($this->type) . "&x_method=" . urlencode($this->method) . "&x_first_name=" . urlencode($this->first_name) . "&x_last_name=" . urlencode($this->last_name) . "&x_amount=" . urlencode($this->amount) . "&x_card_num=" . urlencode($this->cc_num) . "&x_exp_date=" . urlencode($this->cc_exp) . "&x_invoice_num=" . urlencode($this->invoice_num) . "&x_card_code=" . urlencode($this->card_code) . "&x_test_request=" . $this->test_mode; return $data; } function set_error_msg(&$field_err) { switch($this->response_reason_code) { case 2: $this->error_msg = "The transaction has been declined. Please try again."; break; case 3: $this->error_msg = "The transaction has been declined. Please try again."; break; case 4: $this->error_msg = "The transaction has been declined. Please try again."; break; case 5: $this->error_msg = "A valid amount is required. Please try again."; break; case 6: $field_err['cc_number'] = 'invalid'; $this->error_msg = "The credit card number is invalid. Please correct and resubmit."; break; case 7: $this->error_msg = "The credit card expiration date is invalid. Please correct and resubmit."; break; case 8: $this->error_msg = "The credit card has expired. Please correct and resubmit."; break; case 11: $this->error_msg = "A communication error occurred. Please try again."; break; case 12: $this->error_msg = "An authorization code is required."; break; case 15: $this->error_msg = "The transaction ID is invalid."; break; case 16: $this->error_msg = "The transaction was not found."; break; case 17: $this->error_msg = "This type of credit card is not accepted. Please correct and resubmit."; break; case 19: $this->error_msg = "A communication error occurred. Please try again."; break; case 20: $this->error_msg = "A communication error occurred. Please try again."; break; case 21: $this->error_msg = "A communication error occurred. Please try again."; break; case 22: $this->error_msg = "A communication error occurred. Please try again."; break; case 23: $this->error_msg = "A communication error occurred. Please try again."; break; case 25: $this->error_msg = "A communication error occurred. Please try again."; break; case 26: $this->error_msg = "A communication error occurred. Please try again."; break; case 27: $this->error_msg = "The billing address (street and or postal code) does not match the credit card information. Please correct and resubmit."; break; case 28: $this->error_msg = "This type of credit card is not accepted. Please correct and resubmit."; break; case 33: $this->error_msg = "Invalid referenced transaction ID."; break; case 37: $field_err['cc_number'] = 'invalid'; $this->error_msg = "The credit card number is invalid. Please correct and resubmit."; break; case 44: $this->error_msg = "The transaction has been declined. Please check your card code and try again."; break; case 45: $this->error_msg = "The transaction has been declined. Please check your card code and address information and try again."; break; case 47: $this->error_msg = "The amount captured cannot be greater than the authorization amount."; break; case 50: $this->error_msg = "This transaction is awaiting settlement and cannot be refunded."; break; case 51: $this->error_msg = "The sum of all credits against this transaction is greater than the transaction amount."; break; case 54: $this->error_msg = "This transaction does not meet the criteria for issuing a credit. Most likely it needs 1 day to settle first."; break; case 55: $this->error_msg = "The sum of all credits against this transaction would exceed original debit amount."; break; case 57: $this->error_msg = "A communication error occurred. Please try again."; break; case 58: $this->error_msg = "A communication error occurred. Please try again."; break; case 59: $this->error_msg = "A communication error occurred. Please try again."; break; case 60: $this->error_msg = "A communication error occurred. Please try again."; break; case 61: $this->error_msg = "A communication error occurred. Please try again."; break; case 62: $this->error_msg = "A communication error occurred. Please try again."; break; case 63: $this->error_msg = "A communication error occurred. Please try again."; break; case 65: $field_err['cc_cvv2'] = 'did not match'; $this->error_msg = "The credit card security code did not match. Please try again."; break; case 78: $field_err['cc_cvv2'] = 'invalid'; $this->error_msg = "The credit card security code entered is invalid. Please correct and resubmit."; break; case 120: $this->error_msg = "A communication error occurred. Please try again."; break; case 121: $this->error_msg = "A communication error occurred. Please try again."; break; case 122: $this->error_msg = "A communication error occurred. Please try again."; break; case 127: $this->error_msg = "The billing address (street and or postal code) does not match the credit card information. Please correct and resubmit."; break; case 503: $this->error_msg = "A communication error occurred. Please try again."; break; default: $this->error_msg = "Either the card was declined or there was a communication failure. Please try again."; } } } // class authorizenet ?>