From 33863c943858d66c7d7755416ade63ecc5e87665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Vitor=20Oliveira?= Date: Thu, 16 Feb 2023 20:07:49 +0000 Subject: [PATCH] =?UTF-8?q?Cart=C3=A3o=20e=20Boleto:=20Melhoria=20no=20c?= =?UTF-8?q?=C3=A1lculo=20e=20exibi=C3=A7=C3=A3o=20dos=20descontos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class-wc-gerencianet-boleto.php | 28 +++++++++++++------ .../class-wc-gerencianet-cartao.php | 13 ++++----- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/includes/payment-methods/class-wc-gerencianet-boleto.php b/includes/payment-methods/class-wc-gerencianet-boleto.php index 980b7af..248112a 100644 --- a/includes/payment-methods/class-wc-gerencianet-boleto.php +++ b/includes/payment-methods/class-wc-gerencianet-boleto.php @@ -160,6 +160,20 @@ public function payment_fields() { echo wpautop( wp_kses_post( $this->description ) ); } + if(intval( $this->get_option( 'gn_billet_discount' ) ) > 0){ + $discountMessage = ''; + if ( $this->get_option( 'gn_billet_discount_shipping' ) == 'total' ) { + $discountMessage = ' no valor total da compra (frete incluso)'; + }else{ + $discountMessage = ' no valor total dos produtos (frete não incluso)'; + } + + $discountWarn = '
+
' .esc_html( $this->get_option( 'gn_billet_discount' ) ) . '% de Desconto'.$discountMessage. '
+
'; + echo wpautop( wp_kses_post( $discountWarn ) ); + } + $is_sandbox = $this->get_option( 'gn_sandbox' ) == 'yes' ? true : false; if ( $is_sandbox ) { $sandboxWarn = '
@@ -241,11 +255,11 @@ public function process_payment( $order_id ) { case 'line_item': $product = $item->get_product(); $newItem = array( - 'name' => $item->get_name(), + 'name' => $product->get_name(), 'amount' => $item->get_quantity(), - 'value' => $item->get_total() * 100, + 'value' => $product->get_price() * 100, ); - $orderTotal += $item->get_total() * 100 * $item->get_quantity(); + $orderTotal += $product->get_price() * 100 * $item->get_quantity(); $items[] = $newItem; break; default: @@ -300,17 +314,15 @@ public function process_payment( $order_id ) { $discount_gn = 0; if ( $this->get_option( 'gn_billet_discount_shipping' ) == 'total' ) { - $discountMessage = ' no valor total da compra'; if ( isset( $shipping[0]['value'] ) ) { - $discount_gn = ( $orderTotal + $shipping[0]['value'] ) * ( intval( $this->get_option( 'gn_billet_discount' ) ) / 100 ); + $discount_gn = round(( $orderTotal + $shipping[0]['value'] ) * ( intval( $this->get_option( 'gn_billet_discount' ) ) / 100 ), 0, PHP_ROUND_HALF_UP); $discount['value'] += $discount_gn; } else { - $discount_gn = ( ( $orderTotal ) * ( intval( $this->get_option( 'gn_billet_discount' ) ) / 100 ) ); + $discount_gn = round( ( $orderTotal ) * ( intval( $this->get_option( 'gn_billet_discount' ) ) / 100 ), 0, PHP_ROUND_HALF_UP ); $discount['value'] += $discount_gn; } } else { - $discountMessage = ' no valor total dos produtos (frete não incluso)'; - $discount_gn = ( $orderTotal * ( intval( $this->get_option( 'gn_billet_discount' ) ) / 100 ) ); + $discount_gn = round( $orderTotal * ( intval( $this->get_option( 'gn_billet_discount' ) ) / 100 ), 0, PHP_ROUND_HALF_UP ); $discount['value'] += $discount_gn; } $order_item_id = wc_add_order_item( diff --git a/includes/payment-methods/class-wc-gerencianet-cartao.php b/includes/payment-methods/class-wc-gerencianet-cartao.php index 0fbbf50..d42c247 100644 --- a/includes/payment-methods/class-wc-gerencianet-cartao.php +++ b/includes/payment-methods/class-wc-gerencianet-cartao.php @@ -222,13 +222,12 @@ public function process_payment( $order_id ) { 'amount' => 1, 'value' => $item->get_subtotal() * 100, ); - $orderTotal += $item->get_subtotal() * 100; $items[] = $newFee; break; case 'shipping': if ( $item->get_total() > 0 ) { $shipping[] = array( - 'name' => __( 'Frete', Gerencianet_I18n::getTextDomain() ), + 'name' => __( 'Frete', Gerencianet_I18n::getTextDomain()), 'value' => $item->get_total() * 100, ); } @@ -236,18 +235,17 @@ public function process_payment( $order_id ) { case 'coupon': $newDiscount = array( 'type' => 'currency', - 'value' => $item->get_total() * 100, + 'value' => $item->get_discount() * 100, ); $discount = $newDiscount; break; case 'line_item': $product = $item->get_product(); $newItem = array( - 'name' => $item->get_name(), + 'name' => $product->get_name(), 'amount' => $item->get_quantity(), - 'value' => $item->get_total() * 100, + 'value' => $product->get_price() * 100, ); - $orderTotal += $item->get_total() * 100 * $item->get_quantity(); $items[] = $newItem; break; default: @@ -257,7 +255,6 @@ public function process_payment( $order_id ) { 'amount' => $item->get_quantity(), 'value' => $product->get_price() * 100, ); - $orderTotal += $product->get_price() * 100 * $item->get_quantity(); $items[] = $newItem; break; } @@ -308,7 +305,7 @@ public function process_payment( $order_id ) { ); try { - $response = $this->gerencianetSDK->one_step_card( $order_id, $items, $shipping, strtolower( $woocommerce->api_request_url( GERENCIANET_CARTAO_ID ) ), $customer, $paymentToken, $installments, $billingAddress ); + $response = $this->gerencianetSDK->one_step_card( $order_id, $items, $shipping, strtolower( $woocommerce->api_request_url( GERENCIANET_CARTAO_ID ) ), $customer, $paymentToken, $installments, $billingAddress, $discount ); $charge = json_decode( $response, true ); $order->update_status( 'pending-payment' );