Example #1
0
 /**
  * Send authorize request to gateway
  *
  * @param   Varien_Object $payment
  * @param   decimal $amount
  * @return  Mage_Paygate_Model_Authorizenet
  */
 public function authorize(Varien_Object $payment, $amount)
 {
     $payment->setAmount($this->getQuote()->getGrandTotal());
     $error = false;
     $security = $this->getSecurityKey();
     $payment->setSuSecurity($security);
     if ($payment->getAmount()) {
         $amount = number_format($this->getQuote()->getGrandTotal(), 2, '.', '');
         $billing = $this->getQuote()->getBillingAddress();
         $locale = explode('_', Mage::app()->getLocale()->getLocaleCode());
         if (is_array($locale) && !empty($locale) && in_array($locale[0], $this->_supportedLocales)) {
             $locale = strtoupper($locale[0]);
         } else {
             $locale = strtoupper($this->getDefaultLocale());
         }
         $params = array('user_id' => $this->getConfigData('customer'), 'project_id' => $this->getConfigData('project'), 'amount' => $amount, 'reason_1' => Mage::helper('pnsofortueberweisung')->__('Order: ') . $this->getQuote()->getReservedOrderId(), 'reason_2' => '', 'sender_holder' => $payment->getSuHolder(), 'sender_account_number' => $payment->getSuAccountNumber(), 'sender_bank_code' => $payment->getSuBankCode(), 'sender_bank_bic' => $payment->getSuBic(), 'sender_iban' => $payment->getSuIban(), 'sender_country_id' => $billing->getCountry(), 'user_variable_0' => $this->getQuote()->getReservedOrderId(), 'user_variable_1' => $payment->getSuSecurity(), 'user_variable_2' => '', 'user_variable_3' => '', 'user_variable_4' => '', 'user_variable_5' => '', 'expires' => $this->getConfigData('expires'), 'language_id' => $locale);
         if ($this->getConfigData('check_input_yesno') == 1) {
             $params['hash'] = md5(implode('|', $params) . '|' . $this->getConfigData('project_pswd'));
         }
         $result = $this->_postRequest($params);
         if (strstr($result, 'Errors') === false) {
             $payment->setSuPaycode($result);
             $payment->setStatus(self::STATUS_APPROVED);
         } else {
             $error = Mage::helper('pnsofortueberweisung')->__('Please check your account data.');
         }
     } else {
         $error = Mage::helper('pnsofortueberweisung')->__('Invalid amount for authorization.');
     }
     if ($error !== false) {
         Mage::throwException($error);
     }
     return $this;
 }