Plugin Directory

Changeset 3382634


Ignore:
Timestamp:
10/22/2025 01:16:29 PM (4 months ago)
Author:
vindipagamentos
Message:

Atualização da versão 1.0.8

Location:
vindi-pagamentos/trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • vindi-pagamentos/trunk/app/Core/Config.php

    r3371384 r3382634  
    7373    public function pluginVersion(): string
    7474    {
    75         return '1.0.7';
     75        return '1.0.8';
    7676    }
    7777}
  • vindi-pagamentos/trunk/app/Services/WooCommerce/Blocks/BlockCheckoutFieldManager.php

    r3364036 r3382634  
    33namespace VindiPagamentos\Services\WooCommerce\Blocks;
    44
     5use Automattic\WooCommerce\Blocks\Package;
     6use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields;
    57use VindiPagamentos\Exceptions\MissingDocumentException;
    68
     
    1315    public function __construct()
    1416    {
     17        add_action('woocommerce_init', [$this, 'init'], 20);
     18    }
     19
     20    public function init()
     21    {
     22        if ($this->fieldsAlreadyExist()) {
     23            return;
     24        }
     25
    1526        if ($this->shouldUseNativeFields()) {
    1627            $this->initializeNativeFields();
     
    2536    private function shouldUseNativeFields(): bool
    2637    {
    27         if (!function_exists('woocommerce_register_additional_checkout_field')) {
    28             return false;
    29         }
    30 
    31         if ($this->fieldsAlreadyExist()) {
    32             return false;
    33         }
    34 
    35         return true;
     38        return function_exists('woocommerce_register_additional_checkout_field');
    3639    }
    3740
     
    4144    private function fieldsAlreadyExist(): bool
    4245    {
    43         $existing_fields = [
    44             'billing_cpf',
    45             'billing_cnpj',
    46             'billing_persontype',
    47             '_billing_cpf',
    48             '_billing_cnpj',
    49             '_billing_persontype'
    50         ];
    51 
    52         foreach ($existing_fields as $field) {
     46        try {
    5347            if (
    54                 has_filter('woocommerce_checkout_fields', $field) ||
    55                 has_action('woocommerce_checkout_process', $field)
     48                !class_exists('Automattic\WooCommerce\Blocks\Package') ||
     49                !class_exists('Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields')
    5650            ) {
    5751                return true;
    5852            }
    59         }
    60 
    61         return false;
     53
     54            $checkout_fields = Package::container()->get(CheckoutFields::class);
     55            $additional_fields = $checkout_fields->get_additional_fields();
     56
     57            if (empty($additional_fields)) {
     58                return false;
     59            }
     60
     61            foreach ($additional_fields as $field) {
     62                $field_id = strtolower($field['id'] ?? '');
     63
     64                if (strpos($field_id, 'vindi-pagamentos/') === 0) {
     65                    continue;
     66                }
     67
     68                if (
     69                    strpos($field_id, 'billing_cpf') !== false ||
     70                    strpos($field_id, 'billing_cnpj') !== false ||
     71                    strpos($field_id, 'billing_persontype') !== false
     72                ) {
     73                    return true;
     74                }
     75            }
     76
     77            return false;
     78        } catch (\Exception $e) {
     79            return false;
     80        }
    6281    }
    6382
     
    7493
    7594    /**
    76      * Inicializa implementação customizada (fallback)
     95     * Inicializa implementação customizada (fallback), para quando a versão do WooCommerce não suporta campos nativos
    7796     */
    7897    private function initializeCustomFields(): void
  • vindi-pagamentos/trunk/app/Services/WooCommerce/Checkout/PaymentProcessor.php

    r3371384 r3382634  
    12731273    }
    12741274
     1275    /**
     1276     * Busca um meta_key do pedido de forma flexível
     1277     * Procura por qualquer meta_key que CONTENHA o termo buscado
     1278     *
     1279     * @param string $search_term Termo a buscar (ex: 'billing_cpf')
     1280     * @return string Valor encontrado ou string vazia
     1281     */
     1282    private function getOrderMetaFlexible(string $search_term): string
     1283    {
     1284        $all_meta = $this->order->get_meta_data();
     1285       
     1286        foreach ($all_meta as $meta) {
     1287            $meta_key = $meta->key ?? '';
     1288       
     1289            if (strpos($meta_key, $search_term) !== false) {
     1290                $value = $meta->value ?? '';
     1291                if (!empty($value)) {
     1292                    return $value;
     1293                }
     1294            }
     1295        }
     1296       
     1297        return '';
     1298    }
     1299
     1300    private function setCnpjData(array &$data): void
     1301    {
     1302        $data['cnpj'] = $this->getOrderMetaFlexible('billing_cnpj');
     1303
     1304        if (!$data['cnpj']) {
     1305            throw new MissingDocumentException('CNPJ');
     1306        }
     1307
     1308        $data['trade_name'] = "{$this->order->get_billing_first_name()} {$this->order->get_billing_last_name()}";
     1309        $data['company_name'] = $this->order->get_billing_company();
     1310
     1311        $gatewayDocument = $this->getCustomerDocument();
     1312        if ($gatewayDocument) {
     1313            $data['cpf'] = $gatewayDocument;
     1314        }
     1315    }
     1316
     1317    private function setCpfData(array &$data): void
     1318    {
     1319        $data['cpf'] = $this->getOrderMetaFlexible('billing_cpf');
     1320       
     1321        if (!$data['cpf']) {
     1322            throw new MissingDocumentException(__('CPF', 'vindi-pagamentos'));
     1323        }
     1324    }
     1325
    12751326    private function setDocumentFields(array &$data): void
    12761327    {
    1277         $personType = $this->order->get_meta('_billing_persontype');
     1328        $personType = $this->getOrderMetaFlexible('billing_persontype');
    12781329
    12791330        if (empty($personType)) {
    1280             $personType = $this->order->get_meta('billing_persontype');
    1281         }
    1282 
    1283         if (empty($personType)) {
    1284             $cpf = $this->order->get_meta('_billing_cpf');
    1285             $cnpj = $this->order->get_meta('_billing_cnpj');
     1331            $cnpj = $this->getOrderMetaFlexible('billing_cnpj');
     1332            $cpf = $this->getOrderMetaFlexible('billing_cpf');
    12861333
    12871334            if (!empty($cnpj)) {
     
    12911338            }
    12921339        }
     1340
    12931341        switch ($personType) {
    12941342            case '2':
     
    12991347                break;
    13001348            default:
    1301                 $cpf = $this->order->get_meta('_billing_cpf');
    1302                 $cnpj = $this->order->get_meta('_billing_cnpj');
    1303 
    1304                 if (!empty($cnpj)) {
    1305                     $this->setCnpjData($data);
    1306                 } elseif (!empty($cpf)) {
    1307                     $this->setCpfData($data);
    1308                 } else {
    1309                     throw new MissingDocumentException(__('Tipo de Pessoa ou documento (CPF/CNPJ)', 'vindi-pagamentos'));
    1310                 }
     1349                throw new MissingDocumentException(__('Tipo de Pessoa ou documento (CPF/CNPJ)', 'vindi-pagamentos'));
    13111350                break;
    1312         }
    1313     }
    1314 
    1315     private function setCnpjData(array &$data): void
    1316     {
    1317         $data['cnpj'] = $this->order->get_meta('_billing_cnpj');
    1318 
    1319         if (!$data['cnpj']) {
    1320             throw new MissingDocumentException('CNPJ');
    1321         }
    1322 
    1323         $data['trade_name'] = "{$this->order->get_billing_first_name()} {$this->order->get_billing_last_name()}";
    1324         $data['company_name'] = $this->order->get_billing_company();
    1325 
    1326         $gatewayDocument = $this->getCustomerDocument();
    1327         if ($gatewayDocument) {
    1328             $data['cpf'] = $gatewayDocument;
    1329         }
    1330     }
    1331 
    1332     private function setCpfData(array &$data): void
    1333     {
    1334         $data['cpf'] = $this->order->get_meta('_billing_cpf');
    1335         if (!$data['cpf']) {
    1336             throw new MissingDocumentException('CPF');
    13371351        }
    13381352    }
  • vindi-pagamentos/trunk/app/Services/WooCommerce/Core.php

    r3371384 r3382634  
    155155                'woocommerce_store_api_checkout_update_order_from_request',
    156156                [PersonTypeFallback::class, 'updateBlockOrderMeta'],
    157                 10,
     157                20,
    158158                2
    159159            );
  • vindi-pagamentos/trunk/assets/blocks/components/PersonTypeFallback/block.json

    r3371384 r3382634  
    44    "name": "vindi-pagamentos/person-type-fallback",
    55    "icon": "flag",
    6     "version": "1.0.7",
     6    "version": "1.0.8",
    77    "title": "Woo - Tipo de Pessoa (Fallback)",
    88    "description": "Definição de tipo de pessoa no checkout - versão fallback para WooCommerce antigo",
  • vindi-pagamentos/trunk/composer.json

    r3371384 r3382634  
    11{
    22  "name": "vindi/vindi-pagamentos",
    3   "version": "1.0.7",
     3  "version": "1.0.8",
    44  "description": "WooCommerce payment plugin using Vindi gateways",
    55  "type": "wordpress-plugin",
  • vindi-pagamentos/trunk/package.json

    r3371384 r3382634  
    11{
    22  "name": "vindi-pagamentos",
    3   "version": "1.0.7",
     3  "version": "1.0.8",
    44  "description": "WooCommerce payment plugin using Vindi gateways",
    55  "repository": "https://github.com/vindi/vindi-pagamentos",
  • vindi-pagamentos/trunk/readme.txt

    r3371384 r3382634  
    44Requires at least: 6.0
    55Tested up to: 6.8
    6 Stable tag: 1.0.7
     6Stable tag: 1.0.8
    77Requires PHP: 7.4
    88License: GPLv3
     
    5656
    5757== Changelog ==
     58=1.0.8 = 06-10-2025
     59* Melhoria: Detecção automática de campos de checkout (CPF/CNPJ/PersonType)
     60* Melhoria: Busca flexível de meta_keys do pedido para compatibilidade com múltiplos plugins de campos
     61
    5862=1.0.7 = 30-09-2025
    5963* Adição: Opção para habilitar/desabilitar salvamento de cartões de crédito nas configurações
  • vindi-pagamentos/trunk/vendor/autoload.php

    r3371384 r3382634  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderInit9a679a4f6fec3baaddc32c3f8e39b400::getLoader();
     25return ComposerAutoloaderInitbbf5ba13b74aaf6238592a8e3cb2bc1f::getLoader();
  • vindi-pagamentos/trunk/vendor/composer/autoload_real.php

    r3371384 r3382634  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit9a679a4f6fec3baaddc32c3f8e39b400
     5class ComposerAutoloaderInitbbf5ba13b74aaf6238592a8e3cb2bc1f
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInit9a679a4f6fec3baaddc32c3f8e39b400', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInitbbf5ba13b74aaf6238592a8e3cb2bc1f', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    27         spl_autoload_unregister(array('ComposerAutoloaderInit9a679a4f6fec3baaddc32c3f8e39b400', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInitbbf5ba13b74aaf6238592a8e3cb2bc1f', 'loadClassLoader'));
    2828
    2929        require __DIR__ . '/autoload_static.php';
    30         call_user_func(\Composer\Autoload\ComposerStaticInit9a679a4f6fec3baaddc32c3f8e39b400::getInitializer($loader));
     30        call_user_func(\Composer\Autoload\ComposerStaticInitbbf5ba13b74aaf6238592a8e3cb2bc1f::getInitializer($loader));
    3131
    3232        $loader->register(true);
    3333
    34         $filesToLoad = \Composer\Autoload\ComposerStaticInit9a679a4f6fec3baaddc32c3f8e39b400::$files;
     34        $filesToLoad = \Composer\Autoload\ComposerStaticInitbbf5ba13b74aaf6238592a8e3cb2bc1f::$files;
    3535        $requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
    3636            if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
  • vindi-pagamentos/trunk/vendor/composer/autoload_static.php

    r3371384 r3382634  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit9a679a4f6fec3baaddc32c3f8e39b400
     7class ComposerStaticInitbbf5ba13b74aaf6238592a8e3cb2bc1f
    88{
    99    public static $files = array (
     
    3232    {
    3333        return \Closure::bind(function () use ($loader) {
    34             $loader->prefixLengthsPsr4 = ComposerStaticInit9a679a4f6fec3baaddc32c3f8e39b400::$prefixLengthsPsr4;
    35             $loader->prefixDirsPsr4 = ComposerStaticInit9a679a4f6fec3baaddc32c3f8e39b400::$prefixDirsPsr4;
    36             $loader->classMap = ComposerStaticInit9a679a4f6fec3baaddc32c3f8e39b400::$classMap;
     34            $loader->prefixLengthsPsr4 = ComposerStaticInitbbf5ba13b74aaf6238592a8e3cb2bc1f::$prefixLengthsPsr4;
     35            $loader->prefixDirsPsr4 = ComposerStaticInitbbf5ba13b74aaf6238592a8e3cb2bc1f::$prefixDirsPsr4;
     36            $loader->classMap = ComposerStaticInitbbf5ba13b74aaf6238592a8e3cb2bc1f::$classMap;
    3737
    3838        }, null, ClassLoader::class);
  • vindi-pagamentos/trunk/vendor/composer/installed.php

    r3371384 r3382634  
    22    'root' => array(
    33        'name' => 'vindi/vindi-pagamentos',
    4         'pretty_version' => '1.0.7',
    5         'version' => '1.0.7.0',
     4        'pretty_version' => '1.0.8',
     5        'version' => '1.0.8.0',
    66        'reference' => NULL,
    77        'type' => 'wordpress-plugin',
     
    1212    'versions' => array(
    1313        'vindi/vindi-pagamentos' => array(
    14             'pretty_version' => '1.0.7',
    15             'version' => '1.0.7.0',
     14            'pretty_version' => '1.0.8',
     15            'version' => '1.0.8.0',
    1616            'reference' => NULL,
    1717            'type' => 'wordpress-plugin',
  • vindi-pagamentos/trunk/vindi-pagamentos.php

    r3371384 r3382634  
    77 * Author:            Apiki WordPress
    88 * Author URI:        https://github.com/vindi/
    9  * Version:           1.0.7
     9 * Version:           1.0.8
    1010 * Requires PHP:      7.4
    1111 * Requires at least: 6.0
     
    1515 *
    1616 * @link    https://vindi.com.br/
    17  * @since   1.0.7
     17 * @since   1.0.8
    1818 * @package VindiPagamentos
    1919 */
Note: See TracChangeset for help on using the changeset viewer.