diff --git a/.codeclimate.yml b/.codeclimate.yml index ad813d9f..bf870692 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -2,7 +2,7 @@ engines: duplication: enabled: false csslint: - enabled: true + enabled: false phpmd: enabled: true checks: diff --git a/readme.txt b/readme.txt index 90f6a789..62fbb471 100644 --- a/readme.txt +++ b/readme.txt @@ -11,7 +11,7 @@ Tested up to: 6.4 WC requires at least: 3.0.0 WC tested up to: 8.6.1 Requires PHP: 5.6 -Stable Tag: 1.2.7 +Stable Tag: 1.2.8 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -40,6 +40,11 @@ Para dúvidas e suporte técnico, entre em contato com a equipe Vindi através d == Changelog == += 1.2.8 - 05/04/2024 = +-Lançamento da versão de patch. +- **Melhoria:** Adiciona o método de pagamento BolePix +- **Correção:** Bug ao atualizar produtos do tipo assinatura + = 1.2.7 - 04/04/2024 = -Lançamento da versão de patch. - **Melhoria:** Adiciona o método de pagamento Pix diff --git a/src/VindiWoocommerce.php b/src/VindiWoocommerce.php index abad2fc2..5cc3f28d 100644 --- a/src/VindiWoocommerce.php +++ b/src/VindiWoocommerce.php @@ -142,6 +142,7 @@ public function init() require_once plugin_dir_path(__FILE__) . '/includes/gateways/CreditPayment.php'; require_once plugin_dir_path(__FILE__) . '/includes/gateways/BankSlipPayment.php'; require_once plugin_dir_path(__FILE__) . '/includes/gateways/PixPayment.php'; + require_once plugin_dir_path(__FILE__) . '/includes/gateways/BolepixPayment.php'; require_once plugin_dir_path(__FILE__) . '/utils/SubscriptionStatusHandler.php'; require_once plugin_dir_path(__FILE__) . '/utils/InterestPriceHandler.php'; @@ -187,6 +188,7 @@ public function add_gateway($methods) $methods[] = new VindiCreditGateway($this->settings, $this->controllers); $methods[] = new VindiBankSlipGateway($this->settings, $this->controllers); $methods[] = new VindiPixGateway($this->settings, $this->controllers); + $methods[] = new VindiBolepixGateway($this->settings, $this->controllers); return $methods; } diff --git a/src/assets/css/frontend.css b/src/assets/css/frontend.css index 652dd518..e499a2b4 100644 --- a/src/assets/css/frontend.css +++ b/src/assets/css/frontend.css @@ -337,6 +337,9 @@ line-height: 17px; } .vindi_payment_listing .charges .charge .download_button { + width: 150px; + height: 40px; + margin: 5px 0; padding: 12px 20px; background: #FFFFFF; border: 1px solid #006DFF; diff --git a/src/assets/js/thankyou.js b/src/assets/js/thankyou.js index 3da58622..581e6f78 100644 --- a/src/assets/js/thankyou.js +++ b/src/assets/js/thankyou.js @@ -33,16 +33,16 @@ class Thankyou { } copyPixLine() { - const btn = document.querySelector('#copy_vindi_pix_code'); + const buttons = document.querySelectorAll('.copy_vindi_line'); - if(btn) { + buttons.forEach((btn) => { btn.addEventListener('click', () => { const text = btn.getAttribute('data-code'); if (navigator?.clipboard?.writeText) { navigator.clipboard.writeText(text); } }); - } + }) } } diff --git a/src/controllers/PlansController.php b/src/controllers/PlansController.php index 6ac94eb4..d40f04b2 100644 --- a/src/controllers/PlansController.php +++ b/src/controllers/PlansController.php @@ -78,10 +78,8 @@ function create($post_id, $post, $update, $recreated = false) $post_status = get_post_status($post_id); $vindi_plan_id = get_post_meta($post_id, 'vindi_plan_id', true); - if (!$recreated && $post_status != 'publish') { - if (!empty($vindi_plan_id)) { - return $this->update($post_id); - } + if (!$recreated && $post_status != 'publish' || !empty($vindi_plan_id)) { + return $this->update($post_id); } $product = wc_get_product($post_id); diff --git a/src/includes/gateways/BolepixPayment.php b/src/includes/gateways/BolepixPayment.php new file mode 100644 index 00000000..df935fb8 --- /dev/null +++ b/src/includes/gateways/BolepixPayment.php @@ -0,0 +1,147 @@ +id = 'vindi-bolepix'; + $this->icon = apply_filters('vindi_woocommerce_bolepix_icon', ''); + $this->method_title = __('Vindi - Bolepix', VINDI); + $this->method_description = __('Aceitar pagamentos via Bolepix utilizando a Vindi.', VINDI); + $this->has_fields = true; + $this->supports = array( + 'subscriptions', + 'products', + 'subscription_cancellation', + 'subscription_reactivation', + 'subscription_suspension', + 'subscription_amount_changes', + 'subscription_payment_method_change', + 'subscription_payment_method_change_customer', + 'subscription_payment_method_change_admin', + 'subscription_date_changes', + 'multiple_subscriptions', + 'pre-orders' + ); + $this->init_form_fields(); + $this->init_settings(); + add_action('woocommerce_view_order', array(&$this, 'show_bolepix_download'), -10, 1); + add_action('woocommerce_thankyou_' . $this->id, array(&$this, 'thank_you_page')); + parent::__construct($vindiSettings, $controllers); + } + + /** + * Should return payment type for payment processing. + * @return string + */ + public function type() + { + return 'bolepix'; + } + + public function init_form_fields() + { + + $this->form_fields = array( + 'enabled' => array( + 'title' => __('Habilitar/Desabilitar', VINDI), + 'label' => __('Habilitar pagamento por Bolepix com Vindi', VINDI), + 'type' => 'checkbox', + 'default' => 'no', + ), + 'title' => array( + 'title' => __('Título', VINDI), + 'type' => 'text', + 'description' => __('Título que o cliente verá durante o processo de pagamento.', VINDI), + 'default' => __('Bolepix', VINDI), + ) + ); + } + + # Essa função é responsável por verificar a compra que está sendo feita + # No caso de uma assinatura única, o $order[0] não existirá e retornará ela mesmo + # Issue: https://github.com/vindi/vindi-woocommerce/issues/75 + public function bolepix_quantity_to_render($order) + { + if (!isset($order[0])) { + return $order; + } + + return $order[0]; + } + + public function payment_fields() + { + $user_country = $this->get_country_code(); + + if (empty($user_country)) { + _e('Selecione o País para visualizar as formas de pagamento.', VINDI); + return; + } + + $is_single_order = $this->is_single_order(); + $is_trial = $this->vindi_settings->get_is_active_sandbox(); + if ($is_trial) { + $is_trial = $this->routes->isMerchantStatusTrialOrSandbox(); + } + + $this->vindi_settings->get_template('bolepix-checkout.html.php', compact('is_trial', 'is_single_order')); + } + + public function thank_you_page($order_id) + { + $order = wc_get_order($order_id); + $vindi_order = []; + $order_to_iterate = 0; + + if ($order->get_payment_method() == 'vindi-bolepix') { + $vindi_order = $order->get_meta('vindi_order', true); + $order_to_iterate = $this->bolepix_quantity_to_render($vindi_order); + $this->vindi_settings->get_template( + 'bolepix-download.html.php', + compact('vindi_order', 'order_to_iterate', 'order_id') + ); + } + } + + public function show_bolepix_download($order_id) + { + $order = wc_get_order($order_id); + $vindi_order = []; + $order_to_iterate = 0; + + if ($order->get_payment_method() == 'vindi-bolepix') { + $vindi_order = $order->get_meta('vindi_order', true); + $order_to_iterate = $this->bolepix_quantity_to_render($vindi_order); + if (!$order->is_paid() && !$order->has_status('cancelled')) { + $this->vindi_settings->get_template( + 'bolepix-download.html.php', + compact('vindi_order', 'order_to_iterate', 'order_id') + ); + } + } + } +} diff --git a/src/includes/gateways/PixPayment.php b/src/includes/gateways/PixPayment.php index 92251deb..b92444ef 100644 --- a/src/includes/gateways/PixPayment.php +++ b/src/includes/gateways/PixPayment.php @@ -3,7 +3,7 @@ namespace VindiPaymentGateways; /** - * Vindi Payment PIX Card Gateway class. + * Vindi Payment PIX Gateway class. * * Extended by individual payment gateways to handle payments. * @@ -30,7 +30,7 @@ public function __construct(VindiSettings $vindiSettings, VindiControllers $cont $this->id = 'vindi-pix'; $this->icon = apply_filters('vindi_woocommerce_pix_icon', ''); $this->method_title = __('Vindi - PIX', VINDI); - $this->method_description = __('Aceitar pagamentos via boleto bancário utilizando a Vindi.', VINDI); + $this->method_description = __('Aceitar pagamentos via PIX utilizando a Vindi.', VINDI); $this->has_fields = true; $this->supports = array( 'subscriptions', diff --git a/src/templates/bolepix-checkout.html.php b/src/templates/bolepix-checkout.html.php new file mode 100644 index 00000000..9066c2b1 --- /dev/null +++ b/src/templates/bolepix-checkout.html.php @@ -0,0 +1,33 @@ + + + +
+

+

+ Modo Trial. + Este modo é proposto para a realização de testes e, portanto, + nenhum pedido será efetivamente cobrado.', + VINDI + ); ?> +

+
+ +
+ + +
+ +
+
+ + + +
+
diff --git a/src/templates/bolepix-download.html.php b/src/templates/bolepix-download.html.php new file mode 100644 index 00000000..6d10fba8 --- /dev/null +++ b/src/templates/bolepix-download.html.php @@ -0,0 +1,77 @@ + + +
+
+
+
+

+ +

+

+ +

+
+
+
+ $subscription) : ?> + +
+ + + +
+
+ + +
+
+ + + + + + + + + +
+
+
+ + +
+
+ diff --git a/src/templates/pix-download.html.php b/src/templates/pix-download.html.php index 613157b5..a1169fa3 100644 --- a/src/templates/pix-download.html.php +++ b/src/templates/pix-download.html.php @@ -33,9 +33,11 @@
+ $pix_expiration = new DateTime( + $subscription['bill']['pix_expiration'], + new DateTimeZone('America/Sao_Paulo') + ); + if ($pix_expiration < $now && $key !== 'single_payment') :?>
position: relative; right: 75px;">
- - - -
- - - - - - -
- - diff --git a/src/utils/DefinitionVariables.php b/src/utils/DefinitionVariables.php index 5158baca..9579ecb4 100644 --- a/src/utils/DefinitionVariables.php +++ b/src/utils/DefinitionVariables.php @@ -1,6 +1,6 @@ gateway->type()) { - case 'bank_slip': - $code = 'bank_slip'; - break; case 'cc': $code = 'credit_card'; break; - case 'pix': - $code = 'pix'; + case 'bolepix': + $code = 'pix_bank_slip'; break; default: - $code = ''; + $code = $this->gateway->type(); break; } + return $code; } @@ -1121,17 +1119,15 @@ protected function create_bill_meta_for_order($bill) if (isset($bill['charges']) && count($bill['charges'])) { $charges = end($bill['charges']); - $bill_meta['bank_slip_url'] = $charges['print_url'] ?? ''; - if ($this->payment_method_code() === 'pix' - && isset($charges['last_transaction']['gateway_response_fields'])) { + + if (array_intersect([$this->payment_method_code()], ['pix', 'pix_bank_slip']) + && isset($charges['last_transaction']['gateway_response_fields'])) { $transaction = $charges['last_transaction']['gateway_response_fields']; - $bill_meta['charge_id'] = $charges['id']; - $bill_meta['pix_expiration'] = $transaction['max_days_to_keep_waiting_payment']; + $bill_meta['pix_expiration'] = $transaction['max_days_to_keep_waiting_payment'] ?? ''; $bill_meta['pix_code'] = $transaction['qrcode_original_path']; $bill_meta['pix_qr'] = $transaction['qrcode_path']; - unset($bill_meta['bank_slip_url']); } } return $bill_meta; diff --git a/vindi.php b/vindi.php index 046b1c0d..e5a5dbea 100644 --- a/vindi.php +++ b/vindi.php @@ -6,7 +6,7 @@ * Description: Adiciona o gateway de pagamento da Vindi para o WooCommerce. * Author: Vindi * Author URI: https://www.vindi.com.br - * Version: 1.2.7 + * Version: 1.2.8 * Requires at least: 4.4 * Tested up to: 6.4 * Text Domain: vindi-payment-gateway