diff --git a/.codeclimate.yml b/.codeclimate.yml index aade2ce7..ad813d9f 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,4 +1,6 @@ engines: + duplication: + enabled: false csslint: enabled: true phpmd: diff --git a/readme.txt b/readme.txt index 5de012ee..8243288f 100644 --- a/readme.txt +++ b/readme.txt @@ -7,9 +7,9 @@ Tags: vindi, subscriptions, pagamento-recorrente, cobranca-recorrente, cobrança Author URI: https://vindi.com.br/ | https://mentores.com.br Author: Vindi | Mentores Digital Requires at least: 4.4 -Tested up to: 6.3 +Tested up to: 6.4 WC requires at least: 3.0.0 -WC tested up to: 7.6.0 +WC tested up to: 8.6.1 Requires PHP: 5.6 Stable Tag: 1.2.6 License: GPLv3 diff --git a/src/VindiWoocommerce.php b/src/VindiWoocommerce.php index fdb115fa..abad2fc2 100644 --- a/src/VindiWoocommerce.php +++ b/src/VindiWoocommerce.php @@ -111,6 +111,8 @@ public function __construct() )); add_filter('woocommerce_cart_needs_payment', [$this, 'filter_woocommerce_cart_needs_payment'], 10, 2); + add_action('wp_ajax_renew_pix_charge', [$this, 'renew_pix_charge']); + add_action('wp_ajax_nopriv_renew_pix_charge', [$this, 'renew_pix_charge']); } /** @@ -139,6 +141,7 @@ public function init() require_once plugin_dir_path(__FILE__) . '/includes/admin/Settings.php'; require_once plugin_dir_path(__FILE__) . '/includes/gateways/CreditPayment.php'; require_once plugin_dir_path(__FILE__) . '/includes/gateways/BankSlipPayment.php'; + require_once plugin_dir_path(__FILE__) . '/includes/gateways/PixPayment.php'; require_once plugin_dir_path(__FILE__) . '/utils/SubscriptionStatusHandler.php'; require_once plugin_dir_path(__FILE__) . '/utils/InterestPriceHandler.php'; @@ -183,6 +186,7 @@ public function add_gateway($methods) { $methods[] = new VindiCreditGateway($this->settings, $this->controllers); $methods[] = new VindiBankSlipGateway($this->settings, $this->controllers); + $methods[] = new VindiPixGateway($this->settings, $this->controllers); return $methods; } @@ -212,6 +216,39 @@ private function cart_has_trial($cart) return false; } + + public function renew_pix_charge() + { + $order_id = filter_input(INPUT_POST, 'order_id', FILTER_SANITIZE_NUMBER_INT); + $charge_id = filter_input(INPUT_POST, 'charge_id', FILTER_SANITIZE_NUMBER_INT); + $subscription_id = filter_input(INPUT_POST, 'subscription_id', FILTER_SANITIZE_NUMBER_INT); + + $order = wc_get_order($order_id); + $vindi_order = $order->get_meta('vindi_order', true); + + if ($charge_id && $subscription_id) { + $routes = new VindiRoutes($this->settings); + $charge = $routes->renewCharge($charge_id); + + if (isset($charge['status']) && isset($charge['last_transaction']['gateway_response_fields'])) { + $last_transaction = $charge['last_transaction']['gateway_response_fields']; + + $subscription = $vindi_order[$subscription_id]; + $bill = [ + 'id' => $subscription['bill']['id'], + 'status' => $subscription['bill']['status'], + 'charge_id' => $charge['id'], + 'pix_expiration' => $last_transaction['max_days_to_keep_waiting_payment'], + 'pix_code' => $last_transaction['qrcode_original_path'], + 'pix_qr' => $last_transaction['qrcode_path'], + ]; + + $vindi_order[$subscription_id]['bill'] = $bill; + $order->update_meta_data('vindi_order', $vindi_order); + $order->save(); + } + } + } } add_action('plugins_loaded', array(WcVindiPayment::class, 'get_instance')); diff --git a/src/assets/css/frontend.css b/src/assets/css/frontend.css index b35ffc41..652dd518 100644 --- a/src/assets/css/frontend.css +++ b/src/assets/css/frontend.css @@ -280,7 +280,7 @@ transform: rotateY(180deg); } -.vindi_bankslip_listing { +.vindi_payment_listing { background: #FFFFFF; border-radius: 2px; box-shadow: inset 5px 0px 0px #37D559; @@ -290,39 +290,39 @@ font-style: normal; margin-bottom: 1.41575em; } -.vindi_bankslip_listing .info_message { +.vindi_payment_listing .info_message { padding: 20px 30px; display: flex; } -.vindi_bankslip_listing .info_message .icon { +.vindi_payment_listing .info_message .icon { width: 30px; height: 30px; margin-right: 22px; background-image: url("../images/icon-bankslip.svg"); } -.vindi_bankslip_listing .info_message .message { +.vindi_payment_listing .info_message .message { display: flex; flex-direction: column; max-width: 90%; } -.vindi_bankslip_listing .info_message .message .message_title { +.vindi_payment_listing .info_message .message .message_title { margin: 0; line-height: 17px; font-weight: bold; font-size: 14px; } -.vindi_bankslip_listing .info_message .message .message_description { +.vindi_payment_listing .info_message .message .message_description { margin: 3px 0 0; line-height: 18px; font-weight: 300; font-size: 13px; } -.vindi_bankslip_listing .bankslips { +.vindi_payment_listing .charges { display: flex; flex-direction: column; align-items: flex-end; } -.vindi_bankslip_listing .bankslips .bankslip { +.vindi_payment_listing .charges .charge { width: calc(100% - 5px); display: flex; justify-content: space-between; @@ -330,13 +330,14 @@ border-top: 1px solid #E6E6E6; padding: 15px 17px 15px 25px; } -.vindi_bankslip_listing .bankslips .bankslip .product_title { +.vindi_payment_listing .charges .charge .product_title { + text-transform: capitalize; font-weight: bold; font-size: 14px; line-height: 17px; } -.vindi_bankslip_listing .bankslips .bankslip .download_button { - padding: 12px 30px; +.vindi_payment_listing .charges .charge .download_button { + padding: 12px 20px; background: #FFFFFF; border: 1px solid #006DFF; border-radius: 3px; @@ -347,11 +348,20 @@ text-align: center; text-decoration: none !important; transition: opacity 0.2s ease; + display: flex; + align-items: center; + justify-content: center; +} + +.vindi_payment_listing .charges .charge .download_button svg { + width: 24px; } -.vindi_bankslip_listing .bankslips .bankslip .download_button:hover { + +.vindi_payment_listing .charges .charge .download_button:hover { opacity: 0.5; + cursor: pointer; } -.vindi_bankslip_listing .bankslips .bankslip .download_button:focus { +.vindi_payment_listing .charges .charge .download_button:focus { outline-color: #006DFF; } diff --git a/src/assets/js/frontend.js b/src/assets/js/frontend.js index 4c3f364f..6053fe3b 100644 --- a/src/assets/js/frontend.js +++ b/src/assets/js/frontend.js @@ -16,10 +16,10 @@ class FrontEnd { jQuery(".vindi-change-card").bind('click', function () { jQuery('.vindi-old-cc-data').hide(); jQuery('.vindi-old-cc-data').find('input').prop('disabled', true); - + jQuery('.vindi-new-cc-data').find('input, select').prop('disabled', false); jQuery('.vindi-new-cc-data').show(); - + return false; }); } @@ -54,9 +54,9 @@ class FrontEnd { setCardNumber(element, id, number) { const svg = document.getElementById(id); - + if (svg) { - svg.innerHTML = element.value === '' ? number : element.value + svg.innerHTML = element.value === '' ? number : element.value } } @@ -141,6 +141,6 @@ class FrontEnd { new FrontEnd; -jQuery('body').on('updated_checkout', () => { - new FrontEnd +jQuery('body').on('updated_checkout', () => { + new FrontEnd }); diff --git a/src/assets/js/thankyou.js b/src/assets/js/thankyou.js new file mode 100644 index 00000000..3da58622 --- /dev/null +++ b/src/assets/js/thankyou.js @@ -0,0 +1,54 @@ +class Thankyou { + constructor() { + if (!document.querySelector(".vindi_payment_listing")) return; + + this.copyPixLine(); + this.renewPixCharge(); + } + + renewPixCharge() { + const btn = document.querySelector('#generate_new_qr_code'); + + if (btn) { + btn.addEventListener('click', () => { + const order = btn.getAttribute('data-order'); + const charge = btn.getAttribute('data-charge'); + const subscription = btn.getAttribute('data-subscription'); + + jQuery.ajax({ + url: ajax_object.ajax_url, + type: 'post', + data: { + action: 'renew_pix_charge', + charge_id: charge, + order_id: order, + subscription_id: subscription + }, + success: function(response) { + window.location.reload(); + } + }); + }); + } + } + + copyPixLine() { + const btn = document.querySelector('#copy_vindi_pix_code'); + + if(btn) { + btn.addEventListener('click', () => { + const text = btn.getAttribute('data-code'); + if (navigator?.clipboard?.writeText) { + navigator.clipboard.writeText(text); + } + }); + } + } +} + +new Thankyou; + +jQuery('body').on('updated_checkout', () => { + new Thankyou; +}) + diff --git a/src/assets/sass/frontend.sass b/src/assets/sass/frontend.sass index 8188f089..7e391b3e 100644 --- a/src/assets/sass/frontend.sass +++ b/src/assets/sass/frontend.sass @@ -275,7 +275,7 @@ //****************************\\ // BANK SLIPS' LIST STYLING \\ //****************************\\ -.vindi_bankslip_listing +.vindi_payment_listing background: #FFFFFF border-radius: 2px box-shadow: inset 5px 0px 0px #37D559 diff --git a/src/includes/gateways/BankSlipPayment.php b/src/includes/gateways/BankSlipPayment.php index b85028f3..0b81714f 100644 --- a/src/includes/gateways/BankSlipPayment.php +++ b/src/includes/gateways/BankSlipPayment.php @@ -135,7 +135,7 @@ public function thank_you_page($order_id) { $order = wc_get_order($order_id); if ($order->get_payment_method() == 'vindi-bank-slip') { - $vindi_order = get_post_meta($order_id, 'vindi_order', true); + $vindi_order = $order->get_meta('vindi_order', true); $order_to_iterate = $this->bank_slip_quantity_to_render($vindi_order); $this->vindi_settings->get_template( 'bankslip-download.html.php', @@ -148,7 +148,7 @@ public function show_bank_slip_download($order_id) { $order = wc_get_order($order_id); if ($order->get_payment_method() == 'vindi-bank-slip') { - $vindi_order = get_post_meta($order_id, 'vindi_order', true); + $vindi_order = $order->get_meta('vindi_order', true); $order_to_iterate = $this->bank_slip_quantity_to_render($vindi_order); if (!$order->is_paid() && !$order->has_status('cancelled')) { $this->vindi_settings->get_template( diff --git a/src/includes/gateways/PixPayment.php b/src/includes/gateways/PixPayment.php new file mode 100644 index 00000000..92251deb --- /dev/null +++ b/src/includes/gateways/PixPayment.php @@ -0,0 +1,147 @@ +id = 'vindi-pix'; + $this->icon = apply_filters('vindi_woocommerce_pix_icon', ''); + $this->method_title = __('Vindi - PIX', VINDI); + $this->method_description = __('Aceitar pagamentos via boleto bancário utilizando a Vindi.', VINDI); + $this->has_fields = true; + $this->supports = array( + 'subscriptions', + 'products', + 'subscription_cancellation', + 'subscription_reactivation', + 'subscription_suspension', + 'subscription_amount_changes', + 'subscription_payment_method_change', + 'subscription_payment_method_change_customer', + 'subscription_payment_method_change_admin', + 'subscription_date_changes', + 'multiple_subscriptions', + 'pre-orders' + ); + $this->init_form_fields(); + $this->init_settings(); + add_action('woocommerce_view_order', array(&$this, 'show_pix_download'), -10, 1); + add_action('woocommerce_thankyou_' . $this->id, array(&$this, 'thank_you_page')); + parent::__construct($vindiSettings, $controllers); + } + + /** + * Should return payment type for payment processing. + * @return string + */ + public function type() + { + return 'pix'; + } + + public function init_form_fields() + { + + $this->form_fields = array( + 'enabled' => array( + 'title' => __('Habilitar/Desabilitar', VINDI), + 'label' => __('Habilitar pagamento por PIX com Vindi', VINDI), + 'type' => 'checkbox', + 'default' => 'no', + ), + 'title' => array( + 'title' => __('Título', VINDI), + 'type' => 'text', + 'description' => __('Título que o cliente verá durante o processo de pagamento.', VINDI), + 'default' => __('PIX', VINDI), + ) + ); + } + + # Essa função é responsável por verificar a compra que está sendo feita + # No caso de uma assinatura única, o $order[0] não existirá e retornará ela mesmo + # Issue: https://github.com/vindi/vindi-woocommerce/issues/75 + public function pix_quantity_to_render($order) + { + if (!isset($order[0])) { + return $order; + } + + return $order[0]; + } + + public function payment_fields() + { + $user_country = $this->get_country_code(); + + if (empty($user_country)) { + _e('Selecione o País para visualizar as formas de pagamento.', VINDI); + return; + } + + $is_single_order = $this->is_single_order(); + $is_trial = $this->vindi_settings->get_is_active_sandbox(); + if ($is_trial) { + $is_trial = $this->routes->isMerchantStatusTrialOrSandbox(); + } + + $this->vindi_settings->get_template('pix-checkout.html.php', compact('is_trial', 'is_single_order')); + } + + public function thank_you_page($order_id) + { + $order = wc_get_order($order_id); + $vindi_order = []; + $order_to_iterate = 0; + + if ($order->get_payment_method() == 'vindi-pix') { + $vindi_order = $order->get_meta('vindi_order', true); + $order_to_iterate = $this->pix_quantity_to_render($vindi_order); + $this->vindi_settings->get_template( + 'pix-download.html.php', + compact('vindi_order', 'order_to_iterate', 'order_id') + ); + } + } + + public function show_pix_download($order_id) + { + $order = wc_get_order($order_id); + $vindi_order = []; + $order_to_iterate = 0; + + if ($order->get_payment_method() == 'vindi-pix') { + $vindi_order = $order->get_meta('vindi_order', true); + $order_to_iterate = $this->pix_quantity_to_render($vindi_order); + if (!$order->is_paid() && !$order->has_status('cancelled')) { + $this->vindi_settings->get_template( + 'pix-download.html.php', + compact('vindi_order', 'order_to_iterate', 'order_id') + ); + } + } + } +} diff --git a/src/routes/RoutesApi.php b/src/routes/RoutesApi.php index 6a7fdaa8..7e9a6278 100644 --- a/src/routes/RoutesApi.php +++ b/src/routes/RoutesApi.php @@ -58,6 +58,27 @@ public function createPlan($data) return $response['plan']; } + /** + * Update method for updating plan in the Vindi + * + * @since 1.0.0 + * @version 1.0.0 + * @return array + */ + public function renewCharge($charge_id) + { + $response = $this->api->request( + sprintf( + 'charges/%s/charge', + filter_var($charge_id, FILTER_SANITIZE_NUMBER_INT) + ), + 'POST', + [] + ); + + return $response['charge']; + } + /** * Update method for updating plan in the Vindi * diff --git a/src/services/Webhooks.php b/src/services/Webhooks.php index 83176f0e..546c6846 100644 --- a/src/services/Webhooks.php +++ b/src/services/Webhooks.php @@ -114,7 +114,7 @@ private function subscription_renew($renew_infos) $order_id = $subscription->get_last_order(); $order = $this->find_order_by_id($order_id); $subscription_id = $renew_infos['vindi_subscription_id']; - $order_post_meta = array(get_post_meta($order->id, 'vindi_order', true)); + $order_post_meta = array($order->get_meta('vindi_order', true)); $order_post_meta[$subscription_id]['cycle'] = $renew_infos['cycle']; $order_post_meta[$subscription_id]['product'] = $renew_infos['plan_name']; $order_post_meta[$subscription_id]['bill'] = array( @@ -122,7 +122,7 @@ private function subscription_renew($renew_infos) 'status' => $renew_infos['bill_status'], 'bank_slip_url' => $renew_infos['bill_print_url'], ); - update_post_meta($order->id, 'vindi_order', $order_post_meta); + $order->update_meta_data('vindi_order', $order_post_meta); $this->vindi_settings->logger->log('Novo Período criado: Pedido #'.$order->id); // We've already processed the renewal @@ -164,28 +164,35 @@ private function bill_created($data) */ private function bill_paid($data) { - if(empty($data->bill->subscription)) { - $order = $this->find_order_by_id($data->bill->code); + $order = false; + if (empty($data->bill->subscription)) { + $order = $this->find_order_by_id($data->bill->code); - $vindi_order = get_post_meta($order->id, 'vindi_order', true); - if(is_array($vindi_order)) { - $vindi_order['single_payment']['bill']['status'] = $data->bill->status; - } else { - return; - } - } else { - $vindi_subscription_id = $data->bill->subscription->id; - $cycle = $data->bill->period->cycle; - $order = $this->find_order_by_subscription_and_cycle($vindi_subscription_id, $cycle); + $vindi_order = $order->get_meta('vindi_order', true); + if (!is_array($vindi_order)) { + return; + } + $vindi_order['single_payment']['bill']['status'] = $data->bill->status; + } + + if (!empty($data->bill->subscription)) { + $vindi_subscription_id = $data->bill->subscription->id; + $cycle = $data->bill->period->cycle; + $order = $this->find_order_by_subscription_and_cycle($vindi_subscription_id, $cycle); + + $vindi_order = $order->get_meta('vindi_order', true); + if (!is_array($vindi_order)) { + return; + } - $vindi_order = get_post_meta($order->id, 'vindi_order', true); - if(is_array($vindi_order)) { - $vindi_order[$vindi_subscription_id]['bill']['status'] = $data->bill->status; - } else { - return; - } - } - update_post_meta($order->id, 'vindi_order', $vindi_order); + $vindi_order[$vindi_subscription_id]['bill']['status'] = $data->bill->status; + } + + if (!$order) { + return; + } + + $order->update_meta_data('vindi_order', $vindi_order); // Order informations always be updated in last array element $vindi_order_info = end($vindi_order); diff --git a/src/templates/bankslip-download.html.php b/src/templates/bankslip-download.html.php index 0b69c9c0..9be26ea3 100644 --- a/src/templates/bankslip-download.html.php +++ b/src/templates/bankslip-download.html.php @@ -1,6 +1,6 @@ -
+
@@ -12,10 +12,10 @@

