Changeset 3323666
- Timestamp:
- 07/07/2025 01:53:24 PM (9 months ago)
- Location:
- vindi-payment-gateway/trunk
- Files:
-
- 4 deleted
- 17 edited
-
readme.txt (modified) (2 diffs)
-
src/assets/js/editpost.js (modified) (1 diff)
-
src/controllers/PlansController.php (modified) (20 diffs)
-
src/controllers/ProductController.php (modified) (8 diffs)
-
src/includes/admin/ButtonPaymentLink.php (deleted)
-
src/includes/admin/CouponsMetaBox.php (modified) (1 diff)
-
src/includes/admin/ProductsMetabox.php (modified) (5 diffs)
-
src/includes/admin/WcVindiColumns.php (deleted)
-
src/includes/gateways/CreditPayment.php (modified) (2 diffs)
-
src/routes/RoutesApi.php (modified) (1 diff)
-
src/services/Webhooks.php (modified) (3 diffs)
-
src/templates/admin-payment-button.html.php (deleted)
-
src/templates/admin-payment-link-button-column.php (deleted)
-
src/utils/CreditPaymentHelpers.php (modified) (1 diff)
-
src/utils/DefinitionVariables.php (modified) (1 diff)
-
src/utils/FrontendFilesLoader.php (modified) (4 diffs)
-
src/utils/GenerateUser.php (modified) (1 diff)
-
src/utils/PaymentProcessor.php (modified) (8 diffs)
-
src/utils/PostMeta.php (modified) (2 diffs)
-
src/utils/SubscriptionStatusHandler.php (modified) (1 diff)
-
vindi.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
vindi-payment-gateway/trunk/readme.txt
r3280960 r3323666 12 12 WC tested up to: 8.6.1 13 13 Requires PHP: 5.6 14 Stable Tag: 1.3. 814 Stable Tag: 1.3.9 15 15 License: GPLv3 16 16 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 40 40 41 41 == Changelog == 42 = 1.3.9 - 05/06/2025 = 43 -Lançamento da versão de patch. 44 - **Melhoria:** Adaptando o plugin para HPos. 45 42 46 = 1.3.8 - 24/04/2025 = 43 47 -Lançamento da versão de patch. 44 - **Correção:** Alteração no Tested up tode 6.4 para 6.8.48 - **Correção:** Alteração no test up de 6.4 para 6.8. 45 49 46 50 = 1.3.7 - 05/11/2024 = -
vindi-payment-gateway/trunk/src/assets/js/editpost.js
r3179566 r3323666 1 1 jQuery(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 } 12 15 } 13 }) 16 }); -
vindi-payment-gateway/trunk/src/controllers/PlansController.php
r3072649 r3323666 27 27 * @var VindiLogger 28 28 */ 29 private $logger;29 private $logger; 30 30 31 31 /** 32 32 * @var array 33 33 */ 34 private $allowedTypes;34 private $allowedTypes; 35 35 36 36 function __construct(VindiSettings $vindi_settings) … … 38 38 $this->routes = $vindi_settings->routes; 39 39 $this->logger = $vindi_settings->logger; 40 $this->allowedTypes = array('variable-subscription', 'subscription');40 $this->allowedTypes = array('variable-subscription', 'subscription'); 41 41 42 42 add_action('wp_insert_post', array($this, 'create'), 10, 3); … … 53 53 * @SuppressWarnings(PHPMD.MissingImport) 54 54 */ 55 function create($post_id, $ post, $update, $recreated = false)55 function create($post_id, $recreated = false) 56 56 { 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(); 58 63 // 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 } 75 77 76 78 // Check if it's a new post 77 79 // 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 } 86 85 87 86 // 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 } 91 90 92 91 // Checks if the plan is a variation and creates it 93 92 if ($product->get_type() == 'variable-subscription') { 94 95 93 $variations = $product->get_available_variations(); 96 94 $variations_products = $variations_plans = []; … … 104 102 $interval_count = $variation_product->get_meta('_subscription_period_interval'); 105 103 $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 } 113 111 114 112 $trigger_day = VindiConversions::convertTriggerToDay( … … 118 116 119 117 // 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); 121 119 $createdProduct = !empty($vindi_product_id) ? 122 120 $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 ); 135 133 136 134 // Creates the plan within the Vindi … … 143 141 'billing_cycles' => ($product->get_meta('_subscription_length') == 0) ? null : $product->get_meta('_subscription_length'), 144 142 'code' => 'WC-' . $data['id'], 145 'installments' => $plan_installments,143 'installments' => $plan_installments, 146 144 'status' => ($data['status'] == 'publish') ? 'active' : 'inactive', 147 145 'plan_items' => array( … … 158 156 159 157 // 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 } 167 169 } 168 170 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 } 175 181 176 182 return array( … … 182 188 $data = $product->get_data(); 183 189 184 185 190 $interval_type = $product->get_meta('_subscription_period'); 186 191 $interval_count = $product->get_meta('_subscription_period_interval'); … … 192 197 ); 193 198 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 } 198 203 199 204 // 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) : ''; 201 206 $createdProduct = !empty($vindi_product_id) ? 202 207 $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 ); 215 220 216 221 // Creates the plan within the Vindi … … 223 228 'billing_cycles' => ($product->get_meta('_subscription_length') == 0) ? null : $product->get_meta('_subscription_length'), 224 229 'code' => 'WC-' . $data['id'], 225 'installments' => $plan_installments,230 'installments' => $plan_installments, 226 231 'status' => ($data['status'] == 'publish') ? 'active' : 'inactive', 227 232 'plan_items' => array( … … 237 242 238 243 // 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 } 245 252 246 253 if ($createdPlan && $createdProduct) { … … 261 268 { 262 269 $product = wc_get_product($post_id); 263 264 270 // 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 } 268 274 269 275 // Checks whether there is a vindi plan ID created within 270 276 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); 274 278 if (empty($vindi_plan_id)) { 275 276 279 return $this->create($post_id, '', '', true); 277 280 } … … 288 291 289 292 // 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); 292 295 293 296 if (empty($vindi_plan_id)) { … … 298 301 299 302 $data = $variation_product->get_data(); 300 301 303 $interval_type = $variation_product->get_meta('_subscription_period'); 302 304 $interval_count = $variation_product->get_meta('_subscription_period_interval'); 303 305 $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 } 311 313 312 314 $trigger_day = VindiConversions::convertTriggerToDay( … … 341 343 'billing_cycles' => ($product->get_meta('_subscription_length') == 0) ? null : $product->get_meta('_subscription_length'), 342 344 'code' => 'WC-' . $data['id'], 343 'installments' => $plan_installments,345 'installments' => $plan_installments, 344 346 'status' => ($data['status'] == 'publish') ? 'active' : 'inactive', 345 347 ) … … 367 369 ); 368 370 369 $vindi_product_id = get_post_meta($post_id,'vindi_product_id', true);371 $vindi_product_id = $product->get_meta('vindi_product_id', true); 370 372 371 373 // Updates the product within the Vindi … … 384 386 ); 385 387 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 } 391 393 392 394 // Updates the plan within the Vindi … … 401 403 'billing_cycles' => ($product->get_meta('_subscription_length') == 0) ? null : $product->get_meta('_subscription_length'), 402 404 'code' => 'WC-' . $data['id'], 403 'installments' => $plan_installments,405 'installments' => $plan_installments, 404 406 'status' => ($data['status'] == 'publish') ? 'active' : 'inactive', 405 407 ) … … 427 429 function trash($post_id) 428 430 { 431 $product = wc_get_product($post_id); 429 432 // 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 435 437 // 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); 442 444 443 445 if (empty($vindi_product_id) || empty($vindi_plan_id)) { … … 469 471 function untrash($post_id) 470 472 { 473 $product = wc_get_product($post_id); 471 474 // 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 477 479 // 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); 484 486 485 487 if (empty($vindi_product_id) || empty($vindi_plan_id)) { -
vindi-payment-gateway/trunk/src/controllers/ProductController.php
r3056291 r3323666 37 37 function __construct(VindiSettings $vindi_settings) 38 38 { 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, but45 * the check is reversed to ignore this types46 */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); 52 52 } 53 53 … … 60 60 * @SuppressWarnings(PHPMD.MissingImport) 61 61 */ 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(); 64 70 // 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')) { 70 72 return; 71 73 } 72 74 $post_meta = new PostMeta(); 73 75 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(); 75 78 } 76 79 77 80 // Check if it's a new post 78 81 // 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)) { 80 84 return $this->update($post_id); 81 85 } 82 86 83 $product = wc_get_product($post_id);84 87 85 88 // Check if the post is NOT of the subscription type … … 104 107 // Saving product id and plan in the WC goal 105 108 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(); 107 111 set_transient('vindi_product_message', 'created', 60); 108 112 } else { … … 116 120 { 117 121 $product = wc_get_product($post_id); 118 119 122 // Check if the post is NOT of the subscription type 120 123 if (in_array($product->get_type(), $this->ignoredTypes)) { … … 123 126 124 127 // 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); 126 129 127 130 if(empty($vindi_product_id)) { … … 131 134 132 135 $data = $product->get_data(); 133 134 136 // Updates the product within the Vindi 135 137 $updatedProduct = $this->routes->updateProduct( … … 165 167 { 166 168 // 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); 179 179 180 180 if(empty($vindi_product_id)) { … … 198 198 function untrash($post_id) 199 199 { 200 $product = wc_get_product($post_id); 200 201 // 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); 214 211 if(empty($vindi_product_id)) { 215 212 return; -
vindi-payment-gateway/trunk/src/includes/admin/CouponsMetaBox.php
r2901274 r3323666 25 25 'id' => 'cycle_count', 26 26 '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), 28 28 'options' => array( 29 29 '0' => 'Todos os ciclos', -
vindi-payment-gateway/trunk/src/includes/admin/ProductsMetabox.php
r2959528 r3323666 1 1 <?php 2 2 3 namespace VindiPaymentGateways; 3 4 … … 33 34 { 34 35 global $woocommerce, $post; 35 36 36 $product = wc_get_product($post->ID); 37 37 if (!$product) { … … 66 66 private function show_meta_custom_data($subscription_id) 67 67 { 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 68 72 echo '<div class="product_custom_field">'; 69 73 70 74 woocommerce_wp_text_input( 71 75 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, 74 78 'label' => __('Máximo de parcelas com cartão de crédito', 'woocommerce'), 75 79 'type' => 'number', … … 134 138 $post_id = $product->get_id(); 135 139 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); 138 142 $installments = $this->get_post_vars("vindi_max_credit_installments_$post_id"); 139 140 143 if ($period && $interval) { 141 144 $this->save_woocommerce_product_custom_fields($post_id, $installments, $period, $interval); … … 145 148 private function save_woocommerce_product_custom_fields($post_id, $installments, $period, $interval) 146 149 { 150 $product = wc_get_product($post_id); 147 151 if ($period === 'year' && $installments > 12) { 148 152 $installments = 12; 149 153 } 154 error_log(var_export("interval: $interval, period: $period, installments: $installments", true)); 150 155 if ($period === 'month' && $installments > $interval) { 151 156 $installments = $interval; 152 157 } 153 154 158 if (!$installments) { 155 159 $installments = 1; 156 160 } 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(); 159 163 } 160 164 -
vindi-payment-gateway/trunk/src/includes/gateways/CreditPayment.php
r3269711 r3323666 113 113 114 114 $is_trial = $this->check_is_trial(); 115 116 115 $this->vindi_settings->get_template('creditcard-checkout.html.php', compact( 117 116 'installments', … … 238 237 return $this->installments; 239 238 } 239 240 240 $installments = 0; 241 241 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); 246 249 247 250 if ($installments == 0) { 248 $installments = $p lan['installments'];249 } elseif ($p lan['installments']< $installments) {250 $installments = $p lan['installments'];251 $installments = $product_installments; 252 } elseif ($product_installments < $installments) { 253 $installments = $product_installments; 251 254 } 252 255 } -
vindi-payment-gateway/trunk/src/routes/RoutesApi.php
r3269711 r3323666 53 53 public function createPlan($data) 54 54 { 55 56 55 $response = $this->api->request('plans', 'POST', $data); 57 56 -
vindi-payment-gateway/trunk/src/services/Webhooks.php
r3199107 r3323666 7 7 use WP_Query; 8 8 use WC_Order; 9 use WC_Order_Query; 9 10 10 11 class VindiWebhooks … … 176 177 } 177 178 178 $vindi_order = get_post_meta($order->id,'vindi_order', true);179 $vindi_order = $order->get_meta('vindi_order', true); 179 180 if (!is_array($vindi_order)) { 180 181 return wp_send_json(['message' => 'Pedido Vindi não encontrado.'], 422); … … 436 437 * @return WC_Order 437 438 */ 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 } 454 460 455 461 /** -
vindi-payment-gateway/trunk/src/utils/CreditPaymentHelpers.php
r3179566 r3323666 5 5 class CreditHelpers 6 6 { 7 8 7 public function get_cart_total($cart) 9 8 { 10 9 $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 } 14 16 } 17 15 18 foreach ($cart->get_fees() as $fee) { 16 19 if ($fee->name == __('Juros', VINDI)) { -
vindi-payment-gateway/trunk/src/utils/DefinitionVariables.php
r3280960 r3323666 1 1 <?php 2 2 3 define('VINDI_VERSION', '1.3. 8');3 define('VINDI_VERSION', '1.3.9'); 4 4 5 5 define('VINDI_MININUM_WP_VERSION', '5.0'); -
vindi-payment-gateway/trunk/src/utils/FrontendFilesLoader.php
r3179566 r3323666 15 15 add_action('admin_enqueue_scripts', array($this, 'adminFiles')); 16 16 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')); 18 18 add_action('admin_enqueue_scripts', array($this, 'enqueue_payment_link_generator_script')); 19 19 } … … 113 113 } 114 114 115 public function check _for_subscription_in_order()115 public function checkForSubscriptionInOrder() 116 116 { 117 global $current_screen; 117 118 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 } 121 130 } 122 131 } … … 124 133 private function is_shop_order_or_subscription($post) 125 134 { 126 return $post ->post_type === 'shop_order' || $post->post_type=== 'shop_subscription';135 return $post === 'shop_order' || $post === 'shop_subscription'; 127 136 } 128 129 137 private function order_has_subscription($order_id) 130 138 { 131 139 $order = wc_get_order($order_id); 140 if (!$order) { 141 return false; 142 } 143 132 144 $subscriptions_product = new WC_Subscriptions_Product(); 133 145 … … 151 163 } 152 164 153 public function enqueue_payment_link_generator_script( )165 public function enqueue_payment_link_generator_script($hook) 154 166 { 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 } 163 178 } 164 179 } -
vindi-payment-gateway/trunk/src/utils/GenerateUser.php
r3179566 r3323666 43 43 44 44 $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); 46 46 $full_address_2 = ''; 47 47 -
vindi-payment-gateway/trunk/src/utils/PaymentProcessor.php
r3269711 r3323666 416 416 } 417 417 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 419 424 continue; 420 425 } catch (Exception $err) { … … 481 486 { 482 487 $product = $order_item->get_product(); 483 $product_id = $product->get_id();484 488 if ($this->is_variable($product)) { 485 489 $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); 489 494 $subscriptions_grouped_by_period[$period . $interval][] = $order_item; 490 495 $subscription_products[] = $order_item; … … 580 585 581 586 if ($product) { 582 $cycles = (int) get_post_meta($product->get_id(),'_subscription_length', true);587 $cycles = (int) $product->get_meta('_subscription_length', true); 583 588 } 584 589 return $cycles > 0 ? $cycles : null; … … 594 599 private function is_one_time_shipping($product) 595 600 { 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'; 597 602 } 598 603 … … 813 818 $product_id = $order_item['product_id']; 814 819 } 815 $vindi_id = get_post_meta($product_id,'vindi_product_id', true);820 $vindi_id = $product->get_meta('vindi_product_id', true); 816 821 if (!$vindi_id) { 817 822 $vindi_id = $this->routes->findProductByCode('WC-' . $product_id)['id']; … … 1164 1169 protected function config_discount_cycles($coupon, $plan_cycles = 0) 1165 1170 { 1166 $cycle_count = get_post_meta($coupon->get_id(),'cycle_count', true);1171 $cycle_count = $coupon->get_meta('cycle_count', true); 1167 1172 if ($coupon->get_discount_type() == 'recurring_percent') { 1168 1173 $subscriptions_coupon = new WC_Subscriptions_Coupon(); … … 1227 1232 1228 1233 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; 1230 1236 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); 1232 1238 } 1233 1239 } else { 1234 $vindi_plan = get_post_meta($product->get_id(),'vindi_plan_id', true);1240 $vindi_plan = $product->get_meta('vindi_plan_id', true); 1235 1241 } 1236 1242 … … 1495 1501 $product = $order_item->get_product(); 1496 1502 $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); 1498 1504 1499 1505 if (!$vindi_product_id) { -
vindi-payment-gateway/trunk/src/utils/PostMeta.php
r2901274 r3323666 2 2 3 3 namespace VindiPaymentGateways; 4 use WP_Query; 4 5 5 6 class PostMeta … … 13 14 public function check_vindi_item_id($post_id, $meta) 14 15 { 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 18 24 if (!$vindi_id) { 19 25 return 0; 20 26 } 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); 37 39 } 38 40 } -
vindi-payment-gateway/trunk/src/utils/SubscriptionStatusHandler.php
r3199107 r3323666 106 106 public function get_wc_subscription_id($subscription_id) 107 107 { 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 } 110 117 } 111 118 -
vindi-payment-gateway/trunk/vindi.php
r3280960 r3323666 7 7 * Author: Vindi 8 8 * Author URI: https://www.vindi.com.br 9 * Version: 1.3. 89 * Version: 1.3.9 10 10 * Requires at least: 4.4 11 11 * Tested up to: 6.8
Note: See TracChangeset
for help on using the changeset viewer.