if ($payment->isDeclined()) { // Get reason for the decline from the bank. This always says, // "This credit card has been declined". Not very useful. $reason = $payment->getResponseText(); $avs_result = $payment->getAVSResponse(); // not used at this time $cvv_result = $payment->getCVVResponse(); // not used at this time // Politely tell the customer their card was declined // and to try a different form of payment. $err[] = "There was an error processing this credit card. The response from the bank was: {$reason}"; //$err[] = "AVS Result: $avs_result"; //$err[] = "CVV Result: $cvv_result"; // TODO: in case of errors, email the above info to the admin } else { if ($payment->isError()) { // Get the error number so we can reference the Authnet // documentation and get an error description. $error_number = $payment->getResponseSubcode(); $error_message = $payment->getResponseText(); // OR // Capture a detailed error message. No need to refer to the manual // with this one as it tells you everything the manual does. $full_error_message = $payment->getResponseMessage(); $avs_result = $payment->getAVSResponse(); $cvv_result = $payment->getCVVResponse(); $err[] = "Error {$error_number}: {$full_error_message}"; //$err[] = "AVS Result: $avs_result"; //$err[] = "CVV Result: $cvv_result"; // TODO: in case of errors, email the above info to the admin // We can tell what kind of error it is and handle it appropriately.
/** * Authorize and Prosses order using the AuthnetAIM.class.php class. * Fill object of the class ($payment), then send to process order, * this order then gives a echo for the payment error or recieved. * Tutorial: http://www.johnconde.net/blog/tutorial-integrating-the-authorizenet-aim-api-with-php/ * @param object $ccInfo Object containing info for the Authorize.NET API. * @return void */ function wc_AuthorizeCard($ccInfo) { require 'AuthnetAIM.class.php'; $payment = new AuthnetAIM("52H4eeYq", "7RD64g4h993VE6rp", true); $payment->setTransaction($ccInfo->getCreditCard(), $ccInfo->getExpiration(), $ccInfo->getTotal()); $payment->setParameter("x_description", $ccInfo->getProduct()); $payment->setParameter("x_email", $ccInfo->getEmail()); $payment->setParameter("x_first_name", $ccInfo->getName()); $payment->process(); if ($payment->isApproved()) { echo "Payment Received/Approved"; } if ($payment->isError()) { $error_number = $payment->getResponseSubcode(); $error_message = $payment->getResponseText(); echo $payment->getResponseMessage(); } }