Skip to content

Commit

Permalink
build/update_branch_v1_ 2_3 (#146)
Browse files Browse the repository at this point in the history
* fix: cancelled order status

* fix: calculate total for installments select

* fix: show payment methods on zero value orders only when subscriptions has free trial period

* fix: passing the default variable for needs payments function filter

* feat: removing synchronism_status option from Vindi settings

* build: update documentation files

* 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

* empty commit

* fix: bringing back the synchronism option

* docs: update readme.txt
  • Loading branch information
devaguia authored Jul 18, 2023
1 parent 14f9824 commit d1b51cb
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 51 deletions.
9 changes: 7 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Tested up to: 6.2
WC requires at least: 3.0.0
WC tested up to: 7.6.0
Requires PHP: 5.6
Stable Tag: 1.2.2
Stable Tag: 1.2.3
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -39,11 +39,16 @@ Para dúvidas e suporte técnico, entre em contato com a equipe Vindi através d
5. Configurações de pagamentos via cartão de crédito

== Changelog ==
= 1.2.3 - 30/06/2023 =
-Lançamento da versão de patch.
- **Correção:** Aparição dos métodos de pagamentos em pedidos zerados somente para pedidos de teste gratis.
- **Correção:** visualização das parcelas crédito de acordo com o valor total do pedido
- **Correção:** Erro fatal ao cancelar inscrições em ambientes com PHP 8+

= 1.2.2 - 25/04/2023 =
-Lançamento da versão de patch.
- **Correção:** Valor de parcelas de crédito para produtos variáveis.

== Changelog ==
= 1.2.1 - 19/04/2023 =
-Lançamento da versão de patch.
- **Correção:** Erro fatal ao receber notificação de Webhook
Expand Down
23 changes: 21 additions & 2 deletions src/VindiWoocommerce.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace VindiPaymentGateways;

use WC_Subscriptions_Product;

require_once plugin_dir_path(__FILE__) . '/utils/AbstractInstance.php';


Expand Down Expand Up @@ -181,9 +183,26 @@ public function add_gateway($methods)
* Sobrescreve o método que remove os métodos de pagamento para assinaturas com trial
* @return bool
*/
public function filter_woocommerce_cart_needs_payment()
public function filter_woocommerce_cart_needs_payment($needs_payment, $cart)
{
if (floatval($cart->total) == 0 && $this->cart_has_trial($cart)) {
return true;
}

return $needs_payment;
}

private function cart_has_trial($cart)
{
return true;
$items = $cart->get_cart();
foreach ($items as $item) {
if (class_exists('WC_Subscriptions_Product')
&& WC_Subscriptions_Product::get_trial_length($item['product_id']) > 0) {
return true;
}
}

return false;
}
}

Expand Down
91 changes: 53 additions & 38 deletions src/includes/gateways/CreditPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace VindiPaymentGateways;

use WC_Subscriptions_Cart;

if (!defined('ABSPATH')) {
exit;
}
Expand Down Expand Up @@ -154,60 +156,73 @@ public function init_form_fields()

