diff --git a/assets/javascripts/front/checkout/model/payment.js b/assets/javascripts/front/checkout/model/payment.js index a34fadd7..003dc525 100644 --- a/assets/javascripts/front/checkout/model/payment.js +++ b/assets/javascripts/front/checkout/model/payment.js @@ -5,7 +5,10 @@ jQuery(function ($) { globalThis.wc_pagarme_checkout = wc_pagarme_checkout; $.jMaskGlobals.watchDataMask = true; wc_pagarme_checkout.validate = function () { - const checkedPayment = $('form .payment_methods input[name="payment_method"]:checked').val(); + const checkedPayment = $('form .payment_methods input[name="payment_method"]:checked')?.val(); + if (!checkedPayment) { + return true; + } const requiredFields = $('#shipping_number:visible, input[data-required=true]:visible,' + 'select[data-required=true]:visible,' + `.wc_payment_method.payment_method_${checkedPayment} [data-pagarmecheckout-element="brand-input"]`); diff --git a/assets/javascripts/front/checkout/model/payment/card.js b/assets/javascripts/front/checkout/model/payment/card.js index ee6d9dcd..6c59d9e5 100644 --- a/assets/javascripts/front/checkout/model/payment/card.js +++ b/assets/javascripts/front/checkout/model/payment/card.js @@ -36,7 +36,18 @@ let pagarmeCard = { return jQuery('.wc_payment_method.payment_method_' + value); }, isPagarmePayment: function () { - return jQuery('form .payment_methods input[name="payment_method"]:checked').val().indexOf('pagarme'); + let paymentSelected = jQuery('form .payment_methods input[name="payment_method"]:checked'); + if(paymentSelected.length <= 0) { + return false; + } + paymentSelected = paymentSelected.val(); + if(!paymentSelected) { + return false; + } + if(paymentSelected.indexOf('pagarme') == '-1') { + return false; + } + return paymentSelected.indexOf('pagarme'); }, keyEventHandlerCard: function (event) { this.clearToken(event); diff --git a/src/Action/OrderActions.php b/src/Action/OrderActions.php index 630e5356..10fcd127 100644 --- a/src/Action/OrderActions.php +++ b/src/Action/OrderActions.php @@ -28,6 +28,10 @@ public function showInstallmentFeesAdmin($orderId) public function showInstallmentFeesToCustomer($total_rows, $order, $tax_display) { $orderPagarme = new Order($order->get_id()); + if (!$orderPagarme->isPagarmePaymentMethod()) { + return $total_rows; + } + $total = $order->get_total(); $installmentsValue = $orderPagarme->get_meta('pagarme_card_tax'); if (empty($orderPagarme->get_meta('pagarme_card_tax'))) { @@ -37,7 +41,7 @@ public function showInstallmentFeesToCustomer($total_rows, $order, $tax_display) ); $total = $orderPagarme->getTotalAmountByCharges(); } - if ($orderPagarme->isPagarmePaymentMethod() && $installmentsValue > 0) { + if ($installmentsValue > 0) { array_pop($total_rows); $total_rows['pagarme_installment_fee']['label'] = __('Installment Fee', 'woo-pagarme-payments'); $total_rows['pagarme_installment_fee']['value'] = wc_price($installmentsValue);