diff --git a/app/code/community/RicardoMartins/PagSeguro/Helper/Data.php b/app/code/community/RicardoMartins/PagSeguro/Helper/Data.php index 8d4b6de2..ba16f5a5 100644 --- a/app/code/community/RicardoMartins/PagSeguro/Helper/Data.php +++ b/app/code/community/RicardoMartins/PagSeguro/Helper/Data.php @@ -35,6 +35,8 @@ class RicardoMartins_PagSeguro_Helper_Data extends Mage_Core_Helper_Abstract const XML_PATH_PAYMENT_PAGSEGURO_CC_INSTALLMENT_LIMIT = 'payment/rm_pagseguro_cc/installment_limit'; const XML_PATH_PAYMENT_PAGSEGURO_CC_INSTALLMENT_INTEREST_FREE_ONLY = 'payment/rm_pagseguro_cc/installments_product_interestfree_only'; + const XML_PATH_PAYMENT_PAGSEGURO_CC_INSTALLMENT_FREE_INTEREST_MINIMUM_AMT = + 'payment/rm_pagseguro_cc/installment_free_interest_minimum_amt'; const XML_PATH_PAYMENT_PAGSEGURO_NOTIFICATION_URL_NOSID= 'payment/rm_pagseguro/notification_url_nosid'; const XML_PATH_PAYMENT_PAGSEGURO_PLACEORDER_BUTTON = 'payment/rm_pagseguro/placeorder_button'; const XML_PATH_JSDELIVR_ENABLED = 'payment/rm_pagseguro/jsdelivr_enabled'; @@ -453,6 +455,7 @@ public function getConfigJs() 'force_installments_selection' => Mage::getStoreConfigFlag(self::XML_PATH_PAYMENT_PAGSEGURO_CC_FORCE_INSTALLMENTS), 'installment_limit' => (int)Mage::getStoreConfig(self::XML_PATH_PAYMENT_PAGSEGURO_CC_INSTALLMENT_LIMIT), + 'installment_free_interest_minimum_amt' => Mage::getStoreConfig(self::XML_PATH_PAYMENT_PAGSEGURO_CC_INSTALLMENT_FREE_INTEREST_MINIMUM_AMT), 'placeorder_button' => Mage::getStoreConfig(self::XML_PATH_PAYMENT_PAGSEGURO_PLACEORDER_BUTTON), 'loader_url' => Mage::getDesign()->getSkinUrl('pagseguro/ajax-loader.gif', array('_secure'=>true)), 'stc_mirror' => $this->isStcMirrorEnabled() @@ -658,4 +661,17 @@ public function isStcMirrorEnabled() { return $this->getLicenseType() == 'app' && Mage::getStoreConfigFlag(self::XML_PATH_STC_MIRROR); } + + public function getMaxInstallmentsNoInterest($amount) + { + $freeAmt = Mage::getStoreConfig( + self::XML_PATH_PAYMENT_PAGSEGURO_CC_INSTALLMENT_FREE_INTEREST_MINIMUM_AMT + ); + $selectedMaxInstallmentNoInterest = $freeAmt === 0 ? : ''; + if ($freeAmt > 0) { + $selectedMaxInstallmentNoInterest = $amount / $freeAmt; + $selectedMaxInstallmentNoInterest = (int)floor($selectedMaxInstallmentNoInterest); + } + return $selectedMaxInstallmentNoInterest; + } } \ No newline at end of file diff --git a/app/code/community/RicardoMartins/PagSeguro/Model/Payment/Cc.php b/app/code/community/RicardoMartins/PagSeguro/Model/Payment/Cc.php index 098779f0..f8bd45a5 100644 --- a/app/code/community/RicardoMartins/PagSeguro/Model/Payment/Cc.php +++ b/app/code/community/RicardoMartins/PagSeguro/Model/Payment/Cc.php @@ -326,7 +326,7 @@ protected function _order($payment, $amount, $ccIdx) // call API $returnXml = $this->callApi($params, $payment); - + // creates Magento transactions $transaction = $this->_createOrderTransaction($payment, $amount, $ccIdx, $returnXml); @@ -1199,8 +1199,9 @@ public function getInstallmentValue( $maxInstallmentNoInterest = null ) { $amount = number_format($amount, 2, '.', ''); + $sandbox = $this->_helper->isSandbox() ? 'sandbox.' : ''; $sessionId = $this->_helper->getSessionId(); - $url = "https://pagseguro.uol.com.br/checkout/v2/installments.json?sessionId=$sessionId&amount=$amount"; + $url = "https://{$sandbox}pagseguro.uol.com.br/checkout/v2/installments.json?sessionId=$sessionId&amount=$amount"; $url .= "&creditCardBrand=$creditCardBrand"; $url .= ($maxInstallmentNoInterest) ? "&maxInstallmentNoInterest=$maxInstallmentNoInterest" : ""; @@ -1249,8 +1250,9 @@ public function recalculateInstallmentsAndPlaceOrder($payment, $amount) . 'As parcelas serão recalculadas e uma nova tentativa será realizada.', null, 'pagseguro.log', true ); - - $selectedMaxInstallmentNoInterest = null; //not implemented + + $selectedMaxInstallmentNoInterest = $this->_helper->getMaxInstallmentsNoInterest($amount); + $installmentValue = $this->getInstallmentValue( $amount, $payment->getCcType(), $payment->getAdditionalInformation('installment_quantity'), $selectedMaxInstallmentNoInterest @@ -1265,4 +1267,5 @@ public function recalculateInstallmentsAndPlaceOrder($payment, $amount) Mage::throwException($e->getMessage()); } } + } diff --git a/app/code/community/RicardoMartins/PagSeguro/Test/Helper/Params.php b/app/code/community/RicardoMartins/PagSeguro/Test/Helper/Params.php index 3f58e18d..603eaa7b 100644 --- a/app/code/community/RicardoMartins/PagSeguro/Test/Helper/Params.php +++ b/app/code/community/RicardoMartins/PagSeguro/Test/Helper/Params.php @@ -18,6 +18,12 @@ public function testItemValuesWithInstallments() } + + public function testGetMaxInstallmentsNoInterest() + { + $cc = Mage::getModel('ricardomartins_pagseguro/payment_cc'); + $this->assertEquals('1','2'); + } //@TODO Improve it protected function getItemData1() { diff --git a/app/code/community/RicardoMartins/PagSeguro/etc/config.xml b/app/code/community/RicardoMartins/PagSeguro/etc/config.xml index 93c91604..bf21155a 100644 --- a/app/code/community/RicardoMartins/PagSeguro/etc/config.xml +++ b/app/code/community/RicardoMartins/PagSeguro/etc/config.xml @@ -2,7 +2,7 @@ - 3.14.2 + 3.15.0 diff --git a/app/code/community/RicardoMartins/PagSeguro/etc/system.xml b/app/code/community/RicardoMartins/PagSeguro/etc/system.xml index 84edf05b..4ef63ffb 100644 --- a/app/code/community/RicardoMartins/PagSeguro/etc/system.xml +++ b/app/code/community/RicardoMartins/PagSeguro/etc/system.xml @@ -432,8 +432,21 @@ 1 1 1 - + + + + text + 100 + 1 + 1 + 1 + + validate-number validate-not-negative-number + Saiba mais.]]> + 120 diff --git a/app/design/frontend/base/default/template/ricardomartins_pagseguro/product/installments.phtml b/app/design/frontend/base/default/template/ricardomartins_pagseguro/product/installments.phtml index f6de44ee..ef0d40a2 100644 --- a/app/design/frontend/base/default/template/ricardomartins_pagseguro/product/installments.phtml +++ b/app/design/frontend/base/default/template/ricardomartins_pagseguro/product/installments.phtml @@ -8,6 +8,7 @@ $_maxInstallments = (int)Mage::getStoreConfig( $_installmentsFreeOnly = (int)Mage::getStoreConfig( RicardoMartins_PagSeguro_Helper_Data::XML_PATH_PAYMENT_PAGSEGURO_CC_INSTALLMENT_INTEREST_FREE_ONLY ); +$_maxInstallmentNoInterest = $_helper->getMaxInstallmentsNoInterest($_price); ?>
@@ -28,9 +29,12 @@ $_installmentsFreeOnly = (int)Mage::getStoreConfig( }) var updateInstallments = function() { + var maxInstallmentNoInterest = ""; + PagSeguroDirectPayment.getInstallments({ amount: , brand: 'visa', + maxInstallmentNoInterest: maxInstallmentNoInterest, success: function (response) { var responseVisa = response.installments.visa; var maxInstallmentsConfig = ; diff --git a/app/design/frontend/base/default/template/ricardomartins_pagseguro/tests/standalonecc.phtml b/app/design/frontend/base/default/template/ricardomartins_pagseguro/tests/standalonecc.phtml deleted file mode 100644 index 154e4b29..00000000 --- a/app/design/frontend/base/default/template/ricardomartins_pagseguro/tests/standalonecc.phtml +++ /dev/null @@ -1,134 +0,0 @@ -getSessionId() : $_COOKIE['ps_sessionid']; -setcookie('ps_sessionid', $sessionId, time()+300); -$_grandTotal = 100; -$_installments = 10; -?> - - - - - - - - - Exemplo CC PagSeguro - - - getItemsCount()){ - Mage::getSingleton('customer/session')->addError('Adicione um produto ao carrinho antes de testar'); - Mage::app()->getResponse()->setRedirect(Mage::getUrl('/')); - } - echo '

Loaded at: ' . date('H:i:s') . ' - ' . uniqid() . '

'; - echo sprintf('

Session id: %s

', var_export($sessionId, true)); - echo sprintf('

Sender hash(cached): %s

', var_export($pHelper->getPaymentHash('sender_hash'), true)); - ?> - getRequest()->getPost())):?> -
-

Posted Data:

getRequest()->getPost());?>

-

Sender hash: getPaymentHash('sender_hash');?>

-

Credit card token: getPaymentHash('credit_card_token');?>

-
- -
-
- Dados do Cartão - - - - - - - - - - -
- -
- - - - - - - - diff --git a/js/pagseguro/pagseguro.js b/js/pagseguro/pagseguro.js index 9b0b1a1f..b73ac16c 100644 --- a/js/pagseguro/pagseguro.js +++ b/js/pagseguro/pagseguro.js @@ -2,7 +2,7 @@ * PagSeguro Transparente para Magento * @author Ricardo Martins * @link https://github.com/r-martins/PagSeguro-Magento-Transparente - * @version 3.12.5 + * @version 3.15.0 */ RMPagSeguro = Class.create({ @@ -66,6 +66,7 @@ RMPagSeguro = Class.create({ return true; }, + //used when multicc is DISABLED getInstallments: function(grandTotal, selectedInstallment){ var brandName = ""; if(typeof RMPagSeguroObj.brand == "undefined"){ @@ -76,15 +77,21 @@ RMPagSeguro = Class.create({ return; } this.grandTotal = grandTotal; - brandName = RMPagSeguroObj.brand.name; + brandName = RMPagSeguroObj.brand.name; var parcelsDrop = $('rm_pagseguro_cc_cc_installments'); if(!selectedInstallment && parcelsDrop.value != ""){ selectedInstallment = parcelsDrop.value.split('|').first(); } + var maxInstallmentNoInterest = RMPagSeguroObj.config.installment_free_interest_minimum_amt === "0" ? 0 : ""; + if (RMPagSeguroObj.config.installment_free_interest_minimum_amt > 0) { + maxInstallmentNoInterest = grandTotal / RMPagSeguroObj.config.installment_free_interest_minimum_amt; + maxInstallmentNoInterest = Math.floor(maxInstallmentNoInterest); + } PagSeguroDirectPayment.getInstallments({ amount: grandTotal, brand: brandName, + maxInstallmentNoInterest: maxInstallmentNoInterest, success: function(response) { for(installment in response.installments) break; // console.log(response.installments); @@ -1320,12 +1327,19 @@ RMPagSeguro_Multicc_CardForm = Class.create this.setCardMetadata("installments_description", "Buscando parcelas na PagSeguro..."); //this._insert1xInstallmentsOption(); + var maxInstallmentNoInterest = this.config.installment_free_interest_minimum_amt === "0" ? 0 : ""; + if (this.config.installment_free_interest_minimum_amt > 0) { + maxInstallmentNoInterest = this.getCardData("total").toFixed(2) / this.config.installment_free_interest_minimum_amt; + maxInstallmentNoInterest = Math.floor(maxInstallmentNoInterest); + } + var params = { brand: this.getCardData("brand"), amount: this.getCardData("total").toFixed(2), success: this._populateInstallments.bind(this), - error: this._populateSafeInstallments.bind(this) + error: this._populateSafeInstallments.bind(this), + maxInstallmentNoInterest: maxInstallmentNoInterest }; this.parentObj.queuePSCall("getInstallments", params);