public function payment_fields()
{
$cart = $this->vindi_settings->woocommerce->cart;
$cart = $this->vindi_settings->woocommerce->cart;
$total = $this->get_cart_total($cart);

foreach ($cart->get_fees() as $index => $fee) {
if($fee->name == __('Juros', VINDI)) {
$total -= $fee->amount;
}
}

$max_times = 12;
$max_times = $this->get_order_max_installments($total);

if ($max_times > 1) {
for ($times = 1; $times <= $max_times; $times++) {
if ($this->is_interest_rate_enabled()) {
$installments[$times] = ($total * (1 + (($this->get_interest_rate() / 100) * ($times - 1)))) / $times;
} else {
$installments[$times] = ceil($total / $times * 100) / 100;
}
}
}
$installments = $this->build_cart_installments($total);

$user_payment_profile = $this->build_user_payment_profile();
$payment_methods = $this->routes->getPaymentMethods();
$user_payment_profile = $this->build_user_payment_profile();
$payment_methods = $this->routes->getPaymentMethods();

if ($payment_methods === false || empty($payment_methods) || ! count($payment_methods['credit_card'])) {
_e('Estamos enfrentando problemas técnicos no momento. Tente novamente mais tarde ou entre em contato.', VINDI);
return;
}
if ($payment_methods === false || empty($payment_methods) || ! count($payment_methods['credit_card'])) {
_e(
'Estamos enfrentando problemas técnicos no momento. Tente novamente mais tarde ou entre em contato.',
VINDI
);
return;
}

if ($this->is_trial && $this->is_trial == $this->vindi_settings->get_is_active_sandbox()) {
$is_trial = $this->routes->isMerchantStatusTrialOrSandbox();
}

$this->vindi_settings->get_template('creditcard-checkout.html.php', compact(
'installments',
'is_trial',
'user_payment_profile',
'payment_methods'
));
$this->vindi_settings->get_template('creditcard-checkout.html.php', compact(
'installments',
'is_trial',
'user_payment_profile',
'payment_methods'
));
}

public function build_cart_installments($total)
{
$max_times = $this->get_order_max_installments($total);
$installments = [];

if ($max_times > 1) {
for ($times = 1; $times <= $max_times; $times++) {
$installments[$times] = $this->get_cart_installments($times, $total);
}
}

return $installments;
}

public function get_cart_installments($times, $total)
{
if ($this->is_interest_rate_enabled()) {
return ($total * (1 + (($this->get_interest_rate() / 100) * ($times - 1)))) / $times;
}

return ceil($total / $times * 100) / 100;
}

public function get_cart_total($cart)
{
$items = $cart->get_cart();
$price = 0;
$total = $cart->total;
$recurring = end($cart->recurring_carts);

foreach ($items as $item) {
if (isset($item['data']) && is_object($item['data'])) {
$product = $item['data'];
$price += floatval($product->get_price());
if (floatval($cart->total) == 0 && is_object($recurring)) {
$total = $recurring->total;
}

foreach ($cart->get_fees() as $index => $fee) {
if ($fee->name == __('Juros', VINDI)) {
$total -= $fee->amount;
}
}
return $price;

return $total;
}

public function verify_user_payment_profile()
Expand Down
2 changes: 1 addition & 1 deletion src/utils/DefinitionVariables.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define('VINDI_VERSION', '1.2.2');
define('VINDI_VERSION', '1.2.3');

define('VINDI_MININUM_WP_VERSION', '5.0');
define('VINDI_MININUM_PHP_VERSION', '5.6');
Expand Down
13 changes: 6 additions & 7 deletions src/utils/SubscriptionStatusHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,23 @@ public function order_canceled($order)

$vindi_order = get_post_meta($order->id, 'vindi_order', true);

if (!$vindi_order || !is_array($vindi_order)) {
if (!is_array($vindi_order)) {
return;
}

$single_payment_bill_id = 0;

foreach ($vindi_order as $key => $item) {
if ($key == 'single_payment' && isset($vindi_order[$key]['bill']['status'])) {
$status = $vindi_order[$key]['bill']['status'];
$single_payment_bill_id = $status != 'canceled' ? $vindi_order[$key]['bill']['id'] : false;
if ($key == 'single_payment' &&
$vindi_order[$key]['bill']['status'] != 'canceled') {
$single_payment_bill_id = $vindi_order[$key]['bill']['id'];
}

$vindi_order[$key]['bill']['status'] = 'canceled';

}

update_post_meta($order->id, 'vindi_order', $vindi_order);

if ($single_payment_bill_id) {
update_post_meta($order->id, 'vindi_order', $vindi_order);
$this->routes->deleteBill($single_payment_bill_id);
}
}
Expand Down
2 changes: 1 addition & 1 deletion vindi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.2
* Version: 1.2.3
* Requires at least: 4.4
* Tested up to: 6.2
* WC requires at least: 3.0.0
Expand Down

0 comments on commit d1b51cb

Please sign in to comment.