2
In a payment module I’m testing, payment.phtl
extending from Mage_Payment_Model_Method_Abstract
and, for testing purposes, I put an output to a log file in two functions, public function assignData($data)
and public function validate()
, both in my class and in the original Magento class and verified in the log that function assignData($data)
original was called and in my class no, despite the function validate()
be called in both classes.
Thanks for any help.
This function of this class is not called
class Oitoo_Cielo_Model_Payment extends Mage_Payment_Model_Method_Abstract
{
/**=====================================
* Assign data to info model instance
*
* @param mixed $data
* @return Mage_Payment_Model_Info
======================================*/
public function assignData($data)
{
Mage::log(' 88 => assignData ' , null, 'cielo.log');
if (!($data instanceof Varien_Object)) {
$data = new Varien_Object($data);
}
$info = $this->getInfoInstance();
//zera os juros para evitar erros
$info->getQuote()->setJuros(0.0);
$info->getQuote()->setBaseJuros(0.0);
$info->getQuote()->getShippingAddress()->setJuros(0.0);
$info->getQuote()->getShippingAddress()->setBaseJuros(0.0);
$info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
//zera o valor do desconto para evitar erros
$info->getQuote()->setDesconto(0.0);
$info->getQuote()->setBaseDesconto(0.0);
$info->getQuote()->getShippingAddress()->setDesconto(0.0);
$info->getQuote()->getShippingAddress()->setBaseDesconto(0.0);
$info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
$info->setCcType($data->getBandeiraCielo())
->setAdditionalData($data->getParcelasCielo())
->setCcOwner($data->getPortadorCielo())
->setCcLast4(substr($data->getNumeroCartaoCielo(), -4))
//->setCcNumber($data->getCcNumber())
//->setCcCid($data->getCcCid())
->setCcExpMonth($data->getExpiracaoMesCielo())
->setCcExpYear($data->getExpiracaoAnoCielo())
->setCcCid($info->encrypt($data->getCodigoSegurancaCielo())) //criptografa o código de segurança do cartão
->setCcNumber($info->encrypt(str_replace(' ', '',$data->getNumeroCartaoCielo()))) //criptografa o numero do cartão
;
$parcela = $data->getParcelasCielo();
$valorTotal = $info->getQuote()->getGrandTotal();
// $valorDesconto = Mage::helper('apelidocielo')->getDiscountAmount($parcela,$valorTotal);
/* if($valorDesconto > 0):
// Mage::helper('apelidocielo')->setDiscountQuote($info,$valorDesconto);
endif;*/
//verifica se tem juros e aplica no carrinho. Se o retorno do getJurosAmount for maior que 0, aplica no quote.
$valorJuros = Mage::helper('apelidocielo')->getJurosAmount($parcela,$valorTotal);
$valorDesconto = -(Mage::helper('apelidocielo')->getDiscountAmount($parcela,$valorTotal));
if($valorJuros > 0):
$info->getQuote()->setJuros($valorJuros);
$info->getQuote()->setBaseJuros($valorJuros);
$info->getQuote()->getShippingAddress()->setJuros($valorJuros);
$info->getQuote()->getShippingAddress()->setBaseJuros($valorJuros);
$info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
else:
$info->getQuote()->setJuros(0.0);
$info->getQuote()->setBaseJuros(0.0);
$info->getQuote()->getShippingAddress()->setJuros(0.0);
$info->getQuote()->getShippingAddress()->setBaseJuros(0.0);
$info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
endif;
if($valorDesconto < 0):
$info->getQuote()->setDesconto($valorDesconto);
$info->getQuote()->setBaseDesconto($valorDesconto);
$info->getQuote()->getShippingAddress()->setDesconto($valorDesconto);
$info->getQuote()->getShippingAddress()->setBaseDesconto($valorDesconto);
$info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
else:
$info->getQuote()->setDesconto(0.0);
$info->getQuote()->setBaseDesconto(0.0);
$info->getQuote()->getShippingAddress()->setDesconto(0.0);
$info->getQuote()->getShippingAddress()->setBaseDesconto(0.0);
$info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
endif;
$info->getQuote()->save();
return $this;
}
This function is called but as it did not pass at first the data is not recovered.
public function validate() {
$info = $this->getInfoInstance();
$ccNumber = Mage::helper('core')->decrypt($info->getCcNumber());
$bandeira = $info->getCcType();
$validado = false;
Mage::log('178 => Bandeira ' . $bandeira. ' ccnumber ' . $ccNumber , null, 'cielo.log');
if (Mage::helper('apelidocielo')->validateCcNum($ccNumber))
{
$ccTypeRegExp = '/^4[0-9]{12}([0-9]{3})?$/'; //visa
if (preg_match($ccTypeRegExp, $ccNumber) && $bandeira == 'visa')
{
$validado = true;
}
$ccTypeRegExp = '/^5[1-5][0-9]{14}$/'; //mastercard
if (preg_match($ccTypeRegExp, $ccNumber) && $bandeira == 'mastercard')
{
$validado = true;
}
$ccTypeRegExp = '/^3[47][0-9]{13}$/'; //amex
if (preg_match($ccTypeRegExp, $ccNumber) && $bandeira == 'amex')
{
$validado = true;
}
$ccTypeRegExp = '/^6011[0-9]{12}$/'; //discover
if (preg_match($ccTypeRegExp, $ccNumber) && $bandeira == 'discover')
{
$validado = true;
}
$ccTypeRegExp = '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/'; //jcb
if (preg_match($ccTypeRegExp, $ccNumber) && $bandeira == 'jcb')
{
$validado = true;
}
$ccTypeRegExp = '/^3[0,6,8]\d{12}$/'; //diners
if (preg_match($ccTypeRegExp, $ccNumber) && $bandeira == 'diners')
{
$validado = true;
}
if ($bandeira == 'elo' || $bandeira == 'aura')
{
$validado = true;
}
} else {
Mage::throwException(Mage::helper('payment')->__('O número do cartão digitado não é válido.'));
}
if(!$validado):
Mage::throwException(Mage::helper('payment')->__('O número do cartão de crédito não é válido para bandeira selecionada: ' . $bandeira));
endif;
return $this;
}
}
Welcome to Sopt. Click [Edit] and post the code you’re having trouble helping you.
– user28595