-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
783 changed files
with
64,621 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
app/code/community/Ebanx/Gateway/Block/Adminhtml/System/Config/Form/Field/Interest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
173 changes: 173 additions & 0 deletions
173
app/code/community/Ebanx/Gateway/Block/Catalog/Product/View/Oneclick.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
41
app/code/community/Ebanx/Gateway/Block/Checkout/Cart/Total.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/code/community/Ebanx/Gateway/Block/Checkout/Success/Cashpayment.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/code/community/Ebanx/Gateway/Block/Checkout/Success/Creditcardpayment.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
Oops, something went wrong.