fields["$field"] = urlencode($value); } function process() { // This function actually processes the payment. This function will // load the $response array with all the returned information. The return // values for the function are: // 1 - Approved // 2 - Declined // 3 - Error // construct the fields string to pass to authorize.net foreach( $this->fields as $key => $value ) $this->field_string .= "$key=" . urlencode( $value ) . "&"; // execute the HTTPS post via CURL $ch = curl_init($this->gateway_url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $this->field_string, "& " )); $this->response_string = urldecode(curl_exec($ch)); if (curl_errno($ch)) { $this->response['Response Reason Text'] = curl_error($ch); return 3; } else curl_close ($ch); // load a temporary array with the values returned from authorize.net $temp_values = explode('|', $this->response_string); // load a temporary array with the keys corresponding to the values // returned from authorize.net (taken from AIM documentation) $temp_keys= 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($temp_keys, 'Reserved Field '.$i); } $i=0; while (sizeof($temp_keys) < sizeof($temp_values)) { array_push($temp_keys, 'Merchant Defined Field '.$i); $i++; } // combine the keys and values arrays into the $response array. This // can be done with the array_combine() function instead if you are using // php 5. for ($i=0; $iresponse["$temp_keys[$i]"] = $temp_values[$i]; } // Return the response code. return $this->response['Response Code']; } function get_response_reason_text() { return $this->response['Response Reason Text']; } function dump_fields() { // Used for debugging, this function will output all the field/value pairs // that are currently defined in the instance of the class using the // add_field() function. echo "

authorizenet_class->dump_fields() Output:

"; echo ""; foreach ($this->fields as $key => $value) { echo ""; } echo "
Field Name Value
$key".urldecode($value)." 

"; } function dump_response() { // Used for debuggin, this function will output all the response field // names and the values returned for the payment submission. This should // be called AFTER the process() function has been called to view details // about authorize.net's response. echo "

authorizenet_class->dump_response() Output:

"; echo ""; $i = 0; foreach ($this->response as $key => $value) { echo ""; $i++; } echo "
Index  Field Name Value
$i $key $value 

"; } }