Skip to content

Commit

Permalink
Merge pull request #48 from pallomabritoGN/master
Browse files Browse the repository at this point in the history
Correção de formatação do checkout
  • Loading branch information
jvoliveiraGN authored May 24, 2023
2 parents 832eda6 + 869ea87 commit 4d12cb9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
7 changes: 4 additions & 3 deletions assets/js/scripts-cartao.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jQuery(document).ready(function ($) {

if(!document.getElementById('swalCss')){
if (!document.getElementById('swalCss')) {
let swalCss = $("<style id='swalCss'></style>").html(".colored-toast .swal2-title {color: white;}.colored-toast .swal2-close {color: white;}.colored-toast .swal2-html-container {color: white;}.colored-toast.swal2-icon-error {background-color: #f27474 !important;}")
$("#payment").after(swalCss);
}
Expand Down Expand Up @@ -58,7 +58,8 @@ jQuery(document).ready(function ($) {
// Buscar Parcelas
jQuery("#gn_cartao_number").keyup(function () {

let total = document.querySelector("#order_review > table > tfoot > tr.order-total > td > strong > span > bdi").innerHTML.replace('<span class="woocommerce-Price-currencySymbol">R$</span>', '').replaceAll(',', '').replaceAll('.', '').replaceAll('&nbsp;', '');
let total = document.querySelector("#gn_payment_total").value;
total = parseInt(total.replace('.', ''));
console.log(total);

if (jQuery("#gn_cartao_number").val().length >= 19) {
Expand Down Expand Up @@ -312,7 +313,7 @@ jQuery(document).ready(function ($) {
if (msg == 'Error: O total fornecido é superior ao limite máximo por transação.')
msg = 'O valor total da compra é superior ao limite para emissão.'

if(msg.toString().includes('Identificador de conta'))
if (msg.toString().includes('Identificador de conta'))
msg = 'Identificador de Conta inválido. Entre em contato com o administrador da loja.'

if (msg != null && msg != '') {
Expand Down
4 changes: 2 additions & 2 deletions gerencianet-oficial.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Plugin Name: Efí by Gerencianet Oficial
* Plugin URI: https://wordpress.org/plugins/woo-gerencianet-official/
* Description: Gateway de pagamento Efi by Gerencianet para WooCommerce
* Version: 2.0.11
* Version: 2.0.12
* Author: Efi by Gerencianet
* Author URI: https://www.sejaefi.com.br
* License: GPL-2.0+
Expand All @@ -25,7 +25,7 @@
die;
}

define( 'GERENCIANET_OFICIAL_VERSION', '2.0.11' );
define( 'GERENCIANET_OFICIAL_VERSION', '2.0.12' );
define( 'GERENCIANET_BOLETO_ID', 'WC_Gerencianet_Boleto' );
define( 'GERENCIANET_CARTAO_ID', 'WC_Gerencianet_Cartao' );
define( 'GERENCIANET_PIX_ID', 'WC_Gerencianet_Pix' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(array $options = null)
'headers' => [
'Content-Type' => 'application/json',
'api-sdk' => 'php-' . $composerData['version'],
'wordpress-plugin' => 'v2.0.11', // ATUALIZAR VERSÃO A CADA ATUALIZAÇÃO
'wordpress-plugin' => 'v2.0.12', // ATUALIZAR VERSÃO A CADA ATUALIZAÇÃO
'partner-token' => $partner_token
]
];
Expand Down
23 changes: 14 additions & 9 deletions includes/payment-methods/class-wc-gerencianet-boleto.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ public function init_form_fields() {
);
}

public function gn_price_format($value){
$value = number_format($value, 2, "", "");
return $value;
}

public function payment_fields() {
if ( $this->description ) {
echo wpautop( wp_kses_post( $this->description ) );
Expand Down Expand Up @@ -234,23 +239,23 @@ public function process_payment( $order_id ) {
$newFee = array(
'name' => __( 'Taxas', Gerencianet_I18n::getTextDomain() ),
'amount' => 1,
'value' => $item->get_subtotal() * 100,
'value' => (int)$this->gn_price_format($item->get_subtotal()),
);
$orderTotal += $item->get_subtotal() * 100;
$orderTotal += (int)$this->gn_price_format($item->get_subtotal());
$items[] = $newFee;
break;
case 'shipping':
if ( $item->get_total() > 0 ) {
$shipping[] = array(
'name' => __( 'Frete', Gerencianet_I18n::getTextDomain() ),
'value' => $item->get_total() * 100,
'value' => (int)$this->gn_price_format($item->get_total()),
);
}
break;
case 'coupon':
$newDiscount = array(
'type' => 'currency',
'value' => $item->get_discount() * 100,
'value' => (int)$this->gn_price_format($item->get_discount()),
);
$discount = $newDiscount;
break;
Expand All @@ -259,19 +264,19 @@ public function process_payment( $order_id ) {
$newItem = array(
'name' => $product->get_name(),
'amount' => $item->get_quantity(),
'value' => $product->get_price() * 100,
'value' => (int)$this->gn_price_format($product->get_price()),
);
$orderTotal += $product->get_price() * 100 * $item->get_quantity();
$orderTotal += (int)$this->gn_price_format($product->get_price() * $item->get_quantity());
$items[] = $newItem;
break;
default:
$product = $item->get_product();
$newItem = array(
'name' => $item->get_name(),
'amount' => $item->get_quantity(),
'value' => $product->get_price() * 100,
'value' => (int)$this->gn_price_format($product->get_price()),
);
$orderTotal += $product->get_price() * 100 * $item->get_quantity();
$orderTotal += (int)$this->gn_price_format($product->get_price() * $item->get_quantity());
$items[] = $newItem;
break;
}
Expand All @@ -281,7 +286,7 @@ public function process_payment( $order_id ) {
$newItem = array(
'name' => 'Taxas',
'amount' => 1,
'value' => $order->get_total_tax() * 100,
'value' => (int)$this->gn_price_format($order->get_total_tax())
);
array_push($items, $newItem);
}
Expand Down
18 changes: 12 additions & 6 deletions includes/payment-methods/class-wc-gerencianet-cartao.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function __construct() {
add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
}

public function gn_price_format($value){
$value = number_format($value, 2, "", "");
return $value;
}

public function init_form_fields() {

$this->form_fields = array(
Expand Down Expand Up @@ -159,6 +164,7 @@ public function payment_fields() {
<select id="gn_cartao_installments" name="gn_cartao_installments" style="display:none;width: 100%;border-color: #dcd7ca;"></select>
</div>
<input id="gn_payment_token" name="gn_payment_token" type="hidden">
<input id="gn_payment_total" name="gn_payment_total" type="hidden" value="<?php echo WC()->cart->total; ?>">
<script src="<?php echo plugins_url( '../assets/js/vanilla-masker.min.js', plugin_dir_path( __FILE__ ) ); ?>"></script>
<script>
var options = {
Expand Down Expand Up @@ -228,22 +234,22 @@ public function process_payment( $order_id ) {
$newFee = array(
'name' => __( 'Taxas', Gerencianet_I18n::getTextDomain() ),
'amount' => 1,
'value' => $item->get_subtotal() * 100,
'value' => (int)$this->gn_price_format($item->get_subtotal()),
);
$items[] = $newFee;
break;
case 'shipping':
if ( $item->get_total() > 0 ) {
$shipping[] = array(
'name' => __( 'Frete', Gerencianet_I18n::getTextDomain()),
'value' => $item->get_total() * 100,
'value' => (int)$this->gn_price_format($item->get_total()),
);
}
break;
case 'coupon':
$newDiscount = array(
'type' => 'currency',
'value' => $item->get_discount() * 100,
'value' => (int)$this->gn_price_format($item->get_discount()),
);
$discount = $newDiscount;
break;
Expand All @@ -252,7 +258,7 @@ public function process_payment( $order_id ) {
$newItem = array(
'name' => $product->get_name(),
'amount' => $item->get_quantity(),
'value' => $product->get_price() * 100,
'value' => (int)$this->gn_price_format($product->get_price()),
);
$items[] = $newItem;
break;
Expand All @@ -261,7 +267,7 @@ public function process_payment( $order_id ) {
$newItem = array(
'name' => $item->get_name(),
'amount' => $item->get_quantity(),
'value' => $product->get_price() * 100,
'value' => (int)$this->gn_price_format($product->get_price()),
);
$items[] = $newItem;
break;
Expand All @@ -272,7 +278,7 @@ public function process_payment( $order_id ) {
$newItem = array(
'name' => 'Taxas',
'amount' => 1,
'value' => $order->get_total_tax() * 100,
'value' => (int)$this->gn_price_format($order->get_total_tax()),
);
array_push($items, $newItem);
}
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: Efí Bank
Tags: woocommerce, gerencianet, payment, transparent checkout, pix, Boleto, card, brazil, payments brazil, cartão de crédito, efí, efi, efipay, efi bank, efi pay, efípay, efí bank, efí pay
Requires at least: 5.x
Tested up to: 6.2
Stable tag: 2.0.11
Stable tag: 2.0.12
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down

0 comments on commit 4d12cb9

Please sign in to comment.