public function initialize($paymentAction, $stateObject) { parent::initialize($paymentAction, $stateObject); if ($paymentAction != 'sale') { return $this; } // Set the default state of the new order. $state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT; // state now = 'pending_payment' $stateObject->setState($state); $stateObject->setStatus($state); $stateObject->setIsNotified(false); //Retrieve cart/quote information. $sessionCheckout = Mage::getSingleton('checkout/session'); $quoteId = $sessionCheckout->getQuoteId(); // obtiene el quote para informacion de la orden $quote = Mage::getModel("sales/quote")->load($quoteId); $grandTotal = $quote->getData('grand_total'); $subTotal = $quote->getSubtotal(); $shippingHandling = $grandTotal - $subTotal; $convertQuote = Mage::getSingleton('sales/convert_quote'); $order = $convertQuote->toOrder($quote); $orderNumber = $order->getIncrementId(); // obtener datos del pago en info y asignar monto total $infoIntance = $this->getInfoInstance(); $info = unserialize($infoIntance->getAdditionalData()); $info['idPedido'] = $orderNumber; $info['prod'] = trim($this->getConfigData('prod')); $info['idSucursal'] = trim($this->getConfigData('sucursalkey')); $info['idUsuario'] = trim($this->getConfigData('usuariokey')); $info['monto'] = $grandTotal; $info['ipBuyer'] = $_SERVER['REMOTE_ADDR']; $info['noMail'] = (int) trim($this->getConfigData('notify')) == 1 ? 0 : 1; $info['plan'] = (int) trim($this->getConfigData('msi')) == 1 ? $info['mensualidades'] == '00' ? 'NOR' : 'MSI' : 'NOR'; // enviar pago try { $Api = new Pagofacil_Pagofacildirect_Model_Api(); $response = $Api->payment($info); } catch (Exception $error) { Mage::throwException($error->getMessage()); } // respuesta del servicio if ($response == null) { Mage::throwException("El servicio de PagoFacil no se encuentra"); } if ($response['autorizado'] == '0') { $errorMessage = $response['texto'] . "\n"; if (is_array($response['error'])) { $errorMessage .= implode("\n", array_values($response['error'])); } Mage::throwException($errorMessage); } return $this; }