Skip to content

Commit

Permalink
Adiciona método de pagamento Bolepix (#170)
Browse files Browse the repository at this point in the history
* feat: creating PIX gateway class

* feat: processando pagamentos com o método de pagamento PIX

* feat: adicionando script para copiar código pix

* fix: add cursor pointer no botão de copiar pix code

* feat: criando renovação de cobrança PIX

* fix: passando variavel order_id para a página de assinatura para poder ser possível utilizar o botão de gerar novo Qr code

* feat: invertendo verificação na visualização de Qr Code para restringir a opção de renovação somente para pagamentos recorrentes

* feat: melhorando compatibilidade com HPOS

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: trocando texto do método de pagamento pix

* fix: verificação de tipo de transação para webhook

* fix: removendo propriedade de pattern

* fix: codeclimate issues

* docs: update documentation files

* feat: iniciando a criação do novo método de pagamento Bolepix

* feat: adicionando suporte para bolepix no processo de pagamento

* feat: criando visualização na thankyou page e processando pagamento

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* fix: codeclimate issues

* run ci

* run ci

* fix: codeclimate issues

* fix: complexidade da função payment_method_code

* fix: complexidade da função create_bill_meta_for_order

* fix: adicionando timezone para verificação de vencimento do QRcode

* fix: Line exceeds 120 characters; contains 146 characters

* docs: atualiza número de versão do plugin

* fix: corrigindo palavra expiration no template de visualização de PIX

* fix: corrigindo textos nas classes de PIX e Bolepix

* fix: corrigindo identação no arquivo VindiWooCommerce.php

* fix: bug ao salvar produtos do tipo assinatura

* fix: Line indented incorrectly; expected at least 12 spaces, found 10

* docs: update readme.txt

* fix: atualiza identação do arquivo VindiWooCommerce.php
  • Loading branch information
devaguia authored Apr 17, 2024
1 parent 7f10dcc commit 32c2d83
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ engines:
duplication:
enabled: false
csslint:
enabled: true
enabled: false
phpmd:
enabled: true
checks:
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/VindiWoocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions src/assets/css/frontend.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/assets/js/thankyou.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
})
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/controllers/PlansController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
147 changes: 147 additions & 0 deletions src/includes/gateways/BolepixPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php

namespace VindiPaymentGateways;

/**
* Vindi Payment Bolepix Gateway class.
*
* Extended by individual payment gateways to handle payments.
*
* @class VindiBolepixGateway
* @extends VindiPaymentGateway
*/
class VindiBolepixGateway extends VindiPaymentGateway
{
/**
* @var VindiSettings
*/
public $vindiSettings;

/**
* @var VindiControllers
*/
public $controllers;

/**
* Constructor for the gateway.
*/
public function __construct(VindiSettings $vindiSettings, VindiControllers $controllers)
{
$this->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')
);
}
}
}
}
4 changes: 2 additions & 2 deletions src/includes/gateways/PixPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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',
Expand Down
33 changes: 33 additions & 0 deletions src/templates/bolepix-checkout.html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
if (!defined('ABSPATH')) {
exit;
}
?>

<?php if ($is_trial) : ?>
<div style="padding: 10px;border: 1px solid #f00; background-color: #fdd; color: #f00; margin: 10px 2px">
<h3 style="color: #f00"><?php _e('MODO DE TESTES', VINDI); ?></h3>
<p>
<?php _e(
'Sua conta na Vindi está em <strong>Modo Trial</strong>.
Este modo é proposto para a realização de testes e, portanto,
nenhum pedido será efetivamente cobrado.',
VINDI
); ?>
</p>
</div>
<?php endif; ?>
<fieldset>
<?php do_action('vindi_bolepix_form_start'); ?>

<div class="vindi-invoice-description" style="padding: 20px 0; font-weight: bold;">
<?php
_e('Após confirmar o pedido, use PIX ou Boleto Bancário para efetuar o pagamento.', VINDI);
?>
</div>
<div class="clear"></div>

<?php do_action('vindi_bolepix_form_end'); ?>

<div class="clear"></div>
</fieldset>
77 changes: 77 additions & 0 deletions src/templates/bolepix-download.html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
if (!defined('ABSPATH')) {
exit;
}
?>
<?php if (isset($vindi_order)) : ?>
<div class="vindi_payment_listing">
<div class="info_message">
<div class="icon"></div>
<div class="message">
<p class="message_title">
<?php _e('Aqui estão as sua cobranças com Bolepix.', VINDI); ?>
</p>
<p class="message_description">
<?php
_e(
'Você pode pagar utilizando PIX ou Boleto Bancário.
Após recebermos a confirmação do pagamento, seu pedido será processado.',
VINDI
);
?>
</p>
</div>
</div>
<div class="charges">
<?php foreach ($order_to_iterate as $key => $subscription) : ?>
<?php if (is_array($subscription) && array_key_exists('product', $subscription)
&& !in_array($subscription['bill']['status'], array('paid', 'canceled'))) : ?>
<div class="bolepix_charge charge">
<span class="bolepix_product_title product_title">
<?php echo $subscription['product']; ?>
</span>
<div>
<div class="qr_code_viwer">
<object type="image/svg+xml"
alt="QR Code image"
data="<?php echo esc_url($subscription['bill']['pix_qr']); ?>">
</object>
</div>
<div style="display: flex;
flex-direction: column;
align-items: end;
justify-content: end;
position: relative;
right: 75px;">
<a id="copy_vindi_bolepix_code"
class="download_button copy_vindi_line"
data-code="<?php echo esc_attr($subscription['bill']['pix_code']); ?>">
<?php _e('Copiar código PIX', VINDI); ?>
</a>
<a class="download_button"
href="<?php echo esc_url($subscription['bill']['bank_slip_url']); ?>"
target="_blank">
<?php _e('Baixar boleto', VINDI); ?>
<svg color="#006DFF"
style="padding: 0 5px;"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 512 512">
<path d="M288 32c0-17.7-14.3-32-32-32s-32
14.3-32 32V274.7l-73.4-73.4c-12.5-12.5-32.8-12.5-45.3
0s-12.5 32.8 0 45.3l128 128c12.5 12.5 32.8 12.5
45.3 0l128-128c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3
0L288 274.7V32zM64 352c-35.3 0-64 28.7-64 64v32c0 35.3
28.7 64 64 64H448c35.3 0 64-28.7
64-64V416c0-35.3-28.7-64-64-64H346.5l-45.3
45.3c-25 25-65.5 25-90.5 0L165.5 352H64zm368
56a24 24 0 1 1 0 48 24 24 0 1 1 0-48z"/>
</svg>
</a>
</div>
</div>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
Loading

0 comments on commit 32c2d83

Please sign in to comment.