Example #1
0
 /**
  * Authorize
  *
  * @param   Varien_Object $orderPayment
  * @param float $amount
  * @return  Mage_Payment_Model_Abstract
  */
 public function authorize(Varien_Object $payment, $amount)
 {
     $order = $payment->getOrder();
     $customerId = $order->getCustomerId();
     $orderId = $order->getId();
     if ($this->_cc) {
         ${$gwap} = $this->_gwap;
         $cc = new Varien_Object($this->_cc);
     } else {
         $gwap = Mage::getModel('gwap/order')->load($orderId, 'order_id');
         $cc = new Varien_Object(unserialize(Mage::helper('core')->decrypt($gwap->getInfo())));
     }
     $registration = $this->getRegistrationInfo($customerId, $cc->getGwapOneclickSelected());
     $parameters = $this->prepareAuthenticationRequestParameters($order, $cc, $registration);
     //Mage::log(print_r($parameters,true),null,'parametros.log');
     // Se true, não efetua PA
     if ($this->getConfig()->getAcao()) {
         //Autorização instantânea
         if ($this->_cc) {
             //Salva dados para RG (sem gravacao em tabela)
             $this->_cc = Mage::helper('core')->encrypt(serialize($parameters));
         } else {
             $gwap->clearInstance();
             $gwap = Mage::getModel('gwap/order')->load($orderId, 'order_id');
             $gwap->setInfo(Mage::helper('core')->encrypt(serialize($parameters)));
             $gwap->save();
         }
         return $this;
     }
     $url = $this->getRequestURL();
     $postString = $this->buildPostString($parameters);
     $response = $this->makeCurlRequest($url, $postString);
     if ($this->_resultCode != '90') {
         Mage::throwException('Payment code: ' . $response['PAYMENT.CODE'] . ' (' . $response['PROCESSING.REASON'] . ' - ' . $response['PROCESSING.RETURN'] . ')');
     }
     // prepare parameters to capture after Pre Authorize success
     $captureParams = $this->prepareCaptureRequestParameters($response, $registration, $payment->getCcParcelas());
     // Autorização instantânea
     if ($this->_cc) {
         $this->_cc = Mage::helper('core')->encrypt(serialize($captureParams));
     }
     $gwap->setInfo(Mage::helper('core')->encrypt(serialize($captureParams)));
     $gwap->save();
     return $this;
 }