From 5f4d542cf2244f0d2299c0a5852be1a142c5bdf9 Mon Sep 17 00:00:00 2001 From: Ricardo Martins Date: Mon, 14 Mar 2022 18:10:45 +1100 Subject: [PATCH 1/5] =?UTF-8?q?-=20Corre=C3=A7=C3=A3o:=20Um=20problema=20n?= =?UTF-8?q?o=20c=C3=A1lculo=20do=20parcelamento=20ocorria=20em=20casos=20o?= =?UTF-8?q?nde=20o=20valor=20da=20parcela=20m=C3=ADnima=20sem=20juros=20er?= =?UTF-8?q?a=20superior=20ao=20valor=20total=20do=20pedido=20multiplicado?= =?UTF-8?q?=20por=20dois.=20-=20Descoberta:=20Quando=20temos=20uma=20promo?= =?UTF-8?q?=C3=A7=C3=A3o=20de=20parcelamento=20configurada=20no=20PagSegur?= =?UTF-8?q?o,=20n=C3=A3o=20devemos=20usar=20o=20recurso=20de=20"valor=20da?= =?UTF-8?q?=20parcela=20m=C3=ADnima".=20Embora=20as=20APIs=20do=20PagSegur?= =?UTF-8?q?o=20no=20c=C3=A1lculo=20de=20parcelas=20consigam=20calcular=20o?= =?UTF-8?q?=20valor=20correto=20do=20parcelamento,=20nos=20casos=20onde=20?= =?UTF-8?q?nenhuma=20parcela=20sem=20juros=20=C3=A9=20permitido=20faz=20co?= =?UTF-8?q?m=20que=20a=20API=20de=20pagamento=20do=20PagSeguro=20gere=20er?= =?UTF-8?q?ros=20impedindo=20a=20finaliza=C3=A7=C3=A3o=20de=20pedidos.=20E?= =?UTF-8?q?m=20outras=20palavras,=20ao=20usar=20o=20recurso=20de=20"Valor?= =?UTF-8?q?=20m=C3=ADnimo=20de=20parcela=20sem=20juros"=20voc=C3=AA=20deve?= =?UTF-8?q?=20desativar=20ou=20excluir=20qualquer=20promo=C3=A7=C3=A3o=20c?= =?UTF-8?q?riada=20no=20PagSeguro.=20Saiba=20mais=20em=20https://bit.ly/3q?= =?UTF-8?q?1GfiL8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RicardoMartins/PagSeguro/Helper/Data.php | 13 +++++++++++-- .../RicardoMartins/PagSeguro/Helper/Params.php | 15 ++++++++------- .../RicardoMartins/PagSeguro/etc/system.xml | 4 ++-- js/pagseguro/pagseguro.js | 2 ++ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/code/community/RicardoMartins/PagSeguro/Helper/Data.php b/app/code/community/RicardoMartins/PagSeguro/Helper/Data.php index ba16f5a5..266cf9fc 100644 --- a/app/code/community/RicardoMartins/PagSeguro/Helper/Data.php +++ b/app/code/community/RicardoMartins/PagSeguro/Helper/Data.php @@ -667,11 +667,20 @@ public function getMaxInstallmentsNoInterest($amount) $freeAmt = Mage::getStoreConfig( self::XML_PATH_PAYMENT_PAGSEGURO_CC_INSTALLMENT_FREE_INTEREST_MINIMUM_AMT ); - $selectedMaxInstallmentNoInterest = $freeAmt === 0 ? : ''; + if ($freeAmt === null) { + return false; + } + + if ($freeAmt <= 0) { + return 1; + } + + $selectedMaxInstallmentNoInterest = 1; if ($freeAmt > 0) { $selectedMaxInstallmentNoInterest = $amount / $freeAmt; $selectedMaxInstallmentNoInterest = (int)floor($selectedMaxInstallmentNoInterest); } - return $selectedMaxInstallmentNoInterest; + + return ($selectedMaxInstallmentNoInterest > 1) ? $selectedMaxInstallmentNoInterest : false; //prevents 0 } } \ No newline at end of file diff --git a/app/code/community/RicardoMartins/PagSeguro/Helper/Params.php b/app/code/community/RicardoMartins/PagSeguro/Helper/Params.php index 2d802c4a..23b55282 100644 --- a/app/code/community/RicardoMartins/PagSeguro/Helper/Params.php +++ b/app/code/community/RicardoMartins/PagSeguro/Helper/Params.php @@ -159,7 +159,7 @@ public function getCreditCardInstallmentsParams(Mage_Sales_Model_Order $order, $ isset($cardData["installments_qty"]) && isset($cardData["installments_value"]) ) { - return array + $return = array ( 'installmentQuantity' => $cardData["installments_qty"], 'installmentValue' => $cardData["installments_value"], @@ -170,7 +170,7 @@ public function getCreditCardInstallmentsParams(Mage_Sales_Model_Order $order, $ { if ($payment->getAdditionalInformation('installment_quantity') && $payment->getAdditionalInformation('installment_value')) { - return array + $return = array ( 'installmentQuantity' => $payment->getAdditionalInformation('installment_quantity'), 'installmentValue' => number_format( @@ -180,11 +180,12 @@ public function getCreditCardInstallmentsParams(Mage_Sales_Model_Order $order, $ } } - return array - ( - 'installmentQuantity' => '1', - 'installmentValue' => number_format($order->getGrandTotal(), 2, '.', ''), - ); + $maxInstallmentsNoInterest = Mage::helper('ricardomartins_pagseguro') + ->getMaxInstallmentsNoInterest($order->getGrandTotal()); + + if ($maxInstallmentsNoInterest !== false) { + $return['noInterestInstallmentQuantity'] = $maxInstallmentsNoInterest; + } return $return; } diff --git a/app/code/community/RicardoMartins/PagSeguro/etc/system.xml b/app/code/community/RicardoMartins/PagSeguro/etc/system.xml index 4ef63ffb..c1ebdf35 100644 --- a/app/code/community/RicardoMartins/PagSeguro/etc/system.xml +++ b/app/code/community/RicardoMartins/PagSeguro/etc/system.xml @@ -442,10 +442,10 @@ 1 1 validate-number validate-not-negative-number - Saiba mais.]]> + DEVE desativar ou remover qualquer promoção salva no seu painel PagSeguro. Saiba mais.]]> diff --git a/js/pagseguro/pagseguro.js b/js/pagseguro/pagseguro.js index b73ac16c..e23a80a1 100644 --- a/js/pagseguro/pagseguro.js +++ b/js/pagseguro/pagseguro.js @@ -87,6 +87,7 @@ RMPagSeguro = Class.create({ if (RMPagSeguroObj.config.installment_free_interest_minimum_amt > 0) { maxInstallmentNoInterest = grandTotal / RMPagSeguroObj.config.installment_free_interest_minimum_amt; maxInstallmentNoInterest = Math.floor(maxInstallmentNoInterest); + maxInstallmentNoInterest = (maxInstallmentNoInterest > 1) ? maxInstallmentNoInterest : ''; } PagSeguroDirectPayment.getInstallments({ amount: grandTotal, @@ -1331,6 +1332,7 @@ RMPagSeguro_Multicc_CardForm = Class.create 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); + maxInstallmentNoInterest = (maxInstallmentNoInterest > 1) ? maxInstallmentNoInterest : ''; } var params = From 41000ea6874976b3186e61eee0911c574353a514 Mon Sep 17 00:00:00 2001 From: Fillipe Date: Thu, 17 Mar 2022 19:34:39 -0300 Subject: [PATCH 2/5] Forca o status do pedido para que o cancelamento funcione quando o um dos cartoes estah em revisao de pagamento --- .../community/RicardoMartins/PagSeguro/Model/Abstract.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/code/community/RicardoMartins/PagSeguro/Model/Abstract.php b/app/code/community/RicardoMartins/PagSeguro/Model/Abstract.php index b117deae..05d1870a 100644 --- a/app/code/community/RicardoMartins/PagSeguro/Model/Abstract.php +++ b/app/code/community/RicardoMartins/PagSeguro/Model/Abstract.php @@ -727,6 +727,13 @@ protected function _cancelOrder($payment, $notification) if($orderCancellation->getShouldCancel()) { + // checks if the order state is 'Pending Payment' and changes it + // so that the order can be cancelled + if ($order->getState() == Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW) + { + $order->setState(Mage_Sales_Model_Order::STATE_NEW); + } + $order->cancel(); } } From bc996a47be5ba88bfa63a8df142a9de4bccf1cf2 Mon Sep 17 00:00:00 2001 From: Ricardo Martins Date: Fri, 18 Mar 2022 11:46:41 +1100 Subject: [PATCH 3/5] =?UTF-8?q?Melhorando=20coment=C3=A1rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/RicardoMartins/PagSeguro/Model/Abstract.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/community/RicardoMartins/PagSeguro/Model/Abstract.php b/app/code/community/RicardoMartins/PagSeguro/Model/Abstract.php index 05d1870a..3da22a3e 100644 --- a/app/code/community/RicardoMartins/PagSeguro/Model/Abstract.php +++ b/app/code/community/RicardoMartins/PagSeguro/Model/Abstract.php @@ -728,12 +728,12 @@ protected function _cancelOrder($payment, $notification) if($orderCancellation->getShouldCancel()) { // checks if the order state is 'Pending Payment' and changes it - // so that the order can be cancelled - if ($order->getState() == Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW) - { + // so that the order can be cancelled. Orders with STATE_PAYMENT_REVIEW cannot be cancelled by default in + // Magento. See #181550828 for details + if ($order->getState() == Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW) { $order->setState(Mage_Sales_Model_Order::STATE_NEW); } - + $order->cancel(); } } From 413dc1b4b3e9408a574f6124a6436ff2574690ab Mon Sep 17 00:00:00 2001 From: Ricardo Martins Date: Fri, 18 Mar 2022 12:19:45 +1100 Subject: [PATCH 4/5] =?UTF-8?q?Outro=20ajuste=20na=20corre=C3=A7=C3=A3o=20?= =?UTF-8?q?do=20problema=20de=20parcelamento=20invalido?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RicardoMartins/PagSeguro/Helper/Data.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app/code/community/RicardoMartins/PagSeguro/Helper/Data.php b/app/code/community/RicardoMartins/PagSeguro/Helper/Data.php index 266cf9fc..6dfc6c45 100644 --- a/app/code/community/RicardoMartins/PagSeguro/Helper/Data.php +++ b/app/code/community/RicardoMartins/PagSeguro/Helper/Data.php @@ -667,20 +667,14 @@ public function getMaxInstallmentsNoInterest($amount) $freeAmt = Mage::getStoreConfig( self::XML_PATH_PAYMENT_PAGSEGURO_CC_INSTALLMENT_FREE_INTEREST_MINIMUM_AMT ); - if ($freeAmt === null) { - return false; - } - if ($freeAmt <= 0) { - return 1; + if (!$freeAmt || $freeAmt <= 0) { + return false; } - $selectedMaxInstallmentNoInterest = 1; - if ($freeAmt > 0) { - $selectedMaxInstallmentNoInterest = $amount / $freeAmt; - $selectedMaxInstallmentNoInterest = (int)floor($selectedMaxInstallmentNoInterest); - } + $selectedMaxInstallmentNoInterest = $amount / $freeAmt; + $selectedMaxInstallmentNoInterest = (int)floor($selectedMaxInstallmentNoInterest); - return ($selectedMaxInstallmentNoInterest > 1) ? $selectedMaxInstallmentNoInterest : false; //prevents 0 + return ($selectedMaxInstallmentNoInterest > 1) ? $selectedMaxInstallmentNoInterest : false; //prevents 0 or 1 } } \ No newline at end of file From 128d189d591d11243096f0e0df2c70d7b76789f5 Mon Sep 17 00:00:00 2001 From: Ricardo Martins Date: Fri, 18 Mar 2022 12:21:02 +1100 Subject: [PATCH 5/5] Atualizando versao --- app/code/community/RicardoMartins/PagSeguro/etc/config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/RicardoMartins/PagSeguro/etc/config.xml b/app/code/community/RicardoMartins/PagSeguro/etc/config.xml index bf21155a..db6d3bbb 100644 --- a/app/code/community/RicardoMartins/PagSeguro/etc/config.xml +++ b/app/code/community/RicardoMartins/PagSeguro/etc/config.xml @@ -2,7 +2,7 @@ - 3.15.0 + 3.15.1