Skip to content

Commit

Permalink
Merge branch 'release/3.15.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
r-martins committed Feb 8, 2022
2 parents 875034f + 59d36c2 commit 1ae4f78
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 143 deletions.
16 changes: 16 additions & 0 deletions app/code/community/RicardoMartins/PagSeguro/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
}
11 changes: 7 additions & 4 deletions app/code/community/RicardoMartins/PagSeguro/Model/Payment/Cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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" : "";

Expand Down Expand Up @@ -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
Expand All @@ -1265,4 +1267,5 @@ public function recalculateInstallmentsAndPlaceOrder($payment, $amount)
Mage::throwException($e->getMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/RicardoMartins/PagSeguro/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<RicardoMartins_PagSeguro>
<version>3.14.2</version>
<version>3.15.0</version>
</RicardoMartins_PagSeguro>
</modules>
<global>
Expand Down
15 changes: 14 additions & 1 deletion app/code/community/RicardoMartins/PagSeguro/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,21 @@
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment><![CDATA[Limita o número de parcelas. A configuração de juros é sempre feita no seu painel PagSeguro.]]></comment>
<comment><![CDATA[Limita o número de parcelas.]]></comment>
</installment_limit>
<installment_free_interest_minimum_amt>
<label>Valor de parcela mínima sem juros</label>
<frontend_type>text</frontend_type>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<tooltip><![CDATA[
Esta configuração permite especificar qual um valor mínimo de parcela onde o vendedor (você) assume os juros. Ao colocar o valor 10 neste campo, um pedido de R$ 100 poderá ser parcelado em até 10x sem juros.
]]></tooltip>
<validate>validate-number validate-not-negative-number</validate>
<comment><![CDATA[Ao especificar um valor, as configurações de promoções feitas em seu painel PagSeguro serão ignoradas. <a href="//bit.ly/34927gh" target="_blank">Saiba mais.</a>]]></comment>
</installment_free_interest_minimum_amt>
<installments_product>
<label>Exibir parcelas na página de produto?</label>
<sort_order>120</sort_order>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
?>

<div id="rmpagseguro_parcelas_box">
Expand All @@ -28,9 +29,12 @@ $_installmentsFreeOnly = (int)Mage::getStoreConfig(

})
var updateInstallments = function() {
var maxInstallmentNoInterest = "<?php echo $_maxInstallmentNoInterest?>";

PagSeguroDirectPayment.getInstallments({
amount: <?php echo $_price?>,
brand: 'visa',
maxInstallmentNoInterest: maxInstallmentNoInterest,
success: function (response) {
var responseVisa = response.installments.visa;
var maxInstallmentsConfig = <?php echo $_maxInstallments ?>;
Expand Down

This file was deleted.

20 changes: 17 additions & 3 deletions js/pagseguro/pagseguro.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* PagSeguro Transparente para Magento
* @author Ricardo Martins <[email protected]>
* @link https://github.com/r-martins/PagSeguro-Magento-Transparente
* @version 3.12.5
* @version 3.15.0
*/

RMPagSeguro = Class.create({
Expand Down Expand Up @@ -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"){
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1ae4f78

Please sign in to comment.