Plugin Directory

Changeset 3323666


Ignore:
Timestamp:
07/07/2025 01:53:24 PM (9 months ago)
Author:
apiki
Message:

Atualizações e remoções de arquivos obsoletos no plugin

Location:
vindi-payment-gateway/trunk
Files:
4 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • vindi-payment-gateway/trunk/readme.txt

    r3280960 r3323666  
    1212WC tested up to: 8.6.1
    1313Requires PHP: 5.6
    14 Stable Tag: 1.3.8
     14Stable Tag: 1.3.9
    1515License: GPLv3
    1616License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    4040
    4141== Changelog ==
     42= 1.3.9 - 05/06/2025 =
     43-Lançamento da versão de patch.
     44- **Melhoria:** Adaptando o plugin para HPos.
     45
    4246= 1.3.8 - 24/04/2025 =
    4347-Lançamento da versão de patch.
    44 - **Correção:** Alteração no Tested up to de 6.4 para 6.8.
     48- **Correção:** Alteração no test up de 6.4 para 6.8.
    4549
    4650= 1.3.7 - 05/11/2024 =
  • vindi-payment-gateway/trunk/src/assets/js/editpost.js

    r3179566 r3323666  
    11jQuery(document).ready(function ($) {
    2     let side = document.querySelector(".page-title-action");
    3     if (side && orderData.typePost == "shop_order") {
    4         let button = document.createElement('a');
    5         button.className = 'button button-primary';
    6         button.style.marginLeft = '10px';
    7         button.style.marginTop = '10px';
    8         button.setAttribute("target", "_blank");
    9         button.innerText = "Gerar Link de Pagamento";
    10         button.setAttribute("href", `${location.origin}/wp-admin/post-new.php?post_type=shop_order&vindi-payment-link=true`);
    11         side.after(button);
     2    if (orderData.isOrderPage) {
     3        let side = document.querySelector(".page-title-action");
     4        if (side && !document.querySelector('#vindi-payment-link-btn')) {
     5            let button = document.createElement('a');
     6            button.id = 'vindi-payment-link-btn';
     7            button.className = 'button button-primary';
     8            button.style.marginLeft = '10px';
     9            button.style.marginTop = '10px';
     10            button.setAttribute("target", "_blank");
     11            button.innerText = "Gerar Link de Pagamento";
     12            button.setAttribute("href", `${location.origin}/wp-admin/post-new.php?post_type=shop_order&vindi-payment-link=true`);
     13            side.after(button);
     14        }
    1215    }
    13 })
     16});
  • vindi-payment-gateway/trunk/src/controllers/PlansController.php

    r3072649 r3323666  
    2727   * @var VindiLogger
    2828   */
    29     private $logger;
     29  private $logger;
    3030
    3131  /**
    3232   * @var array
    3333   */
    34     private $allowedTypes;
     34  private $allowedTypes;
    3535
    3636  function __construct(VindiSettings $vindi_settings)
     
    3838    $this->routes = $vindi_settings->routes;
    3939    $this->logger = $vindi_settings->logger;
    40         $this->allowedTypes = array('variable-subscription', 'subscription');
     40    $this->allowedTypes = array('variable-subscription', 'subscription');
    4141
    4242    add_action('wp_insert_post', array($this, 'create'), 10, 3);
     
    5353   * @SuppressWarnings(PHPMD.MissingImport)
    5454   */
    55   function create($post_id, $post, $update, $recreated = false)
     55  function create($post_id, $recreated = false)
    5656  {
    57 
     57    $product = wc_get_product($post_id);
     58    // Check if the post is product
     59    if (!$product) {
     60      return;
     61    }
     62    $post_status = $product->get_status();
    5863    // Check if the post is a draft
    59     if (strpos(get_post_status($post_id), 'draft') !== false) {
    60       return;
    61     }
    62     // Check if the post is product
    63     if (get_post_type($post_id) != 'product') {
    64       return;
    65     }
    66 
    67         $post_meta = new PostMeta();
    68         if ($post_meta->check_vindi_item_id($post_id, 'vindi_plan_id') > 1) {
    69             update_post_meta($post_id, 'vindi_plan_id', '');
    70         }
    71 
    72         if ($post_meta->check_vindi_item_id($post_id, 'vindi_product_id') > 1) {
    73             update_post_meta($post_id, 'vindi_product_id', '');
    74         }
     64    if (str_contains($post_status, 'draft')) {
     65      return;
     66    }
     67
     68    $post_meta = new PostMeta();
     69    if ($post_meta->check_vindi_item_id($post_id, 'vindi_plan_id') > 1) {
     70      $product->update_meta_data('vindi_plan_id', '');
     71      $product->save();
     72    }
     73    if ($post_meta->check_vindi_item_id($post_id, 'vindi_product_id') > 1) {
     74      $product->update_meta_data('vindi_product_id', '');
     75      $product->save();
     76    }
    7577
    7678    // Check if it's a new post
    7779    // The $update value is unreliable because of the auto_draft functionality
    78         $post_status = get_post_status($post_id);
    79         $vindi_plan_id = get_post_meta($post_id, 'vindi_plan_id', true);
    80 
    81         if (!$recreated && $post_status != 'publish' || !empty($vindi_plan_id)) {
    82             return $this->update($post_id);
    83         }
    84 
    85     $product = wc_get_product($post_id);
     80    $vindi_plan_id = $product ? $product->get_meta('vindi_plan_id', true) : '';
     81
     82    if (!$recreated && $post_status != 'publish' || !empty($vindi_plan_id)) {
     83      return $this->update($post_id);
     84    }
    8685
    8786    // Check if the post is of the subscription type
    88         if (!in_array($product->get_type(), $this->allowedTypes)) {
    89           return;
    90         }
     87    if (!in_array($product->get_type(), $this->allowedTypes)) {
     88      return;
     89    }
    9190
    9291    // Checks if the plan is a variation and creates it
    9392    if ($product->get_type() == 'variable-subscription') {
    94 
    9593      $variations = $product->get_available_variations();
    9694      $variations_products = $variations_plans = [];
     
    104102        $interval_count    = $variation_product->get_meta('_subscription_period_interval');
    105103        $plan_interval     = VindiConversions::convert_interval($interval_count, $interval_type);
    106                 $variation_id      = $variation['variation_id'];
    107 
    108                 $plan_installments = $variation_product->get_meta("vindi_max_credit_installments_$variation_id");
    109 
    110                 if (!$plan_installments || $plan_installments === 0) {
    111                     $plan_installments = 1;
    112                 }
     104        $variation_id      = $variation['variation_id'];
     105
     106        $plan_installments = $variation_product->get_meta("vindi_max_credit_installments_$variation_id");
     107
     108        if (!$plan_installments || $plan_installments === 0) {
     109          $plan_installments = 1;
     110        }
    113111
    114112        $trigger_day = VindiConversions::convertTriggerToDay(
     
    118116
    119117        // Creates the product within the Vindi
    120         $vindi_product_id = get_post_meta($post_id, 'vindi_product_id', true);
     118        $vindi_product_id = $product->get_meta('vindi_product_id', true);
    121119        $createdProduct = !empty($vindi_product_id) ?
    122120          $this->routes->findProductById($vindi_product_id) :
    123                       $this->routes->createProduct(
    124                       array(
    125                           'name' => VINDI_PREFIX_PRODUCT . $data['name'],
    126                           'code' => 'WC-' . $data['id'],
    127                           'status' => ($data['status'] == 'publish') ? 'active' : 'inactive',
    128                           'invoice' => 'always',
    129                           'pricing_schema' => array(
    130                           'price' => ($data['price']) ? $data['price'] : 0,
    131                           'schema_type' => 'flat',
    132                         )
    133                       )
    134                     );
     121          $this->routes->createProduct(
     122            array(
     123              'name' => VINDI_PREFIX_PRODUCT . $data['name'],
     124              'code' => 'WC-' . $data['id'],
     125              'status' => ($data['status'] == 'publish') ? 'active' : 'inactive',
     126              'invoice' => 'always',
     127              'pricing_schema' => array(
     128                'price' => ($data['price']) ? $data['price'] : 0,
     129                'schema_type' => 'flat',
     130              )
     131            )
     132          );
    135133
    136134        // Creates the plan within the Vindi
     
    143141          'billing_cycles' => ($product->get_meta('_subscription_length') == 0) ? null : $product->get_meta('_subscription_length'),
    144142          'code' => 'WC-' . $data['id'],
    145                       'installments' => $plan_installments,
     143          'installments' => $plan_installments,
    146144          'status' => ($data['status'] == 'publish') ? 'active' : 'inactive',
    147145          'plan_items' => array(
     
    158156
    159157        // Saving product id and plan in the WC goal
    160                       if (isset($variation['variation_id']) && $createdProduct['id']) {
    161                             update_post_meta($variation['variation_id'], 'vindi_product_id', $createdProduct['id']);
    162                       }
    163 
    164                         if (isset($variation['variation_id']) && $createdPlan['id']) {
    165                             update_post_meta($variation['variation_id'], 'vindi_plan_id', $createdPlan['id']);
    166                         }
     158        if (isset($variation['variation_id']) && $createdProduct['id']) {
     159          $variation_product = wc_get_product($variation['variation_id']);
     160          $variation_product->update_meta_data('vindi_product_id', $createdProduct['id']);
     161          $variation_product->save();
     162        }
     163
     164        if (isset($variation['variation_id']) && $createdPlan['id']) {
     165          $variation_product = wc_get_product($variation['variation_id']);
     166          $variation_product->update_meta_data('vindi_plan_id', $createdPlan['id']);
     167          $variation_product->save();
     168        }
    167169      }
    168170
    169             $product_id = end($variations_products)['id'];
    170 
    171             if ($product_id) {
    172                 update_post_meta($post_id, 'vindi_product_id', end($variations_products)['id']);
    173                 update_post_meta($post_id, 'vindi_plan_id', end($variations_products)['id']);
    174             }
     171      $variation_id = array_key_last($variations_products);
     172
     173      if ($variation_id) {
     174        $variation_product = wc_get_product($variation_id);
     175        if ($variation_product) {
     176          $variation_product->update_meta_data('vindi_product_id', end($variations_products)['id']);
     177          $variation_product->update_meta_data('vindi_plan_id', end($variations_plans)['id']);
     178          $variation_product->save();
     179        }
     180      }
    175181
    176182      return array(
     
    182188    $data = $product->get_data();
    183189
    184 
    185190    $interval_type = $product->get_meta('_subscription_period');
    186191    $interval_count = $product->get_meta('_subscription_period_interval');
     
    192197    );
    193198
    194           $plan_installments = $product->get_meta("vindi_max_credit_installments_$post_id");
    195           if (!$plan_installments || $plan_installments === 0) {
    196               $plan_installments = 1;
    197           }
     199    $plan_installments = $product->get_meta("vindi_max_credit_installments_$post_id");
     200    if (!$plan_installments || $plan_installments === 0) {
     201      $plan_installments = 1;
     202    }
    198203
    199204    // Creates the product within the Vindi
    200     $vindi_product_id = get_post_meta($post_id, 'vindi_product_id', true);
     205    $vindi_product_id = $product ? $product->get_meta('vindi_product_id', true) : '';
    201206    $createdProduct = !empty($vindi_product_id) ?
    202207      $this->routes->findProductById($vindi_product_id) :
    203             $this->routes->createProduct(
    204               array(
    205                 'name' => VINDI_PREFIX_PRODUCT . $data['name'],
    206                 'code' => 'WC-' . $data['id'],
    207                 'status' => ($data['status'] == 'publish') ? 'active' : 'inactive',
    208                 'invoice' => 'always',
    209                 'pricing_schema' => array(
    210                   'price' => ($data['price']) ? $data['price'] : 0,
    211                   'schema_type' => 'flat',
    212                 )
    213               )
    214             );
     208      $this->routes->createProduct(
     209        array(
     210          'name' => VINDI_PREFIX_PRODUCT . $data['name'],
     211          'code' => 'WC-' . $data['id'],
     212          'status' => ($data['status'] == 'publish') ? 'active' : 'inactive',
     213          'invoice' => 'always',
     214          'pricing_schema' => array(
     215            'price' => ($data['price']) ? $data['price'] : 0,
     216            'schema_type' => 'flat',
     217          )
     218        )
     219      );
    215220
    216221    // Creates the plan within the Vindi
     
    223228      'billing_cycles' => ($product->get_meta('_subscription_length') == 0) ? null : $product->get_meta('_subscription_length'),
    224229      'code' => 'WC-' . $data['id'],
    225           'installments' => $plan_installments,
     230      'installments' => $plan_installments,
    226231      'status' => ($data['status'] == 'publish') ? 'active' : 'inactive',
    227232      'plan_items' => array(
     
    237242
    238243    // Saving product id and plan in the WC goal
    239           if ($createdProduct && isset($createdProduct['id'])) {
    240             update_post_meta($post_id, 'vindi_product_id', $createdProduct['id']);
    241           }
    242             if ($createdPlan && isset($createdPlan['id'])) {
    243               update_post_meta($post_id, 'vindi_plan_id', $createdPlan['id']);
    244             }
     244    if ($createdProduct && isset($createdProduct['id'])) {
     245      $product->update_meta_data('vindi_product_id', $createdProduct['id']);
     246      $product->save();
     247    }
     248    if ($createdPlan && isset($createdPlan['id'])) {
     249      $product->update_meta_data('vindi_plan_id', $createdPlan['id']);
     250      $product->save();
     251    }
    245252
    246253    if ($createdPlan && $createdProduct) {
     
    261268  {
    262269    $product = wc_get_product($post_id);
    263 
    264270    // Check if the post is of the signature type
    265         if (!in_array($product->get_type(), $this->allowedTypes)) {
    266           return;
    267         }
     271    if (!in_array($product->get_type(), $this->allowedTypes)) {
     272      return;
     273    }
    268274
    269275    // Checks whether there is a vindi plan ID created within
    270276    if ($product->get_type() == 'subscription') {
    271 
    272       $vindi_plan_id = get_post_meta($post_id, 'vindi_plan_id', true);
    273 
     277      $vindi_plan_id = $product->get_meta('vindi_plan_id', true);
    274278      if (empty($vindi_plan_id)) {
    275 
    276279        return $this->create($post_id, '', '', true);
    277280      }
     
    288291
    289292        // Checks whether there is a vindi plan ID created within
    290         $vindi_plan_id = get_post_meta($variation['variation_id'], 'vindi_plan_id', true);
    291         $vindi_product_id = get_post_meta($variation['variation_id'], 'vindi_product_id', true);
     293        $vindi_plan_id = $variation_product->get_meta('vindi_plan_id', true);
     294        $vindi_product_id = $variation_product->get_meta('vindi_product_id', true);
    292295
    293296        if (empty($vindi_plan_id)) {
     
    298301
    299302        $data = $variation_product->get_data();
    300 
    301303        $interval_type     = $variation_product->get_meta('_subscription_period');
    302304        $interval_count    = $variation_product->get_meta('_subscription_period_interval');
    303305        $plan_interval     = VindiConversions::convert_interval($interval_count, $interval_type);
    304                 $variation_id      = $variation['variation_id'];
    305 
    306                 $plan_installments = $variation_product->get_meta("vindi_max_credit_installments_$variation_id");
    307 
    308                 if (!$plan_installments || $plan_installments === 0) {
    309                     $plan_installments = 1;
    310                 }
     306        $variation_id      = $variation['variation_id'];
     307
     308        $plan_installments = $variation_product->get_meta("vindi_max_credit_installments_$variation_id");
     309
     310        if (!$plan_installments || $plan_installments === 0) {
     311          $plan_installments = 1;
     312        }
    311313
    312314        $trigger_day = VindiConversions::convertTriggerToDay(
     
    341343            'billing_cycles' => ($product->get_meta('_subscription_length') == 0) ? null : $product->get_meta('_subscription_length'),
    342344            'code' => 'WC-' . $data['id'],
    343                       'installments' => $plan_installments,
     345            'installments' => $plan_installments,
    344346            'status' => ($data['status'] == 'publish') ? 'active' : 'inactive',
    345347          )
     
    367369    );
    368370
    369     $vindi_product_id = get_post_meta($post_id, 'vindi_product_id', true);
     371    $vindi_product_id = $product->get_meta('vindi_product_id', true);
    370372
    371373    // Updates the product within the Vindi
     
    384386    );
    385387
    386     $vindi_plan_id     = get_post_meta($post_id, 'vindi_plan_id', true);
    387           $plan_installments = $product->get_meta("vindi_max_credit_installments_$post_id");
    388           if (!$plan_installments || $plan_installments === 0) {
    389               $plan_installments = 1;
    390           }
     388    $vindi_plan_id     = $product->get_meta('vindi_plan_id', true);
     389    $plan_installments = $product->get_meta("vindi_max_credit_installments_$post_id");
     390    if (!$plan_installments || $plan_installments === 0) {
     391      $plan_installments = 1;
     392    }
    391393
    392394    // Updates the plan within the Vindi
     
    401403        'billing_cycles' => ($product->get_meta('_subscription_length') == 0) ? null : $product->get_meta('_subscription_length'),
    402404        'code' => 'WC-' . $data['id'],
    403             'installments' => $plan_installments,
     405        'installments' => $plan_installments,
    404406        'status' => ($data['status'] == 'publish') ? 'active' : 'inactive',
    405407      )
     
    427429  function trash($post_id)
    428430  {
     431    $product = wc_get_product($post_id);
    429432    // Check if the post is product
    430     if (get_post_type($post_id) != 'product') {
    431       return;
    432     }
    433 
    434     $product = wc_get_product($post_id);
     433    if ($product->get_type() != 'product') {
     434      return;
     435    }
     436
    435437    // Check if the post is of the signature type
    436         if (!in_array($product->get_type(), $this->allowedTypes)) {
    437             return;
    438         }
    439 
    440     $vindi_product_id = get_post_meta($product->id, 'vindi_product_id', true);
    441     $vindi_plan_id = get_post_meta($product->id, 'vindi_plan_id', true);
     438    if (!in_array($product->get_type(), $this->allowedTypes)) {
     439      return;
     440    }
     441
     442    $vindi_product_id = $product->get_meta('vindi_product_id', true);
     443    $vindi_plan_id = $product->get_meta('vindi_plan_id', true);
    442444
    443445    if (empty($vindi_product_id) || empty($vindi_plan_id)) {
     
    469471  function untrash($post_id)
    470472  {
     473    $product = wc_get_product($post_id);
    471474    // Check if the post is product
    472     if (get_post_type($post_id) != 'product') {
    473       return;
    474     }
    475 
    476     $product = wc_get_product($post_id);
     475    if ($product->get_type() != 'product') {
     476      return;
     477    }
     478
    477479    // Check if the post is of the signature type
    478         if (!in_array($product->get_type(), $this->allowedTypes)) {
    479             return;
    480         }
    481 
    482     $vindi_product_id = get_post_meta($product->id, 'vindi_product_id', true);
    483     $vindi_plan_id = get_post_meta($product->id, 'vindi_plan_id', true);
     480    if (!in_array($product->get_type(), $this->allowedTypes)) {
     481      return;
     482    }
     483
     484    $vindi_product_id = $product->get_meta('vindi_product_id', true);
     485    $vindi_plan_id = $product->get_meta('vindi_plan_id', true);
    484486
    485487    if (empty($vindi_product_id) || empty($vindi_plan_id)) {
  • vindi-payment-gateway/trunk/src/controllers/ProductController.php

    r3056291 r3323666  
    3737  function __construct(VindiSettings $vindi_settings)
    3838  {
    39         $this->routes = $vindi_settings->routes;
    40         $this->logger = $vindi_settings->logger;
    41 
    42         /**
    43          * Define wich product types to NOT handle in this controller.
    44          * Basically they are the same as the PlansController, but
    45          * the check is reversed to ignore this types
    46          */
    47         $this->ignoredTypes = array('variable-subscription', 'subscription');
    48 
    49         add_action('wp_insert_post', array($this, 'create'), 10, 3);
    50         add_action('wp_trash_post', array($this, 'trash'), 10, 1);
    51         add_action('untrash_post', array($this, 'untrash'), 10, 1);
     39    $this->routes = $vindi_settings->routes;
     40    $this->logger = $vindi_settings->logger;
     41
     42    /**
     43     * Define wich product types to NOT handle in this controller.
     44     * Basically they are the same as the PlansController, but
     45     * the check is reversed to ignore this types
     46     */
     47    $this->ignoredTypes = array('variable-subscription', 'subscription');
     48
     49    add_action('wp_insert_post', array($this, 'create'), 10, 3);
     50    add_action('wp_trash_post', array($this, 'trash'), 10, 1);
     51    add_action('untrash_post', array($this, 'untrash'), 10, 1);
    5252  }
    5353
     
    6060   * @SuppressWarnings(PHPMD.MissingImport)
    6161   */
    62   function create($post_id, $post, $update, $recreated = false)
    63   {
     62  function create($post_id, $recreated = false)
     63  {
     64        $product = wc_get_product($post_id);
     65        // Check if the post is product
     66        if (!$product) {
     67          return;
     68        }
     69        $post_status = $product->get_status();
    6470        // Check if the post is a draft
    65         if (strpos(get_post_status($post_id), 'draft') !== false) {
    66           return;
    67         }
    68         // Check if the post is product
    69         if (get_post_type($post_id) != 'product') {
     71        if (str_contains($post_status, 'draft')) {
    7072          return;
    7173        }
    7274            $post_meta = new PostMeta();
    7375        if ($post_meta->check_vindi_item_id($post_id, 'vindi_product_id') > 1) {
    74             update_post_meta($post_id, 'vindi_product_id', '');
     76            $product->update_meta_data('vindi_product_id', '');
     77            $product->save();
    7578        }
    7679
    7780        // Check if it's a new post
    7881        // The $update value is unreliable because of the auto_draft functionality
    79         if(!$recreated && get_post_status($post_id) != 'publish' || !empty(get_post_meta($post_id, 'vindi_product_id', true))) {
     82        $vindi_product_id = $product->get_meta('vindi_product_id', true);
     83        if(!$recreated && $product->get_status() != 'publish' || !empty($vindi_product_id)) {
    8084          return $this->update($post_id);
    8185        }
    8286
    83         $product = wc_get_product($post_id);
    8487
    8588        // Check if the post is NOT of the subscription type
     
    104107              // Saving product id and plan in the WC goal
    105108          if ($createdProduct && isset($createdProduct['id'])) {
    106             update_post_meta( $post_id, 'vindi_product_id', $createdProduct['id'] );
     109            $product->update_meta_data('vindi_product_id', $createdProduct['id']);
     110            $product->save();
    107111            set_transient('vindi_product_message', 'created', 60);
    108112          } else {
     
    116120  {
    117121        $product = wc_get_product($post_id);
    118 
    119122        // Check if the post is NOT of the subscription type
    120123        if (in_array($product->get_type(), $this->ignoredTypes)) {
     
    123126
    124127        // Checks whether there is a vindi product ID associated within
    125         $vindi_product_id = get_post_meta($post_id, 'vindi_product_id', true);
     128        $vindi_product_id = $product->get_meta('vindi_product_id', true);
    126129
    127130        if(empty($vindi_product_id)) {
     
    131134
    132135        $data = $product->get_data();
    133 
    134136        // Updates the product within the Vindi
    135137        $updatedProduct = $this->routes->updateProduct(
     
    165167  {
    166168        // Check if the post is product
    167         if (get_post_type($post_id) != 'product') {
    168           return;
    169         }
    170 
    171         $product = wc_get_product($post_id);
    172 
    173         // Check if the post is NOT of the subscription type
    174         if (in_array($product->get_type(), $this->ignoredTypes)) {
    175           return;
    176         }
    177 
    178         $vindi_product_id = get_post_meta($post_id, 'vindi_product_id', true);
     169        $product = wc_get_product($post_id);
     170        if (!$product) {
     171          return;
     172        }
     173        // Check if the post is NOT of the subscription type
     174        if (in_array($product->get_type(), $this->ignoredTypes)) {
     175          return;
     176        }
     177
     178        $vindi_product_id = $product->get_meta('vindi_product_id', true);
    179179
    180180        if(empty($vindi_product_id)) {
     
    198198  function untrash($post_id)
    199199  {
     200        $product = wc_get_product($post_id);
    200201        // Check if the post is product
    201         if (get_post_type($post_id) != 'product') {
    202           return;
    203         }
    204 
    205         $product = wc_get_product($post_id);
    206 
    207         // Check if the post is NOT of the subscription type
    208         if (in_array($product->get_type(), $this->ignoredTypes)) {
    209           return;
    210         }
    211 
    212         $vindi_product_id = get_post_meta($post_id, 'vindi_product_id', true);
    213 
     202        if (!$product) {
     203          return;
     204        }
     205        // Check if the post is NOT of the subscription type
     206        if (in_array($product->get_type(), $this->ignoredTypes)) {
     207          return;
     208        }
     209
     210        $vindi_product_id = $product->get_meta('vindi_product_id', true);
    214211        if(empty($vindi_product_id)) {
    215212          return;
  • vindi-payment-gateway/trunk/src/includes/admin/CouponsMetaBox.php

    r2901274 r3323666  
    2525            'id'      => 'cycle_count',
    2626            'label'   => __('Número de ciclos do cupom', VINDI),
    27             'value'   => get_post_meta($coupon_id, 'cycle_count')[0],
     27            'value'   => $coupon->get_meta('cycle_count', true),
    2828            'options' => array(
    2929              '0'  => 'Todos os ciclos',
  • vindi-payment-gateway/trunk/src/includes/admin/ProductsMetabox.php

    r2959528 r3323666  
    11<?php
     2
    23namespace VindiPaymentGateways;
    34
     
    3334    {
    3435        global $woocommerce, $post;
    35 
    3636        $product = wc_get_product($post->ID);
    3737        if (!$product) {
     
    6666    private function show_meta_custom_data($subscription_id)
    6767    {
     68        $product = wc_get_product($subscription_id);
     69        $field_id = "vindi_max_credit_installments_$subscription_id";
     70        $value = $product ? $product->get_meta($field_id, true) : '';
     71
    6872        echo '<div class="product_custom_field">';
    6973
    7074        woocommerce_wp_text_input(
    7175            array(
    72                 'id'    => "vindi_max_credit_installments_$subscription_id",
    73                 'value' => get_post_meta($subscription_id, "vindi_max_credit_installments_$subscription_id", true),
     76                'id'    => $field_id,
     77                'value' => $value,
    7478                'label' => __('Máximo de parcelas com cartão de crédito', 'woocommerce'),
    7579                'type'  => 'number',
     
    134138        $post_id = $product->get_id();
    135139
    136         $period = $this->get_post_vars('_subscription_period');
    137         $interval = $this->get_post_vars('_subscription_period_interval');
     140        $period = $product->get_meta('_subscription_period', true);
     141        $interval = $product->get_meta('_subscription_period_interval', true);
    138142        $installments = $this->get_post_vars("vindi_max_credit_installments_$post_id");
    139 
    140143        if ($period && $interval) {
    141144            $this->save_woocommerce_product_custom_fields($post_id, $installments, $period, $interval);
     
    145148    private function save_woocommerce_product_custom_fields($post_id, $installments, $period, $interval)
    146149    {
     150        $product = wc_get_product($post_id);
    147151        if ($period === 'year' && $installments > 12) {
    148152            $installments = 12;
    149153        }
     154        error_log(var_export("interval: $interval, period: $period, installments: $installments", true));
    150155        if ($period === 'month' && $installments > $interval) {
    151156            $installments = $interval;
    152157        }
    153 
    154158        if (!$installments) {
    155159            $installments = 1;
    156160        }
    157 
    158         update_post_meta($post_id, "vindi_max_credit_installments_$post_id", $installments);
     161        $product->update_meta_data("vindi_max_credit_installments_$post_id", $installments);
     162        $product->save();
    159163    }
    160164
  • vindi-payment-gateway/trunk/src/includes/gateways/CreditPayment.php

    r3269711 r3323666  
    113113
    114114        $is_trial = $this->check_is_trial();
    115 
    116115        $this->vindi_settings->get_template('creditcard-checkout.html.php', compact(
    117116            'installments',
     
    238237            return $this->installments;
    239238        }
     239
    240240        $installments = 0;
    241241        foreach ($this->vindi_settings->woocommerce->cart->cart_contents as $item) {
    242             $plan_id = $item['data']->get_meta('vindi_plan_id');
    243 
    244             if (!empty($plan_id)) {
    245                 $plan = $this->routes->getPlan($plan_id);
     242            $product = $item['data'];
     243            $product_id = $product->get_id();
     244
     245            $product_installments = $product->get_meta("vindi_max_credit_installments_$product_id", true);
     246
     247            if (!empty($product_installments)) {
     248                $product_installments = intval($product_installments);
    246249
    247250                if ($installments == 0) {
    248                     $installments = $plan['installments'];
    249                 } elseif ($plan['installments'] < $installments) {
    250                     $installments = $plan['installments'];
     251                    $installments = $product_installments;
     252                } elseif ($product_installments < $installments) {
     253                    $installments = $product_installments;
    251254                }
    252255            }
  • vindi-payment-gateway/trunk/src/routes/RoutesApi.php

    r3269711 r3323666  
    5353  public function createPlan($data)
    5454  {
    55 
    5655    $response = $this->api->request('plans', 'POST', $data);
    5756
  • vindi-payment-gateway/trunk/src/services/Webhooks.php

    r3199107 r3323666  
    77use WP_Query;
    88use WC_Order;
     9use WC_Order_Query;
    910
    1011class VindiWebhooks
     
    176177            }
    177178
    178             $vindi_order = get_post_meta($order->id, 'vindi_order', true);
     179            $vindi_order = $order->get_meta('vindi_order', true);
    179180            if (!is_array($vindi_order)) {
    180181                return wp_send_json(['message' => 'Pedido Vindi não encontrado.'], 422);
     
    436437   * @return WC_Order
    437438   */
    438     private function find_order_by_bill_id($bill_id)
    439   {
    440     $args = array(
    441       'post_type' => 'shop_order',
    442       'meta_key' => 'vindi_bill_id',
    443       'meta_value' => $bill_id,
    444       'post_status' => 'any',
    445     );
    446 
    447     $query = new WP_Query($args);
    448 
    449     if (false === $query->have_posts())
    450       throw new Exception(sprintf(__('Pedido com bill_id #%s não encontrado!', VINDI), $bill_id), 2);
    451 
    452     return wc_get_order($query->post->ID);
    453     }
     439  private function find_order_by_bill_id($bill_id)
     440  {
     441      $query = new WC_Order_Query(array(
     442          'limit'        => 1,
     443          'type'         => 'shop_order',
     444          'status'       => array_keys(wc_get_order_statuses()),
     445          'meta_key'     => 'vindi_bill_id',
     446          'meta_value'   => $bill_id,
     447          'return'       => 'ids',
     448      ));
     449 
     450      $order_ids = $query->get_orders();
     451 
     452      if (empty($order_ids)) {
     453          throw new Exception(
     454              sprintf(__('Pedido com bill_id #%s não encontrado!', VINDI), $bill_id), 2
     455          );
     456      }
     457 
     458      return wc_get_order($order_ids[0]);
     459  }
    454460
    455461  /**
  • vindi-payment-gateway/trunk/src/utils/CreditPaymentHelpers.php

    r3179566 r3323666  
    55class CreditHelpers
    66{
    7 
    87    public function get_cart_total($cart)
    98    {
    109        $total = $cart->total;
    11         $recurring = end($cart->recurring_carts);
    12         if (floatval($cart->total) == 0 && is_object($recurring)) {
    13             $total = $recurring->total;
     10        if (is_array($cart->recurring_carts) && !empty($cart->recurring_carts)) {
     11            $recurring = end($cart->recurring_carts);
     12
     13            if (floatval($cart->total) == 0 && is_object($recurring)) {
     14                $total = $recurring->total;
     15            }
    1416        }
     17       
    1518        foreach ($cart->get_fees() as $fee) {
    1619            if ($fee->name == __('Juros', VINDI)) {
  • vindi-payment-gateway/trunk/src/utils/DefinitionVariables.php

    r3280960 r3323666  
    11<?php
    22
    3 define('VINDI_VERSION', '1.3.8');
     3define('VINDI_VERSION', '1.3.9');
    44
    55define('VINDI_MININUM_WP_VERSION', '5.0');
  • vindi-payment-gateway/trunk/src/utils/FrontendFilesLoader.php

    r3179566 r3323666  
    1515    add_action('admin_enqueue_scripts', array($this, 'adminFiles'));
    1616        add_action('wp_enqueue_scripts', [$this, 'enqueue_inputmask_scripts']);
    17         add_action('add_meta_boxes', array($this, 'check_for_subscription_in_order'));
     17        add_action('add_meta_boxes', array($this, 'checkForSubscriptionInOrder'));
    1818        add_action('admin_enqueue_scripts', array($this, 'enqueue_payment_link_generator_script'));
    1919  }
     
    113113    }
    114114
    115     public function check_for_subscription_in_order()
     115    public function checkForSubscriptionInOrder()
    116116    {
     117        global $current_screen;
    117118        global $post;
    118         if ($this->is_shop_order_or_subscription($post)) {
    119             $has_subscription = $this->order_has_subscription($post->ID);
    120             $this->enqueue_notification_script($has_subscription);
     119       
     120        $post_type = isset($post) && isset($post->post_type) ? $post->post_type : null;
     121        $screen_post_type = isset($current_screen) && isset($current_screen->post_type) ? $current_screen->post_type : null;
     122       
     123        if ($this->is_shop_order_or_subscription($post_type) || $this->is_shop_order_or_subscription($screen_post_type)) {
     124            $post_id = isset($post) && isset($post->ID) ? $post->ID : (isset($_GET['id']) ? $_GET['id'] : null);
     125           
     126            if ($post_id) {
     127                $has_subscription = $this->order_has_subscription($post_id);
     128                $this->enqueue_notification_script($has_subscription);
     129            }
    121130        }
    122131    }
     
    124133    private function is_shop_order_or_subscription($post)
    125134    {
    126         return $post->post_type === 'shop_order' || $post->post_type === 'shop_subscription';
     135        return $post === 'shop_order' || $post === 'shop_subscription';
    127136    }
    128 
    129137    private function order_has_subscription($order_id)
    130138    {
    131139        $order = wc_get_order($order_id);
     140        if (!$order) {
     141            return false;
     142        }
     143       
    132144        $subscriptions_product = new WC_Subscriptions_Product();
    133145       
     
    151163    }
    152164
    153     public function enqueue_payment_link_generator_script()
     165    public function enqueue_payment_link_generator_script($hook)
    154166    {
    155         $post = get_post_type();
    156         $dir_path = plugins_url('/assets/js/edit.js', plugin_dir_path(__FILE__));
    157         wp_register_script('edit-js', $dir_path, array('jquery'), VINDI_VERSION, true);
    158         wp_enqueue_script('edit-js');
    159        
    160         wp_localize_script('edit-js', 'orderData', array(
    161             'typePost' => $post
    162         ));
     167        global $current_screen;
     168   
     169        if ($current_screen->post_type === 'shop_order') {
     170            $dir_path = plugins_url('/assets/js/editpost.js', plugin_dir_path(__FILE__));
     171            wp_register_script('edit-js', $dir_path, array('jquery'), VINDI_VERSION, true);
     172            wp_enqueue_script('edit-js');
     173            wp_localize_script('edit-js', 'orderData', array(
     174                'isOrderPage' => true,
     175                'hpos' => isset($_GET['page']) && $_GET['page'] === 'wc-orders'
     176            ));
     177        }
    163178    }
    164179}
  • vindi-payment-gateway/trunk/src/utils/GenerateUser.php

    r3179566 r3323666  
    4343   
    4444        $billing_address_2 = $order->get_billing_address_2();
    45         $billing_neighborhood = get_post_meta($order->get_id(), '_billing_neighborhood', true);
     45        $billing_neighborhood = $order->get_meta('_billing_neighborhood', true);
    4646        $full_address_2 = '';
    4747
  • vindi-payment-gateway/trunk/src/utils/PaymentProcessor.php

    r3269711 r3323666  
    416416                }
    417417
    418                 update_post_meta($wc_subscription_id, 'vindi_subscription_id', $subscription_id);
     418                $subscription_obj = wcs_get_subscription( $wc_subscription_id );
     419                if ( $subscription_obj && is_a( $subscription_obj, 'WC_Subscription' ) ) {
     420                    $subscription_obj->update_meta_data( 'vindi_subscription_id', $subscription_id );
     421                    $subscription_obj->save();
     422                }
     423               
    419424                continue;
    420425            } catch (Exception $err) {
     
    481486    {
    482487        $product = $order_item->get_product();
    483         $product_id = $product->get_id();
    484488        if ($this->is_variable($product)) {
    485489            $product_id = $order_item['variation_id'];
    486         }
    487         $period = get_post_meta($product_id, '_subscription_period', true);
    488         $interval = get_post_meta($product_id, '_subscription_period_interval', true);
     490            $product = wc_get_product($product_id);
     491        }
     492        $period = $product->get_meta('_subscription_period', true);
     493        $interval = $product->get_meta('_subscription_period_interval', true);
    489494        $subscriptions_grouped_by_period[$period . $interval][] = $order_item;
    490495        $subscription_products[] = $order_item;
     
    580585
    581586        if ($product) {
    582             $cycles = (int) get_post_meta($product->get_id(), '_subscription_length', true);
     587            $cycles = (int) $product->get_meta('_subscription_length', true);
    583588        }
    584589        return $cycles > 0 ? $cycles : null;
     
    594599    private function is_one_time_shipping($product)
    595600    {
    596         return get_post_meta($product->get_id(), '_subscription_one_time_shipping', true) == 'yes';
     601        return $product->get_meta('_subscription_one_time_shipping', true) == 'yes';
    597602    }
    598603
     
    813818                $product_id = $order_item['product_id'];
    814819            }
    815             $vindi_id = get_post_meta($product_id, 'vindi_product_id', true);
     820            $vindi_id = $product->get_meta('vindi_product_id', true);
    816821            if (!$vindi_id) {
    817822                $vindi_id = $this->routes->findProductByCode('WC-' . $product_id)['id'];
     
    11641169    protected function config_discount_cycles($coupon, $plan_cycles = 0)
    11651170    {
    1166         $cycle_count = get_post_meta($coupon->get_id(), 'cycle_count', true);
     1171        $cycle_count = $coupon->get_meta('cycle_count', true);
    11671172        if ($coupon->get_discount_type() == 'recurring_percent') {
    11681173            $subscriptions_coupon = new WC_Subscriptions_Coupon();
     
    12271232
    12281233        if (isset($order_item['variation_id']) && $order_item['variation_id'] != 0) {
    1229             $vindi_plan = get_post_meta($order_item['variation_id'], 'vindi_plan_id', true);
     1234            $product_variation = wc_get_product($order_item['variation_id']);
     1235            $vindi_plan = $product_variation ? $product_variation->get_meta('vindi_plan_id', true) : null;
    12301236            if (empty($vindi_plan) || !is_numeric($vindi_plan) || is_null($vindi_plan) || $vindi_plan == 0) {
    1231                 $vindi_plan = get_post_meta($product->get_id(), 'vindi_plan_id', true);
     1237                $vindi_plan = $product->get_meta('vindi_plan_id', true);
    12321238            }
    12331239        } else {
    1234             $vindi_plan = get_post_meta($product->get_id(), 'vindi_plan_id', true);
     1240            $vindi_plan = $product->get_meta('vindi_plan_id', true);
    12351241        }
    12361242
     
    14951501        $product = $order_item->get_product();
    14961502        $product_id = $order_item->get_id();
    1497         $vindi_product_id = get_post_meta($product, 'vindi_product_id', true);
     1503        $vindi_product_id = $product->get_meta('vindi_product_id', true);
    14981504
    14991505        if (!$vindi_product_id) {
  • vindi-payment-gateway/trunk/src/utils/PostMeta.php

    r2901274 r3323666  
    22
    33namespace VindiPaymentGateways;
     4use WP_Query;
    45
    56class PostMeta
     
    1314    public function check_vindi_item_id($post_id, $meta)
    1415    {
    15         global $wpdb;
    16         $vindi_id = get_post_meta($post_id, $meta, true);
    17 
     16        $product = wc_get_product($post_id);
     17   
     18        if (!$product) {
     19            return 0;
     20        }
     21   
     22        $vindi_id = $product->get_meta($meta, true);
     23   
    1824        if (!$vindi_id) {
    1925            return 0;
    2026        }
    21        
    22         $sql = "SELECT
    23                   post_id as id
    24                 FROM {$wpdb->prefix}postmeta
    25                 WHERE
    26                   meta_key LIKE '$meta' AND
    27                   meta_value LIKE $vindi_id
    28                 ";
    29 
    30         $result = $wpdb->get_results($sql);
    31 
    32         if (is_array($result) && !empty($result)) {
    33             return count($result);
    34         }
    35 
    36         return 0;
     27   
     28        $args = [
     29            'post_type'  => 'product',
     30            'meta_key'   => $meta,
     31            'meta_value' => $vindi_id,
     32            'fields'     => 'ids',
     33            'posts_per_page' => -1,
     34        ];
     35   
     36        $query = new WP_Query($args);
     37   
     38        return count($query->posts);
    3739    }
    3840}
  • vindi-payment-gateway/trunk/src/utils/SubscriptionStatusHandler.php

    r3199107 r3323666  
    106106    public function get_wc_subscription_id($subscription_id)
    107107    {
    108         return get_post_meta($subscription_id, 'vindi_subscription_id', true) ? :
    109             get_post_meta($subscription_id, 'vindi_wc_subscription_id', true);
     108
     109        $subscription = wcs_get_subscription($subscription_id);
     110        if ($subscription) {
     111            $vindi_subscription_id = $subscription->get_meta('vindi_subscription_id', true);
     112            if (!empty($vindi_subscription_id)) {
     113                return $vindi_subscription_id;
     114            }
     115            return $subscription->get_meta('vindi_wc_subscription_id', true);
     116        }
    110117    }
    111118
  • vindi-payment-gateway/trunk/vindi.php

    r3280960 r3323666  
    77 * Author: Vindi
    88 * Author URI: https://www.vindi.com.br
    9  * Version: 1.3.8
     9 * Version: 1.3.9
    1010 * Requires at least: 4.4
    1111 * Tested up to: 6.8
Note: See TracChangeset for help on using the changeset viewer.