/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } // salva a bandeira, o numero de parcelas e o token $info = $this->getInfoInstance(); $additionaldata = array('parcels_number' => $data->getParcelsNumber()); if ($data->getToken()) { $tokenData = $this->_getTokenById($data->getToken()); $additionaldata['token'] = $tokenData['token']; $data->setCcType($tokenData['ccType']); } $info->setCcType($data->getCcType())->setCcNumber(Mage::helper('core')->encrypt($data->getCcNumber()))->setCcOwner($data->getCcOwner())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcCid(Mage::helper('core')->encrypt($data->getCcCid()))->setAdditionalData(serialize($additionaldata)); // pega dados de juros $withoutInterest = intval($this->getConfigData('installment_without_interest', $this->getStoreId())); $interestValue = floatval($this->getConfigData('installment_interest_value', $this->getStoreId())); // verifica se há juros if ($data->getParcelsNumber() > $withoutInterest) { $installmentValue = Mage::helper('Query_Cielo')->calcInstallmentValue($info->getQuote()->getGrandTotal(), $interestValue / 100, $data->getParcelsNumber()); $installmentValue = round($installmentValue, 2); $interest = $installmentValue * $data->getParcelsNumber() - $info->getQuote()->getGrandTotal(); $info->getQuote()->setInterest($info->getQuote()->getStore()->convertPrice($interest, false)); $info->getQuote()->setBaseInterest($interest); $info->getQuote()->setTotalsCollectedFlag(false)->collectTotals(); $info->getQuote()->save(); } else { $info->getQuote()->setInterest(0.0); $info->getQuote()->setBaseInterest(0.0); $info->getQuote()->setTotalsCollectedFlag(false)->collectTotals(); $info->getQuote()->save(); } return $this; }