Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
adam ling committed Jul 6, 2018
2 parents fe66e27 + c03e4ec commit a7dcff3
Show file tree
Hide file tree
Showing 783 changed files with 64,621 additions and 74 deletions.
1 change: 1 addition & 0 deletions app/code/community/Adyen/Payment/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function addMethodsToConfig(Varien_Event_Observer $observer = null)
}
}


if (Mage::getStoreConfigFlag('payment/adyen_hpp/active', $store)) {
// by default disable adyen_ideal only if IDeal is in directoryLookup result show this payment method
$store->setConfig('payment/adyen_ideal/active', 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

class Ebanx_Gateway_Block_Adminhtml_System_Config_Form_Field_Interest
extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
{
public function __construct()
{
$this->addColumn('instalments', array(
'label' => Mage::helper('ebanx')->__('Up To'),
'style' => 'width:120px',
));

$this->addColumn('interest', array(
'label' => Mage::helper('ebanx')->__('Interest Rate'),
'style' => 'width:120px',
));

$this->_addAfter = false;

parent::__construct();
}

/**
* Render array cell for prototypeJS template
*
* @param string $columnName
* @return string
*/
protected function _renderCellTemplate($columnName)
{
if (empty($this->_columns[$columnName])) {
throw new Exception('Wrong column name specified.');
}

$column = $this->_columns[$columnName];
$elementName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
$extraParams = ' data-value="#{' . $columnName . '}" ' .
(isset($column['style']) ? ' style="' . $column['style'] . '"' : '');

if ($columnName == 'instalments') {
return $this->getInstallmentsSelectHtml($elementName, $extraParams);
}
return parent::_renderCellTemplate($columnName);
}

/**
* @param $name
* @param $extraParams
* @return string
*/
public function getInstallmentsSelectHtml($name, $extraParams)
{
$select = $this->getLayout()->createBlock('adminhtml/html_select')
->setName($name)
->setClass('select-instalments')
->setExtraParams($extraParams)
->setOptions(Mage::getSingleton('ebanx/source_instalment')->toOptionArray());

return $select->getHtml();
}

/**
* Render block HTML
*
* @return string
*/
protected function _toHtml()
{
$fieldId = $this->getElement()->getId();

$html = "<div id=\"$fieldId\">";
$html .= parent::_toHtml();
$html .= Mage::helper('adminhtml/js')->getScript(
"$$('.select-instalments').each(function(el){ el.value = el.readAttribute('data-value'); });\n"
);
$html .= '</div>';

return $html;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?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 = array())
{
parent::__construct($args);
$this->initialize();
}

public function getText()
{
$country = $this->getCountry();
$text = array(
'local-amount' => 'Total a pagar en Peso mexicano: ',
'cvv' => 'Código de verificación',
'instalments' => 'Número de parcelas',
);
switch ($country) {
case 'BR':
$text['local-amount'] = $this->getLocalAmountText();
$text['cvv'] = 'Código de segurança';
break;
case 'CO':
$text['local-amount'] = 'Total a pagar en Peso mexicano: ';
break;
case 'AR':
$text['local-amount'] = 'Total a pagar en Peso argentino: ';
break;
default:
break;
}
return $text;
}

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

return $address;
}

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

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

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

private function countryDocumentIsOptional($country) {
$isOptional = array(
'MX',
'CO',
'AR',
);

return in_array($country, $isOptional);
}

/**
* @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()
{
switch ($this->getCountry()) {
case 'MX':
return 'MXN';
case 'CO':
return 'COP';
case 'AR':
return 'ARS';
case 'BR':
default:
return '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()
{
switch ($this->getCountry()) {
case 'MX':
return new Ebanx_Gateway_Model_Mexico_Creditcard();
case 'CO':
return new Ebanx_Gateway_Model_Colombia_Creditcard();
case 'AR':
return new Ebanx_Gateway_Model_Argentina_Creditcard();
case 'BR':
default:
return new Ebanx_Gateway_Model_Brazil_Creditcard();
}
}

private function getLocalAmountText() {
return Mage::getStoreConfig('payment/ebanx_settings/iof_local_amount')
? 'Total a pagar com IOF (0.38%): '
: 'Total a pagar: ';
}

public function formatInstalment($instalment, $localCurrency)
{
$amount = Mage::app()->getLocale()->currency($localCurrency)->toCurrency($instalment->localAmountWithTax);
$instalmentNumber = $instalment->instalmentNumber;
$interestMessage = $this->getInterestMessage($instalment->hasInterests);
$message = sprintf('%sx de %s %s', $instalmentNumber, $amount, $interestMessage);

return $message;
}
}
41 changes: 41 additions & 0 deletions app/code/community/Ebanx/Gateway/Block/Checkout/Cart/Total.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

class Ebanx_Gateway_Block_Checkout_Cart_Total extends Mage_Core_Block_Template
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('ebanx/checkout/cart/total.phtml');
}

protected function _toHtml()
{
if ($this->getAmount() == $this->_getQuote()->getBaseGrandTotal()) {
return '';
}
return parent::_toHtml();
}

public function getAmount()
{
$amount = $this->_getQuote()->getBaseGrandTotal();
$payment = $this->_getPayment();
if ($payment->getMethod() == 'ebanx_cc_br') {
// TODO: Get instalments
// TODO: Get interest rate
// TODO: Calc amount
}

return $amount;
}

protected function _getQuote()
{
return Mage::getSingleton('checkout/session')->getQuote();
}

protected function _getPayment()
{
return $this->_getQuote()->getPayment();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

class Ebanx_Gateway_Block_Checkout_Success_Cashpayment extends Ebanx_Gateway_Block_Checkout_Success_Payment
{
protected $_order;

public function getEbanxDueDate($format = 'dd/MM')
{
$date = new Zend_Date($this->getPayment()->getEbanxDueDate());

return $date->get($format);
}

public function getEbanxUrlPrint()
{
$hash = $this->getEbanxPaymentHash();
return $this->helper->getVoucherUrlByHash($hash, 'print');
}

public function getEbanxPaymentHash()
{
return $this->getOrder()->getPayment()->getEbanxPaymentHash();
}

public function getEbanxUrlPdf()
{
$hash = $this->getEbanxPaymentHash();
return $this->helper->getVoucherUrlByHash($hash, 'pdf');
}

public function getEbanxUrlBasic()
{
$hash = $this->getEbanxPaymentHash();
return $this->helper->getVoucherUrlByHash($hash, 'basic');
}

public function getVoucherUrl()
{
return Mage::getUrl('ebanx/voucher', array(
'hash' => $this->getEbanxPaymentHash()
));
}

public function getEbanxUrlMobile()
{
$hash = $this->getEbanxPaymentHash();
return $this->helper->getVoucherUrlByHash($hash, 'mobile');
}

protected function _construct()
{
parent::_construct();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class Ebanx_Gateway_Block_Checkout_Success_Creditcardpayment extends Ebanx_Gateway_Block_Checkout_Success_Payment
{
protected function _construct()
{
parent::_construct();
}

}
Loading

0 comments on commit a7dcff3

Please sign in to comment.