-
+
-
+
@@ -26,7 +26,7 @@ -
+
diff --git a/src/templates/creditcard-checkout.html.php b/src/templates/creditcard-checkout.html.php index 7a8fcccb..18fd165d 100644 --- a/src/templates/creditcard-checkout.html.php +++ b/src/templates/creditcard-checkout.html.php @@ -157,7 +157,13 @@ * - + * - +
- +
diff --git a/src/templates/pix-checkout.html.php b/src/templates/pix-checkout.html.php new file mode 100644 index 00000000..61fe609a --- /dev/null +++ b/src/templates/pix-checkout.html.php @@ -0,0 +1,33 @@ + + + +
+

+

+ Modo Trial. + Este modo é proposto para a realização de testes e, portanto, + nenhum pedido será efetivamente cobrado.', + VINDI + ); ?> +

+
+ +
+ + +
+ +
+
+ + + +
+
diff --git a/src/templates/pix-download.html.php b/src/templates/pix-download.html.php new file mode 100644 index 00000000..613157b5 --- /dev/null +++ b/src/templates/pix-download.html.php @@ -0,0 +1,134 @@ + + +
+
+
+
+

+ +

+

+ +

+
+
+
+ $subscription) : ?> + +
+ + + +
+ +
+
+ Seu Qr Code Expirou! +
+ + + + + + +
+ +
+ + +
+ + +
+
+ + + +
+ + + + + + +
+ + + + +
+
+ diff --git a/src/utils/FrontendFilesLoader.php b/src/utils/FrontendFilesLoader.php index f77c77cc..8c20609a 100644 --- a/src/utils/FrontendFilesLoader.php +++ b/src/utils/FrontendFilesLoader.php @@ -23,12 +23,56 @@ public static function adminFiles() wp_enqueue_style('vindi_woocommerce_admin_style'); wp_enqueue_script("vindi_products", plugins_url('/assets/js/product.js', plugin_dir_path(__FILE__))); } - public static function frontendFiles() - { - wp_register_script('imask', plugins_url('/assets/js/imask.min.js', plugin_dir_path(__FILE__)), array(), VINDI_VERSION, true); + public static function frontendFiles() + { + wp_register_script( + 'vindi_woocommerce_frontend_js', + plugins_url('/assets/js/frontend.js', plugin_dir_path(__FILE__)), + array('jquery'), + VINDI_VERSION, + true + ); + wp_enqueue_script('vindi_woocommerce_frontend_js'); + + self::enqueueCreditCardScripts(); + self::enqueueThankyouPageScript(); + + wp_register_style( + 'vindi_woocommerce_style', + plugins_url('/assets/css/frontend.css', plugin_dir_path(__FILE__)), + array(), + VINDI_VERSION + ); + wp_enqueue_style('vindi_woocommerce_style'); + } + + public static function enqueueThankyouPageScript() + { + wp_register_script( + 'vindi_woocommerce_thankyou_js', + plugins_url('/assets/js/thankyou.js', plugin_dir_path(__FILE__)), + array(), + VINDI_VERSION, + true + ); + wp_enqueue_script('vindi_woocommerce_thankyou_js'); - wp_register_script('vindi_woocommerce_frontend_js', plugins_url('/assets/js/frontend.js', plugin_dir_path(__FILE__)), array('jquery', 'imask'), VINDI_VERSION, true); - wp_enqueue_script('vindi_woocommerce_frontend_js'); + wp_localize_script( + 'vindi_woocommerce_thankyou_js', + 'ajax_object', + array('ajax_url' => admin_url('admin-ajax.php')) + ); + } + + public static function enqueueCreditCardScripts() + { + wp_register_script( + 'imask', + plugins_url('/assets/js/imask.min.js', plugin_dir_path(__FILE__)), + array(), + VINDI_VERSION, + true + ); wp_register_script( 'vindi_woocommerce_masks_js', @@ -47,8 +91,5 @@ public static function frontendFiles() true ); wp_enqueue_script('vindi_woocommerce_brands_js'); - - wp_register_style('vindi_woocommerce_style', plugins_url('/assets/css/frontend.css', plugin_dir_path(__FILE__)), array(), VINDI_VERSION); - wp_enqueue_style('vindi_woocommerce_style'); - } + } } diff --git a/src/utils/PaymentGateway.php b/src/utils/PaymentGateway.php index 4fbaa5d8..ad8072df 100644 --- a/src/utils/PaymentGateway.php +++ b/src/utils/PaymentGateway.php @@ -248,7 +248,7 @@ public function process_refund($order_id, $amount = null, $reason = '') { } $results = []; - $order_meta = get_post_meta($order->id, 'vindi_order', true); + $order_meta = $order->get_meta('vindi_order', true); foreach ($order_meta as $key => $order_item) { $bill_id = $order_item['bill']['id']; diff --git a/src/utils/PaymentProcessor.php b/src/utils/PaymentProcessor.php index 7e9e3aa3..749a74c2 100644 --- a/src/utils/PaymentProcessor.php +++ b/src/utils/PaymentProcessor.php @@ -179,7 +179,6 @@ public function get_bank_slip_payment_type($customer_id) return array( 'customer_id' => $customer_id, 'payment_method_code' => $this->payment_method_code(), - ); } @@ -211,7 +210,21 @@ public function is_bank_slip() */ public function payment_method_code() { - return $this->is_cc() ? 'credit_card' : 'bank_slip'; + switch ($this->gateway->type()) { + case 'bank_slip': + $code = 'bank_slip'; + break; + case 'cc': + $code = 'credit_card'; + break; + case 'pix': + $code = 'pix'; + break; + default: + $code = ''; + break; + } + return $code; } /** @@ -354,7 +367,7 @@ public function process_order() } } - update_post_meta($this->order->get_id(), 'vindi_order', $order_post_meta); + $this->order->update_meta_data('vindi_order', $order_post_meta); WC()->session->__unset('current_payment_profile'); WC()->session->__unset('current_customer'); remove_action('woocommerce_scheduled_subscription_payment', 'WC_Subscriptions_Manager::prepare_renewal'); @@ -1020,7 +1033,7 @@ protected function create_subscription($customer_id, $order_item) } $subscription['wc_id'] = $wc_subscription_id; if (isset($subscription['bill']['id'])) { - update_post_meta($this->order->get_id(), 'vindi_bill_id', $subscription['bill']['id']); + $this->order->update_meta_data('vindi_bill_id', $subscription['bill']['id']); } return $subscription; } @@ -1088,7 +1101,7 @@ protected function create_bill($customer_id, $order_items) if ($bill['id']) { $this->logger->log(sprintf('Update Bill: %s', json_encode($bill))); - update_post_meta($this->order->id, 'vindi_bill_id', $bill['id']); + $this->order->update_meta_data('vindi_bill_id', $bill['id']); } return $bill; } @@ -1102,11 +1115,24 @@ protected function create_bill($customer_id, $order_items) */ protected function create_bill_meta_for_order($bill) { - + $bill_meta = []; $bill_meta['id'] = $bill['id']; $bill_meta['status'] = $bill['status']; + if (isset($bill['charges']) && count($bill['charges'])) { - $bill_meta['bank_slip_url'] = $bill['charges'][0]['print_url']; + $charges = end($bill['charges']); + + $bill_meta['bank_slip_url'] = $charges['print_url'] ?? ''; + if ($this->payment_method_code() === 'pix' + && isset($charges['last_transaction']['gateway_response_fields'])) { + $transaction = $charges['last_transaction']['gateway_response_fields']; + + $bill_meta['charge_id'] = $charges['id']; + $bill_meta['pix_expiration'] = $transaction['max_days_to_keep_waiting_payment']; + $bill_meta['pix_code'] = $transaction['qrcode_original_path']; + $bill_meta['pix_qr'] = $transaction['qrcode_path']; + unset($bill_meta['bank_slip_url']); + } } return $bill_meta; } diff --git a/src/utils/SubscriptionStatusHandler.php b/src/utils/SubscriptionStatusHandler.php index ff0cf18e..434cb027 100644 --- a/src/utils/SubscriptionStatusHandler.php +++ b/src/utils/SubscriptionStatusHandler.php @@ -154,7 +154,7 @@ public function order_canceled($order) $order = wc_get_order($order); } - $vindi_order = get_post_meta($order->id, 'vindi_order', true); + $vindi_order = $order->get_meta('vindi_order', true); if (!is_array($vindi_order)) { return; @@ -168,7 +168,7 @@ public function order_canceled($order) } } - update_post_meta($order->id, 'vindi_order', $vindi_order); + $order->update_meta_data('vindi_order', $vindi_order); if ($single_payment_bill_id) { $this->routes->deleteBill($single_payment_bill_id); diff --git a/vindi.php b/vindi.php index ec3ccd46..eb4b4e6a 100644 --- a/vindi.php +++ b/vindi.php @@ -8,9 +8,7 @@ * Author URI: https://www.vindi.com.br * Version: 1.2.6 * Requires at least: 4.4 - * Tested up to: 6.3 - * WC requires at least: 3.0.0 - * WC tested up to: 7.6.0 + * Tested up to: 6.4 * Text Domain: vindi-payment-gateway * * Domain Path: ./src/languages/