Hi I got the code from here: http://community.developer.authorize.net/t5/The-Authorize-Net-Developer-Blog/Handling-Online-Payment...
It doesn't give me any errors while on test mode but any Credit Card I use, payments doesn't go through on live mode. 2 errors come up:
1. Your credit card was declined by your bank. Please try another form of payment.;
2. We encountered an error while processing your payment. Your credit card was not charged. Please try again or contact customer service to place your order.
Note: My Credit Card has more than enough balance to cover the transaction.
Below is the code: I've removed the API login ID and Transaction key as well as replaced the domain name in the code below.
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');
$errors = array();
if ('POST' === $_SERVER['REQUEST_METHOD'])
{
require('payment-functions.php');
$credit_card = sanitize($_POST['credit_card']);
$expiration_month = (int) sanitize($_POST['expiration_month']);
$expiration_year = (int) sanitize($_POST['expiration_year']);
$cvv = sanitize($_POST['cvv']);
$cardholder_first_name = sanitize($_POST['cardholder_first_name']);
$cardholder_last_name = sanitize($_POST['cardholder_last_name']);
$billing_address = sanitize($_POST['billing_address']);
$billing_address2 = sanitize($_POST['billing_address2']);
$billing_city = sanitize($_POST['billing_city']);
$billing_state = sanitize($_POST['billing_state']);
$billing_zip = sanitize($_POST['billing_zip']);
$telephone = sanitize($_POST['telephone']);
$email = sanitize($_POST['email']);
$honeypot = sanitize($_POST['ssn']);
$token = sanitize($_POST['token']);
if ($token !== $_SESSION['token'])
{
$errors['token'] = "This form submission is invalid. Please try again or contact support for additional assistance.";
}
if (!empty($honeypot))
{
$errors['hp'] = "This form submission is invalid. Please try again or contact support for additional assistance.";
}
if (!validateCreditcard_number($credit_card))
{
$errors['credit_card'] = "Please enter a valid credit card number";
}
if (!validateCreditCardExpirationDate($expiration_month, $expiration_year))
{
$errors['expiration_month'] = "Please enter a valid expiration date for your credit card";
}
if (!validateCVV($credit_card, $cvv))
{
$errors['cvv'] = "Please enter the security code (CVV number) for your credit card";
}
if (empty($cardholder_first_name))
{
$errors['cardholder_first_name'] = "Please provide the card holder's first name";
}
if (empty($cardholder_last_name))
{
$errors['cardholder_last_name'] = "Please provide the card holder's last name";
}
if (empty($billing_address))
{
$errors['billing_address'] = 'Please provide your billing address.';
}
if (empty($billing_city))
{
$errors['billing_city'] = 'Please provide the city of your billing address.';
}
if (empty($billing_state))
{
$errors['billing_state'] = 'Please provide the state for your billing address.';
}
if (empty($telephone) || strlen($telephone) > 20)
{
$errors['billing_city'] = 'Please provide a telephone number where we can reach you if necessary.';
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$errors['email'] = "Please provide a valid email address";
}
// If there are no errors let's process the payment
if (count($errors) === 0)
{
// Format the expiration date
$expiration_date = sprintf("%04d-%02d", $expiration_year, $expiration_month);
// Include the SDK
//require_once('config.php');
require_once 'AuthorizeNet.php';
define("AUTHORIZENET_API_LOGIN_ID", "");
define("AUTHORIZENET_TRANSACTION_KEY", "");
define("AUTHORIZENET_SANDBOX", false);
// Process the transaction using the AIM API
$transaction = new AuthorizeNetAIM;
$transaction->setSandbox(AUTHORIZENET_SANDBOX);
$transaction->setFields(
array(
'amount' => '20.00',
'card_num' => $credit_card,
'exp_date' => $expiration_date,
'first_name' => $cardholder_first_name,
'last_name' => $cardholder_last_name,
'address' => $billing_address,
'city' => $billing_city,
'state' => $billing_state,
'zip' => $billing_zip,
'email' => $email,
'card_code' => $cvv,
)
);
$response = $transaction->authorizeAndCapture();
if ($response->approved)
{
// Transaction approved. Collect pertinent transaction information for saving in the database.
$transaction_id = $response->transaction_id;
$authorization_code = $response->authorization_code;
$avs_response = $response->avs_response;
$cavv_response = $response->cavv_response;
// Put everything in a database for later review and order processing
// How you do this depends on how your application is designed
// and your business needs.
//unset our PRG session variable if it exists
if (isset($_SESSION['prg']))
{
unset($_SESSION['prg']);
}
$_SESSION['$transaction_id'] = $transaction_id;
$_SESSION['$authorization_code'] = $authorization_code;
$_SESSION['$avs_response'] = $avs_response;
$_SESSION['$cavv_response'] = $$cavv_response;
// Once we're finished let's redirect the user to a receipt page
header('Location: https://www.mydomain.com/introduction.php');
exit;
}
else if ($response->declined)
{
// Transaction declined. Set our error message.
$errors['declined'] = 'Your credit card was declined by your bank. Please try another form of payment.';
}
else
{
// And error has occurred. Set our error message.
$errors['error'] = 'We encountered an error while processing your payment. Your credit card was not charged. Please try again or contact customer service to place your order.';
// Collect transaction response information for possible troubleshooting
// Since our application won't be doing this we'll comment this out for now.
//
// $response_subcode = $response->response_subcode;
// $response_reason_code = $response->response_reason_code;
}
}
else
{
// Create an array in our session for use to store their variables
$_SESSION['prg'] = array();
// Put their information into the array
$_SESSION['prg']['credit_card'] = $credit_card;
$_SESSION['prg']['expiration_month'] = $expiration_month;
$_SESSION['prg']['expiration_year'] = $expiration_year;
$_SESSION['prg']['cvv'] = $cvv;
$_SESSION['prg']['cardholder_first_name'] = $cardholder_first_name;
$_SESSION['prg']['cardholder_last_name'] = $cardholder_last_name;
$_SESSION['prg']['billing_address'] = $billing_address;
$_SESSION['prg']['billing_address2'] = $billing_address2;
$_SESSION['prg']['billing_city'] = $billing_city;
$_SESSION['prg']['billing_state'] = $billing_state;
$_SESSION['prg']['billing_zip'] = $billing_zip;
$_SESSION['prg']['telephone'] = $telephone;
$_SESSION['prg']['email'] = $email;
// Don't forget the $errors array!
$_SESSION['prg']['errors'] = $errors;
// Do our redirect. Make sure it sends the 303 header
header('Location: https://www.mydomain.com/payment-form.php', true, 303);
exit;
}
}
else if (isset($_SESSION['prg']) && is_array($_SESSION['prg']))
{
// Retreive the user's information and our error messages
// Don't store the credit card information unless you are 100% sure your
// server and website is PCI compliant!
// $credit_card = $_SESSION['prg']['credit_card'];
// $expiration_month = $_SESSION['prg']['expiration_month'];
// $expiration_year = $_SESSION['prg']['expiration_year'];
$cvv = $_SESSION['prg']['cvv'];
$cardholder_first_name = $_SESSION['prg']['cardholder_first_name'];
$cardholder_last_name = $_SESSION['prg']['cardholder_last_name'];
$billing_address = $_SESSION['prg']['billing_address'];
$billing_address2 = $_SESSION['prg']['billing_address2'];
$billing_city = $_SESSION['prg']['billing_city'];
$billing_state = $_SESSION['prg']['billing_state'];
$billing_zip = $_SESSION['prg']['billing_zip'];
$telephone = $_SESSION['prg']['telephone'];
$email = $_SESSION['prg']['email'];
$errors = $_SESSION['prg']['errors'];
}
$_SESSION['token'] = md5(uniqid(rand(), true));
?>
โ12-06-2012 02:34 PM
echo the $response->response_subcode and $response->response_reason_code
and see what the error is.
โ12-06-2012 04:02 PM
it says "AVS mismatch. the address provided does not match the address of cardholder"
The fact though is it matches
โ12-06-2012 08:20 PM
What is the AVS response code? double check the billing address right before it get send to authorize.net.
โ12-07-2012 04:15 AM