/**
  *
  */
 public function testSetNormalizedLanguage_language()
 {
     $data = $this->testData;
     unset($data['uselang']);
     unset($data['language']);
     $data['language'] = 'no';
     $ddObj = new DonationData($this->getFreshGatewayObject(self::$initial_vars), $data);
     //change to test mode with explicit test data
     $returned = $ddObj->getDataEscaped();
     $this->assertEquals('no', $returned['language'], "Language 'no' was normalized out of existance. Sad.");
     $this->assertArrayNotHasKey('uselang', $returned, "'uselang' should have been removed from the data");
 }
 /**
  * Performs a transaction through the gateway. Optionally may reattempt the transaction if
  * a recoverable gateway error occurred.
  *
  * This function provides all functionality to the external world to communicate with a
  * properly constructed gateway and handle all the return data in an appropriate manner.
  * -- Appropriateness is determined by the requested $transaction structure and definition.
  *
  * @param string $transaction    The specific transaction type, like 'INSERT_ORDERWITHPAYMENT',
  *  that maps to a first-level key in the $transactions array.
  *
  * @return PaymentTransactionResponse
  */
 public function do_transaction($transaction)
 {
     $this->session_addDonorData();
     if (!$this->validatedOK()) {
         //If the data didn't validate okay, prevent all data transmissions.
         $return = new PaymentTransactionResponse();
         $return->setCommunicationStatus(false);
         $return->setMessage('Failed data validation');
         foreach ($this->getAllErrors() as $code => $error) {
             $return->addError($code, array('message' => $error, 'logLevel' => LogLevel::INFO, 'debugInfo' => ''));
         }
         // TODO: should we set $this->transaction_response ?
         $this->logger->info("Failed Validation. Aborting {$transaction} " . print_r($this->getValidationErrors(), true));
         return $return;
     }
     $retryCount = 0;
     $loopCount = $this->getGlobal('RetryLoopCount');
     do {
         $retryVars = null;
         $retval = $this->do_transaction_internal($transaction, $retryVars);
         if (!empty($retryVars)) {
             // TODO: Add more intelligence here. Right now we just assume it's the order_id
             // and that it is totally OK to just reset it and reroll.
             $this->logger->info("Repeating transaction on request for vars: " . implode(',', $retryVars));
             // Force regen of the order_id
             $this->regenerateOrderID();
             // Pull anything changed from dataObj
             $this->unstaged_data = $this->dataObj->getDataEscaped();
             $this->staged_data = $this->unstaged_data;
             $this->stageData();
         }
     } while (!empty($retryVars) && ++$retryCount < $loopCount);
     if ($retryCount >= $loopCount) {
         $this->logger->error("Transaction canceled after {$retryCount} retries.");
     }
     return $retval;
 }
 /**
  *
  */
 public function testSetNormalizedAmount_noGoodAmount()
 {
     $data = $this->testData;
     $data['amount'] = 'splunge';
     $data['amountGiven'] = 'wombat';
     $data['amountOther'] = 'macedonia';
     //unset($data['zip']);
     $ddObj = new DonationData('', true, $data);
     $returned = $ddObj->getDataEscaped();
     $this->assertEquals($returned['amount'], 0.0, "Amount was not properly reset");
     $this->assertTrue(!array_key_exists('amountOther', $returned), "amountOther should have been removed from the data");
     $this->assertTrue(!array_key_exists('amountGiven', $returned), "amountGiven should have been removed from the data");
 }