public function submitPayment() { $dir = $this->getMethodDirectory(); //require_once $dir.'anet_php_sdk/AuthorizeNet.php'; $METHOD_TO_USE = "AIM"; define("AUTHORIZENET_API_LOGIN_ID", Config::get('vividstore.authnetLoginID')); // Add your API LOGIN ID define("AUTHORIZENET_TRANSACTION_KEY", Config::get('vividstore.authnetTransactionKey')); // Add your API transaction key define("AUTHORIZENET_SANDBOX", Config::get('vividstore.authnetTestmode')); // Set to false to test against production define("TEST_REQUEST", "FALSE"); // You may want to set to true if testing against production //define("AUTHORIZENET_MD5_SETTING",""); // Add your MD5 Setting. //$site_root = ""; // Add the URL to your site if (AUTHORIZENET_API_LOGIN_ID == "") { die('Enter your merchant credentials'); } $transaction = new AuthorizeNetAIM(); $transaction->setSandbox(AUTHORIZENET_SANDBOX); $transaction->setFields(array('amount' => VividCart::getTotal(), 'card_num' => $_POST['authnet-checkout-credit-card'], 'exp_date' => $_POST['authnet-checkout-exp-month'] . $_POST['authnet-checkout-exp-year'])); $response = $transaction->authorizeAndCapture(); if ($response->approved) { return true; } else { return array('error' => 1, 'errorMessage' => $response->error_message . " Error Code: " . $response->response_code . ". Message: " . $response->response_reason_text); } }
public function testInvalidCredentials() { if (MERCHANT_LIVE_API_LOGIN_ID) { // Post a response to live server using invalid credentials. $sale = new Request('a', 'a'); $sale->setSandbox(false); $sale->setFields(array('amount' => rand(1, 1000), 'card_num' => '6011000000000012', 'exp_date' => '0415')); $response = $sale->authorizeAndCapture(); $this->assertTrue($response->error); $this->assertEquals("13", $response->response_reason_code); } }