<commit_before><?php

class Ebanx_Gateway_Block_Catalog_Product_View_Oneclick extends Mage_Core_Block_Template
{
	/**
	 * @var array|Ebanx_Gateway_Model_Resource_Usercard_Collection
	 */
	public $usercards;
	/**
	 * @var Mage_Customer_Model_Customer
	 */
	public $customer;

	public function __construct(array $args = [])
	{
		parent::__construct($args);
		$this->initialize();
	}

	public function getText()
	{
		return [
			'local-amount' => 'Total a pagar com IOF (0.38%): ',
			'cvv'          => 'Código de segurança',
			'instalments'  => 'Número de parcelas',
		];
	}

	public function getAddress()
	{
		$addressId = $this->customer->getDefaultShipping();
		if (!$addressId) {
			return '';
		}
		$address = Mage::getModel('customer/address')->load($addressId)->getData();

		return $address;
	}

	public function canShowOneclickButton()
	{
		return Mage::getSingleton('customer/session')->isLoggedIn()
			   && $this->usercards
			   && $this->usercards->getSize()
			   && $this->getAddress()['street']
			   && ($this->customer->getEbanxCustomerDocument()
				   || $this->getCountry() === 'MX');
	}

	private function initialize()
	{
		if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
			$this->usercards = [];
		}
		$this->customer = Mage::getSingleton('customer/session')->getCustomer();

		$this->usercards = Mage::getModel('ebanx/usercard')->getCustomerSavedCards($this->customer->getId());
	}

	/**
	 * @return string
	 */
	private function getCountry()
	{
		return $this->getAddress()['country_id'];
	}

	/**
	 * @return string
	 */
	public function getLocalCurrency()
	{
		return $this->getAddress()['country_id'] === 'MX' ? 'MXN' : 'BRL';
	}

	public function getLocalAmount($currency, $formatted = true)
	{
		$amount = round(Mage::helper('ebanx')->getLocalAmountWithTax($currency, $this->getTotal()), 2);

		return $formatted ? $this->formatPriceWithLocalCurrency($currency, $amount) : $amount;
	}

	private function formatPriceWithLocalCurrency($currency, $price)
	{
		return Mage::app()->getLocale()->currency($currency)->toCurrency($price);
	}

	public function getTotal()
	{
		return Mage::registry('current_product')->getPrice();
	}

	public function getInstalmentTerms()
	{
		return $this->getMethod()->getInstalmentTerms($this->getTotal());
	}

	/**
	 * @return Ebanx_Gateway_Model_Payment_Creditcard
	 */
	private function getMethod()
	{
		return $this->getAddress()['country_id'] === 'MX' ? new Ebanx_Gateway_Model_Mexico_Creditcard() : new Ebanx_Gateway_Model_Brazil_Creditcard();
	}

	public function formatInstalment($instalment)
	{
		$amount = Mage::helper('core')->formatPrice($instalment->baseAmount, false);
		$instalmentNumber = $instalment->instalmentNumber;
		$interestMessage = $this->getInterestMessage($instalment->hasInterests);
		$message = sprintf('%sx de %s %s', $instalmentNumber, $amount, $interestMessage);
		return $message;
	}
}<commit_msg>Fixed oneclick<commit_after><?php

class Ebanx_Gateway_Block_Catalog_Product_View_Oneclick extends Mage_Core_Block_Template
{
	/**
	 * @var array|Ebanx_Gateway_Model_Resource_Usercard_Collection
	 */
	public $usercards;
	/**
	 * @var Mage_Customer_Model_Customer
	 */
	public $customer;

	public function __construct(array $args = [])
	{
		parent::__construct($args);
		$this->initialize();
	}

	public function getText()
	{
		return [
			'local-amount' => 'Total a pagar com IOF (0.38%): ',
			'cvv'          => 'Código de segurança',
			'instalments'  => 'Número de parcelas',
		];
	}

	public function getAddress()
	{
		$addressId = $this->customer->getDefaultShipping();
		if (!$addressId) {
			return [];
		}
		$address = Mage::getModel('customer/address')->load($addressId)->getData();

		return $address;
	}

	public function canShowOneclickButton()
	{
		return Mage::getSingleton('customer/session')->isLoggedIn()
			   && $this->usercards
			   && $this->usercards->getSize()
			   && $this->getAddress()['street']
			   && ($this->customer->getEbanxCustomerDocument()
				   || $this->getCountry() === 'MX');
	}

	private function initialize()
	{
		if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
			$this->usercards = [];
		}
		$this->customer = Mage::getSingleton('customer/session')->getCustomer();

		$this->usercards = Mage::getModel('ebanx/usercard')->getCustomerSavedCards($this->customer->getId());
	}

	/**
	 * @return string
	 */
	private function getCountry()
	{
		$address = $this->getAddress();
		if (!array_key_exists('country_id', $address)) {
			return '';
		}

		return $address['country_id'];
	}

	/**
	 * @return string
	 */
	public function getLocalCurrency()
	{
		return $this->getCountry() === 'MX' ? 'MXN' : 'BRL';
	}

	public function getLocalAmount($currency, $formatted = true)
	{
		$amount = round(Mage::helper('ebanx')->getLocalAmountWithTax($currency, $this->getTotal()), 2);

		return $formatted ? $this->formatPriceWithLocalCurrency($currency, $amount) : $amount;
	}

	private function formatPriceWithLocalCurrency($currency, $price)
	{
		return Mage::app()->getLocale()->currency($currency)->toCurrency($price);
	}

	public function getTotal()
	{
		return Mage::registry('current_product')->getPrice();
	}

	public function getInstalmentTerms()
	{
		return $this->getMethod()->getInstalmentTerms($this->getTotal());
	}

	/**
	 * @return Ebanx_Gateway_Model_Payment_Creditcard
	 */
	private function getMethod()
	{
		return $this->getCountry() === 'MX' ? new Ebanx_Gateway_Model_Mexico_Creditcard() : new Ebanx_Gateway_Model_Brazil_Creditcard();
	}

	public function formatInstalment($instalment)
	{
		$amount           = Mage::helper('core')->formatPrice($instalment->baseAmount, false);
		$instalmentNumber = $instalment->instalmentNumber;
		$interestMessage  = $this->getInterestMessage($instalment->hasInterests);
		$message          = sprintf('%sx de %s %s', $instalmentNumber, $amount, $interestMessage);

		return $message;
	}
}
{'fraction_non_alphanumeric': 0.17144797148192156, 'fraction_numerical': 0.0013580037345102699, 'mean_word_length': 4.874376869391824, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2016880', 'n_tokens_mistral': 2117, 'n_tokens_neox': 1950, 'n_words': 307}