コード例 #1
0
 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);
     }
 }
コード例 #2
0
 public function testGetUnsettledTransactionList()
 {
     $sale = new AimRequest();
     $amount = rand(1, 100);
     $response = $sale->authorizeAndCapture($amount, '4012888818888', '04/17');
     $this->assertTrue($response->approved);
     $request = new Request();
     $response = $request->getUnsettledTransactionList();
     $this->assertTrue($response->isOk());
     $this->assertTrue($response->xml->transactions->count() >= 1);
 }
コード例 #3
0
 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);
     }
 }
コード例 #4
0
 public function testUpdateSplitTenderGroup()
 {
     // Create a partial auth test transaction
     $amount = 4.92;
     $sale = new AimRequest();
     $sale->amount = $amount;
     $sale->card_num = '4222222222222';
     $sale->zip = "46225";
     $sale->exp_date = '04/24';
     $sale->allow_partial_auth = true;
     $response = $sale->authorizeAndCapture();
     $this->assertTrue($response->held);
     $this->assertEquals("1.23", $response->amount);
     $this->assertEquals($amount, $response->requested_amount);
     $split_tender_id = $response->split_tender_id;
     // Charge a bit more
     $sale = new AimRequest();
     $sale->amount = 1.23;
     $sale->card_num = '6011000000000012';
     $sale->exp_date = '04/26';
     $sale->split_tender_id = $split_tender_id;
     $sale->allow_partial_auth = true;
     $response = $sale->authorizeAndCapture();
     $this->assertTrue($response->approved);
     // Void the group of partial auths.
     $request = new Request();
     $response = $request->updateSplitTenderGroup($split_tender_id, "voided");
     $this->assertTrue($response->isOk());
 }
コード例 #5
0
 public function testSetBadField()
 {
     try {
         $amount = rand(1, 1000);
         $zipcode = "02301";
         $sale = new Request();
         $sale->setFields(array('amount' => $amount, 'card_num' => '6011000000000012', 'exp_date' => '0415', 'zipcode' => $zipcode));
         $result = $sale->authorizeAndCapture();
         $this->assertTrue($result->approved);
         // should have thrown an exception by now
         $this->assertFalse(true);
     } catch (AuthorizeNetException $e) {
         $this->assertTrue(true);
     }
 }