I ended up dropping the Authorize.net plugin completely and decided to use the server validation custom code section instead and write my own interface to Authorize.net using curl. This ends up working better for me in the long run due to all the other stuff I had to do in custom code sections to get the form to work the way I wanted it to. With this code I can let chronoforms handle the client side validation as usual, I can validate using my custom code below, and chronoforms can handle the emails and redirect. Before I had to disable to the email and redirection in code due to the way the plugin handled (or rather lack of) failures.
Hope this code helps anybody who had the same problems as I did. Remember to update this to turn off test mode before taking the form live.
<?PHP
// By default, this sample code is designed to post to our test server for
// developer accounts: https://test.authorize.net/gateway/transact.dll
// for real accounts (even in test mode), please make sure that you are
// posting to: https://secure.authorize.net/gateway/transact.dll
//$post_url = "https://test.authorize.net/gateway/transact.dll";
$post_url = "https://secure.authorize.net/gateway/transact.dll";
/* test numbers
good:
370000000000002 American Express
6011000000000012 Discover
5424000000000015 MasterCard
4007000000027 Visa
bad: 4222222222222222
amount determines error returned
*/
$post_values = array(
// the API Login ID and Transaction Key must be replaced with valid values
"x_login" => "your_login",
"x_tran_key" => "your_key",
"x_test_request" => "T",
"x_version" => "3.1",
"x_delim_data" => "TRUE",
"x_delim_char" => "|",
"x_relay_response" => "FALSE",
"x_type" => "AUTH_CAPTURE",
"x_method" => "CC",
"x_card_num" => $_POST['cardNumber'],
"x_exp_date" => $_POST['cardMonth'] . '-' . $_POST['cardYear'],
"x_amount" => $_POST['amount'],
"x_description" => $_POST['description'],
"x_first_name" => $_POST['cardFirstName'],
"x_last_name" => $_POST['cardLastName'],
"x_address" => $_POST['cardAddress'],
"x_city" => $_POST['cardCity'],
"x_state" => $_POST['cardST'],
"x_zip" => $_POST['cardZIP']
// Additional fields can be added here as outlined in the AIM integration
// guide at: http://developer.authorize.net
);
// This section takes the input fields and converts them to the proper format
// for an http post. For example: "x_login=username&x_tran_key=a1B2c3D4"
$post_string = "";
foreach( $post_values as $key => $value )
{ $post_string .= "$key=" . urlencode( $value ) . "&"; }
$post_string = rtrim( $post_string, "& " );
// This sample code uses the CURL library for php to establish a connection,
// submit the post, and record the response.
// If you receive an error, you may want to ensure that you have the curl
// library enabled in your php configuration
$request = curl_init($post_url); // initiate curl object
curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
$post_response = curl_exec($request); // execute curl post and store results in $post_response
// additional options may be required depending upon your server configuration
// you can find documentation on curl options at http://www.php.net/curl_setopt
curl_close ($request); // close curl object
// This line takes the response and breaks it into an array using the specified delimiting character
$response_array = explode($post_values["x_delim_char"],$post_response);
$response_code = $response_array[0];
$response_reason = $response_array[3];
// individual elements of the array could be accessed to read certain response
// fields. For example, response_array[0] would return the Response Code,
// response_array[2] would return the Response Reason Code.
// for a list of response fields, please review the AIM Implementation Guide
if ($response_code != 1){
return "Credit Card Error: $response_reason";
}
?>