Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build/update_branch_v1_2_5 #162

Merged
merged 16 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ composer.phar
.notes
.DS_Store
.vscode*
.idea*
*.zip

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
Expand Down
8 changes: 7 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.3
WC requires at least: 3.0.0
WC tested up to: 7.6.0
Requires PHP: 5.6
Stable Tag: 1.2.4
Stable Tag: 1.2.5
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -38,6 +38,12 @@ Para dúvidas e suporte técnico, entre em contato com a equipe Vindi através d
4. Opção de reembolso automático do pedido
5. Configurações de pagamentos via cartão de crédito

== Changelog ==
= 1.2.5 - 12/10/2023 =
-Lançamento da versão de patch.
- **Correção:** Validação das depenências do plugin
- **Correção:** Funcionamento da opção de sincronismo de assinaturas

== Changelog ==
= 1.2.4 - 30/08/2023 =
-Lançamento da versão de patch.
Expand Down
12 changes: 10 additions & 2 deletions src/VindiWoocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class WcVindiPayment extends AbstractInstance
*/
private $interest_price_handler;

/**
* @var VindiWCSRenewalDisable
*/
private $wcs_renewal_disable;

public function __construct()
{

Expand All @@ -88,8 +93,10 @@ public function __construct()
$this->frontend_files_loader = new FrontendFilesLoader();
$this->subscription_status_handler = new VindiSubscriptionStatusHandler($this->settings);
$this->vindi_status_notifier = new VindiProductStatus($this->settings);
$this->interest_price_handler = new InterestPriceHandler();
$this->interest_price_handler = new InterestPriceHandler();
$this->product_metabox = new ProductsMetabox();
$this->wcs_renewal_disable = new VindiWCSRenewalDisable();


/**
* Add Gateway to Woocommerce
Expand Down Expand Up @@ -125,6 +132,7 @@ public function init()
require_once plugin_dir_path(__FILE__) . '/utils/PaymentGateway.php';
require_once plugin_dir_path(__FILE__) . '/utils/Conversions.php';
require_once plugin_dir_path(__FILE__) . '/utils/RedirectCheckout.php';
require_once plugin_dir_path(__FILE__) . '/utils/PostMeta.php';

require_once plugin_dir_path(__FILE__) . '/includes/admin/CouponsMetaBox.php';
require_once plugin_dir_path(__FILE__) . '/includes/admin/ProductsMetabox.php';
Expand All @@ -143,7 +151,7 @@ public function init()
require_once plugin_dir_path(__FILE__) . '/controllers/index.php';

require_once plugin_dir_path(__FILE__) . '/utils/PaymentProcessor.php';
require_once plugin_dir_path(__FILE__) . '/utils/PostMeta.php';
require_once plugin_dir_path(__FILE__) . '/utils/WCSRenewalDisable.php';
}

public static function getPath()
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.4');
define('VINDI_VERSION', '1.2.5');

define('VINDI_MININUM_WP_VERSION', '5.0');
define('VINDI_MININUM_PHP_VERSION', '5.6');
Expand Down
40 changes: 40 additions & 0 deletions src/utils/WCSRenewalDisable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace VindiPaymentGateways;

class VindiWCSRenewalDisable
{
public function __construct()
{
// Hook as early as possible to try disabling WC_Subcriptions_Manager handling
add_action('wp_loaded', [$this, 'hook_before_prepare_renewal'], 1);
}

public function hook_before_prepare_renewal()
{
if (class_exists('WC_Subscriptions_Manager', false)) {
add_action('woocommerce_scheduled_subscription_payment', [
$this,
'deactivate_renewal_prepare'
], 0, 1);
}
}

public function deactivate_renewal_prepare($subscription_id)
{
$subscription = wcs_get_subscription($subscription_id);

// Check if this subscriptions is a Vindi Subscription
if (empty($subscription->get_meta('vindi_wc_subscription_id'))
&& empty($subscription->get_meta('vindi_subscription_id'))) {
return;
}

// Disable Woocommerce Subscriptions Renewal order and let Vindi handle it via webhooks
remove_action(
'woocommerce_scheduled_subscription_payment',
'WC_Subscriptions_Manager::prepare_renewal',
1
);
}
}
64 changes: 32 additions & 32 deletions src/validators/Dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,37 +136,34 @@ public static function check()

$required_plugins = [
[
'path' => 'woocommerce/woocommerce.php',
'plugin' => [
'name' => 'WooCommerce',
'url' => $woocommerce_url,
'version' => [
'validation' => '>=',
'number' => '3.0'
]
'path' => 'woocommerce/woocommerce.php',
'class' => 'WooCommerce',
'name' => 'WooCommerce',
'url' => $woocommerce_url,
'version' => [
'validation' => '>=',
'number' => '3.0'
]
],
[
'path' => 'woocommerce-extra-checkout-fields-for-brazil/
woocommerce-extra-checkout-fields-for-brazil.php',
'plugin' => [
'name' => 'Brazilian Market on WooCommerce',
'url' => $ecfb_url,
'version' => [
'validation' => '>=',
'number' => '3.5'
]
'path' =>
'woocommerce-extra-checkout-fields-for-brazil/woocommerce-extra-checkout-fields-for-brazil.php',
'class' => 'Extra_Checkout_Fields_For_Brazil',
'name' => 'Brazilian Market on WooCommerce',
'url' => $ecfb_url,
'version' => [
'validation' => '>=',
'number' => '3.5'
]
],
[
'path' => 'woocommerce-subscriptions/woocommerce-subscriptions.php',
'plugin' => [
'name' => 'WooCommerce Subscriptions',
'url' => 'http://www.woothemes.com/products/woocommerce-subscriptions/',
'version' => [
'validation' => '>=',
'number' => '2.6.1'
]
'path' => 'woocommerce-subscriptions/woocommerce-subscriptions.php',
'class' => 'WC_Subscriptions',
'name' => 'WooCommerce Subscription',
'url' => 'http://www.woothemes.com/products/woocommerce-subscriptions/',
'version' => [
'validation' => '>=',
'number' => '2.6.1'
]
]
];
Expand All @@ -185,9 +182,14 @@ public static function check()
*/
public static function missing_notice($name, $version, $link)
{
if (!is_admin() || !is_user_logged_in()) {
return;
}

include plugin_dir_path(VINDI_SRC) . 'src/views/missing-dependency.php';
}


/**
* Generate critical dependency notice content
*
Expand All @@ -205,9 +207,8 @@ private static function check_plugin_dependencies($required_plugins)
{
$checked = true;

foreach ($required_plugins as $required_plugin) {
$plugin = $required_plugin['plugin'];
$search = self::search_plugin_name($plugin['name'], self::$active_plugins);
foreach ($required_plugins as $plugin) {
$search = self::search_plugin($plugin, self::$active_plugins);

if ($search &&
version_compare(
Expand All @@ -218,23 +219,22 @@ private static function check_plugin_dependencies($required_plugins)
continue;
}

$notice = self::missing_notice(
self::missing_notice(
$plugin['name'],
$plugin['version']['number'],
$plugin['url']
);

add_action('admin_notices', $notice);
$checked = false;
}

return $checked;
}

private static function search_plugin_name($name, $array)
private static function search_plugin($required, $array)
{
foreach ($array as $val) {
if ($val['name'] === $name) {
if ($val['plugin'] === $required['path'] && class_exists($required['class'])) {
return $val;
}
}
Expand Down
15 changes: 2 additions & 13 deletions src/views/missing-dependency.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
<?php
/**
* Admin View: Notice - Warning when the site doesn't have a critical dependency installed
* or it doesn't have the minimum version
*/

if (!defined('ABSPATH')) {
exit;
}
?>

<div class="vindi-alert notice vindi-error d-flex" style=>
<div class="vindi-alert notice vindi-error d-flex">
<p>
<?php echo sprintf(
__('O Plugin Vindi WooCommerce depende da versão %s do %s para funcionar!', VINDI),
__('O Plugin Vindi WooCommerce depende da versão %s ou maior do plugin %s para funcionar!', VINDI),
$version,
$name,
)?>
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.4
* Version: 1.2.5
* Requires at least: 4.4
* Tested up to: 6.3
* WC requires at least: 3.0.0
Expand Down
Loading