/** * Implements all 3 steps of the Direct Post Method for demonstration * purposes. */ public static function directPostDemo($url, $api_login_id, $transaction_key, $amount = "0.00", $md5_setting = "") { // Step 1: Show checkout form to customer. if (!count($_POST) && !count($_GET)) { $fp_sequence = time(); // Any sequential number like an invoice number. echo AuthorizeNetDPM::getCreditCardForm($amount, $fp_sequence, $url, $api_login_id, $transaction_key); } elseif (count($_POST)) { $response = new SimResponse($api_login_id, $md5_setting); if ($response->isAuthorizeNet()) { if ($response->approved) { // Do your processing here. $redirect_url = $url . '?response_code=1&transaction_id=' . $response->transaction_id; } else { // Redirect to error page. $redirect_url = $url . '?response_code=' . $response->response_code . '&response_reason_text=' . $response->response_reason_text; } // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); } else { echo "Error -- not AuthorizeNet. Check your MD5 Setting."; } } elseif (!count($_POST) && count($_GET)) { if ($_GET['response_code'] == 1) { echo "Thank you for your purchase! Transaction id: " . htmlentities($_GET['transaction_id']); } else { echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); } } }
public function testIsAuthNet() { $_POST['x_amount'] = "4.12"; $_POST['x_trans_id'] = "123"; $_POST['x_MD5_Hash'] = "8FC33C32ABB3EDD8BBC4BE3E904CB47E"; $message = new Response("528udYYwz", "test"); $this->assertTrue($message->isAuthorizeNet()); $_POST['x_amount'] = "4.12"; $_POST['x_trans_id'] = "123"; $_POST['x_MD5_Hash'] = "8FC33C32BB3EDD8BBC4BE3E904CB47E"; $message = new Response("528udYYwz", "test"); $this->assertFalse($message->isAuthorizeNet()); }