From b81b0cdcbf9a44c327140344ac33072729f2c095 Mon Sep 17 00:00:00 2001 From: JKacicM Date: Thu, 10 Mar 2022 19:16:08 -0300 Subject: [PATCH] Agrega estado del pago. Elimina Webpay --- includes/abstract-wc-gateway-khipu.php | 8 +- includes/class-wc-gateway-khipu-payme.php | 137 ----------------- ...lass-wc-gateway-khipu-regular-transfer.php | 1 + ...s-wc-gateway-khipu-simplified-transfer.php | 1 + includes/class-wc-gateway-khipu-webpay.php | 140 ------------------ includes/class-wc-gateway-khipu.php | 18 ++- readme.txt | 7 +- woocommerce-gateway-khipu.php | 10 +- 8 files changed, 30 insertions(+), 292 deletions(-) delete mode 100644 includes/class-wc-gateway-khipu-payme.php delete mode 100644 includes/class-wc-gateway-khipu-webpay.php diff --git a/includes/abstract-wc-gateway-khipu.php b/includes/abstract-wc-gateway-khipu.php index f607228..e375614 100644 --- a/includes/abstract-wc-gateway-khipu.php +++ b/includes/abstract-wc-gateway-khipu.php @@ -43,7 +43,7 @@ function create_payment($order_id) $configuration = new Khipu\Configuration(); $configuration->setSecret($this->secret); $configuration->setReceiverId($this->receiver_id); - $configuration->setPlatform('woocommerce-khipu', '3.0'); + $configuration->setPlatform('woocommerce-khipu', '3.1'); // $configuration->setDebug(true); $client = new Khipu\ApiClient($configuration); @@ -89,7 +89,7 @@ private function get_payment_response($notification_token) $configuration = new Khipu\Configuration(); $configuration->setSecret($this->secret); $configuration->setReceiverId($this->receiver_id); - $configuration->setPlatform('woocommerce-khipu', '3.0'); + $configuration->setPlatform('woocommerce-khipu', '3.1'); $client = new Khipu\ApiClient($configuration); $payments = new Khipu\Client\PaymentsApi($client); @@ -144,6 +144,10 @@ function check_ipn_response() } $order->add_order_note(sprintf(__('Pago verificado con código único de verificación khipu %s', 'woocommerce-gateway-khipu'), $paymentResponse->getPaymentId())); $order->payment_complete($paymentResponse->getPaymentId()); + $defined_status = get_option('woocommerce_gateway_khipu_after_payment_status'); + if ($defined_status) { + $order->update_status($defined_status); + } exit('Notification processed'); } diff --git a/includes/class-wc-gateway-khipu-payme.php b/includes/class-wc-gateway-khipu-payme.php deleted file mode 100644 index 002fa75..0000000 --- a/includes/class-wc-gateway-khipu-payme.php +++ /dev/null @@ -1,137 +0,0 @@ -id = 'khipupayme'; - - $this->has_fields = false; - $this->method_title = __('khipu PayMe', 'woocommerce-gateway-khipu'); - $this->method_description = sprintf( __( 'Las configuraciones generales de khipu se hacen aquí.', 'woocommerce-gateway-khipu' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=khipu' ) ); - - $this->notify_url = add_query_arg('wc-api', 'WC_Gateway_' . $this->id, home_url('/')); - - // Load the settings and init variables. - $this->init_form_fields(); - $this->init_settings(); - $this->title = $this->get_option('title'); - $this->description = $this->get_option('description'); - $this->receiver_id = get_option('woocommerce_gateway_khipu_receiver_id'); - $this->secret = get_option('woocommerce_gateway_khipu_secret'); - $this->icon = $this->get_payment_method_icon('PAY_ME'); - - add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page')); - add_action('woocommerce_update_options_payment_gateways_' . $this->id, - array($this, 'process_admin_options')); - - // Payment listener/API hook - add_action('woocommerce_api_wc_gateway_' . $this->id, array($this, 'check_ipn_response')); - - if (!$this->is_valid_for_use()) { - $this->enabled = false; - } - } - - /** - * Check if this gateway is enabled and available in the user's country - */ - function is_valid_for_use() - { - if (!$this->is_configured()){ - return false; - } - if (!$this->is_payment_method_available()) { - return false; - } - if (!$this->is_valid_currency()){ - return false; - } - return true; - } - - - function is_payment_method_available() - { - return $this->is_payment_method_available_in_khipu('PAY_ME'); - } - - function is_valid_currency() { - if (in_array(get_woocommerce_currency(), - apply_filters('woocommerce_' . $this->id . '_supported_currencies', array('BOB'))) - ) { - return true; - } - } - - function is_configured() { - return $this->secret && $this->receiver_id; - } - - - /** - * Initialise Gateway Settings Form Fields - */ - function init_form_fields() - { - $this->form_fields = array( - 'enabled' => array( - 'title' => __('Enable/Disable', 'woocommerce'), - 'type' => 'checkbox', - 'label' => sprintf(__('Habilita %s', 'woocommerce-gateway-khipu'), $this->method_title), - 'default' => 'yes' - ), - 'title' => array( - 'title' => __('Title', 'woocommerce'), - 'type' => 'text', - 'description' => __('This controls the title which the user sees during checkout.', - 'woocommerce'), - 'default' => __('khipu - PayMe Crédito y Débito', 'woocommerce-gateway-khipu'), - 'desc_tip' => true - ), - 'description' => array( - 'title' => __('Description', 'woocommerce'), - 'type' => 'textarea', - 'description' => __('Payment method description that the customer will see on your checkout.', - 'woocommerce'), - 'default' => __('Paga con cualquier Tarjeta de Crédito o Débito.', 'woocommerce-gateway-khipu') - ), - ); - - } - - - /** - * Process the payment and return the result - */ - function process_payment($order_id) - { - $order = new WC_Order($order_id); - return array('result' => 'success', 'redirect' => $order->get_checkout_payment_url(true)); - } - - /** - * Output for the order received page. - */ - function receipt_page($order) - { - $response = $this->create_payment($order); - if(method_exists($response, 'getPaymeUrl')) { - wp_redirect($response->getPaymeUrl()); - } else { - echo $response; - } - } - - - -} - diff --git a/includes/class-wc-gateway-khipu-regular-transfer.php b/includes/class-wc-gateway-khipu-regular-transfer.php index 721c4c1..90178db 100644 --- a/includes/class-wc-gateway-khipu-regular-transfer.php +++ b/includes/class-wc-gateway-khipu-regular-transfer.php @@ -28,6 +28,7 @@ public function __construct() $this->receiver_id = get_option('woocommerce_gateway_khipu_receiver_id'); $this->secret = get_option('woocommerce_gateway_khipu_secret'); $this->icon = $this->get_payment_method_icon('REGULAR_TRANSFER'); + $this->after_payment_status = get_option('woocommerce_gateway_khipu_after_payment_status'); add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page')); add_action('woocommerce_update_options_payment_gateways_' . $this->id, diff --git a/includes/class-wc-gateway-khipu-simplified-transfer.php b/includes/class-wc-gateway-khipu-simplified-transfer.php index 17155ac..328f47f 100644 --- a/includes/class-wc-gateway-khipu-simplified-transfer.php +++ b/includes/class-wc-gateway-khipu-simplified-transfer.php @@ -28,6 +28,7 @@ public function __construct() $this->receiver_id = get_option('woocommerce_gateway_khipu_receiver_id'); $this->secret = get_option('woocommerce_gateway_khipu_secret'); $this->icon = $this->get_payment_method_icon('SIMPLIFIED_TRANSFER'); + $this->after_payment_status = get_option('woocommerce_gateway_khipu_after_payment_status'); add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page')); add_action('woocommerce_update_options_payment_gateways_' . $this->id, diff --git a/includes/class-wc-gateway-khipu-webpay.php b/includes/class-wc-gateway-khipu-webpay.php deleted file mode 100644 index 8936ff6..0000000 --- a/includes/class-wc-gateway-khipu-webpay.php +++ /dev/null @@ -1,140 +0,0 @@ -id = 'khipuwebpay'; - - $this->has_fields = false; - $this->method_title = __('khipu WebPay', 'woocommerce-gateway-khipu'); - $this->method_description = sprintf(__('Las configuraciones generales de khipu se hacen aquí.', 'woocommerce-gateway-khipu'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=khipu')); - - $this->notify_url = add_query_arg('wc-api', 'WC_Gateway_' . $this->id, home_url('/')); - - // Load the settings and init variables. - $this->init_form_fields(); - $this->init_settings(); - $this->title = $this->get_option('title'); - $this->description = $this->get_option('description'); - $this->receiver_id = get_option('woocommerce_gateway_khipu_receiver_id'); - $this->secret = get_option('woocommerce_gateway_khipu_secret'); - $logo = $this->get_payment_method_icon('WEBPAY_PSP'); - if(!$logo) { - $logo = $this->get_payment_method_icon('WEBPAY'); - } - $this->icon = $logo; - - add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page')); - add_action('woocommerce_update_options_payment_gateways_' . $this->id, - array($this, 'process_admin_options')); - - // Payment listener/API hook - add_action('woocommerce_api_wc_gateway_' . $this->id, array($this, 'check_ipn_response')); - - if (!$this->is_valid_for_use()) { - $this->enabled = false; - } - } - - - /** - * Check if this gateway is enabled and available in the user's country - */ - function is_valid_for_use() - { - if (!$this->is_configured()){ - return false; - } - if (!$this->is_payment_method_available()) { - return false; - } - if (!$this->is_valid_currency()){ - return false; - } - return true; - } - - function is_payment_method_available() - { - return $this->is_payment_method_available_in_khipu("WEBPAY") || $this->is_payment_method_available_in_khipu("WEBPAY_PSP"); - } - - function is_valid_currency() { - if (in_array(get_woocommerce_currency(), - apply_filters('woocommerce_' . $this->id . '_supported_currencies', array('CLP'))) - ) { - return true; - } - } - - function is_configured() { - return $this->secret && $this->receiver_id; - } - - - /** - * Initialise Gateway Settings Form Fields - */ - function init_form_fields() - { - $this->form_fields = array( - 'enabled' => array( - 'title' => __('Enable/Disable', 'woocommerce'), - 'type' => 'checkbox', - 'label' => sprintf(__('Habilita %s', 'woocommerce-gateway-khipu'), $this->method_title), - 'default' => 'yes' - ), - 'title' => array( - 'title' => __('Title', 'woocommerce'), - 'type' => 'text', - 'description' => __('This controls the title which the user sees during checkout.', - 'woocommerce'), - 'default' => __('khipu - WebPay Crédito y Débito', 'woocommerce-gateway-khipu', 'woocommerce-gateway-khipu'), - 'desc_tip' => true - ), - 'description' => array( - 'title' => __('Description', 'woocommerce'), - 'type' => 'textarea', - 'description' => __('Payment method description that the customer will see on your checkout.', - 'woocommerce'), - 'default' => __('Paga con cualquier Tarjeta de Crédito o RedCompra.', 'woocommerce-gateway-khipu') - ), - ); - - } - - - /** - * Process the payment and return the result - */ - function process_payment($order_id) - { - $order = new WC_Order($order_id); - return array('result' => 'success', 'redirect' => $order->get_checkout_payment_url(true)); - } - - /** - * Output for the order received page. - */ - function receipt_page($order) - { - $response = $this->create_payment($order); - if (method_exists($response, 'getWebpayUrl')) { - wp_redirect($response->getWebpayUrl()); - } else { - echo $response; - } - } - - -} - diff --git a/includes/class-wc-gateway-khipu.php b/includes/class-wc-gateway-khipu.php index 8866f9a..3c7348c 100644 --- a/includes/class-wc-gateway-khipu.php +++ b/includes/class-wc-gateway-khipu.php @@ -14,7 +14,7 @@ public function __construct() $this->id = 'khipu'; $this->has_fields = false; $this->method_title = __('khipu configuración básica', 'woocommerce-gateway-khipu'); - $this->method_description = sprintf( __( 'khipu permite aceptar pagos con transferencia, tarjetas de crédito y débito. Crea un cuenta khipu y obten tus credenciales para WooCommerce.', 'woocommerce-gateway-khipu' ), 'https://khipu.com/page/precios', 'https://khipu.com/merchant/profile' ); + $this->method_description = sprintf( __( 'khipu permite aceptar pagos con transferencia bancaria. Crea un cuenta khipu y obten tus credenciales para WooCommerce.', 'woocommerce-gateway-khipu' ), 'https://khipu.com/page/precios', 'https://khipu.com/merchant/profile' ); // Load the settings and init variables. @@ -23,6 +23,7 @@ public function __construct() $this->title = __('khipu configuración básica', 'woocommerce-gateway-khipu'); $this->receiver_id = $this->get_option('receiver_id'); $this->secret = $this->get_option('secret'); + $this->after_payment_status = get_option('woocommerce_gateway_khipu_after_payment_status'); // Actions add_action('woocommerce_update_options_payment_gateways_' . $this->id, @@ -52,6 +53,7 @@ function process_admin_options() { update_option('woocommerce_gateway_khipu_receiver_id', $post_data['woocommerce_khipu_receiver_id']); update_option('woocommerce_gateway_khipu_secret', $post_data['woocommerce_khipu_secret']); update_option('woocommerce_gateway_khipu_payment_methods', ''); + update_option('woocommerce_gateway_khipu_after_payment_status', $post_data['woocommerce_khipu_after_payment_status']); } /** @@ -75,8 +77,20 @@ function init_form_fields() 'woocommerce-gateway-khipu'), 'default' => '', 'desc_tip' => true + ), + 'after_payment_status' => array( + 'title' => __('Estado del pedido pagado.'), + 'type' => 'select', + 'description' => __('Seleccione estado con el que desea dejar sus órdenes luego de pagadas.', 'woocommerce-gateway-khipu'), + 'type' => 'select', + 'options' => array( + 'wc-processing' => __('Procesando', 'woocommerce-gateway-khipu'), + 'wc-completed' => __('Completado', 'woocommerce-gateway-khipu'), + ), + 'default' => 'wc-processing', + 'desc_tip' => true ) - ); + ); } diff --git a/readme.txt b/readme.txt index b005869..931dcb8 100644 --- a/readme.txt +++ b/readme.txt @@ -4,15 +4,15 @@ Donate link: Tags: payment gateway, khipu, woocommerce, chile Requires at least: 3.3 Tested up to: 4.1 -Stable tag: 3.0 +Stable tag: 3.1 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html -Permite el uso de khipu en WooCommerce, khipu es un medio de pago que permite pagar usando Cuentas Bancarias, tarjetas de crédito, débito y prepago. +Permite el uso de khipu en WooCommerce, khipu es un medio de pago que permite pagar usando Cuentas Bancarias. == Description == -Permite el uso de khipu en WooCommerce, khipu es un medio de pago que permite pagar usando Cuentas Bancarias, tarjetas de crédito, débito y prepago. +Permite el uso de khipu en WooCommerce, khipu es un medio de pago que permite pagar usando Cuentas Bancarias. == Installation == @@ -31,6 +31,7 @@ No hay preguntas aún. 3. https://s3.amazonaws.com/static.khipu.com/id-cobrador.png == Changelog == +3.1 Permite elegir estado luego del apgo recibido. 3.0 Uso del timeout de woocommerce para recuperación de stock al crear un pago, detección automática de medios de pago disponibles. 2.9 Cambio de nombre en configuración de woocommerce 2.8.1 Corrección de URL de cancelación para permitir al usuario volver al carro diff --git a/woocommerce-gateway-khipu.php b/woocommerce-gateway-khipu.php index 470599b..44a3c4a 100644 --- a/woocommerce-gateway-khipu.php +++ b/woocommerce-gateway-khipu.php @@ -7,8 +7,8 @@ /** * Plugin Name: WooCommerce khipu Gateway * Plugin URI: https://khipu.com/page/woocommerce - * Description: Acepte pagos con transferencia, tarjetas de crédito o débito procesados por khipu - * Version: 3.0 + * Description: Acepte pagos con transferencia procesadas por khipu + * Version: 3.1 * Author: khipu * Author URI: https://khipu.com */ @@ -63,18 +63,14 @@ function woocommerce_gateway_khipu_init() **/ require_once dirname( __FILE__ ) . '/includes/abstract-wc-gateway-khipu.php'; require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-khipu.php'; - require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-khipu-webpay.php'; require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-khipu-simplified-transfer.php'; require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-khipu-regular-transfer.php'; - require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-khipu-payme.php'; function woocommerce_gateway_khipu_add_gateways($methods) { $methods[] = 'WC_Gateway_khipu'; $methods[] = 'WC_Gateway_khipu_simplified_transfer'; $methods[] = 'WC_Gateway_khipu_regular_transfer'; - $methods[] = 'WC_Gateway_khipu_webpay'; - $methods[] = 'WC_Gateway_khipu_payme'; return $methods; } @@ -84,7 +80,6 @@ function woocommerce_gateway_khipu_add_gateways($methods) function woocommerce_gateway_khipu_add_currencies( $currencies ) { $currencies['CLP'] = __( 'Peso Chileno', 'woocommerce' ); - $currencies['BOB'] = __( 'Boliviano', 'woocommerce' ); return $currencies; } @@ -93,7 +88,6 @@ function woocommerce_gateway_khipu_add_currencies( $currencies ) { function woocommerce_gateway_khipu_add_currencies_symbol( $currency_symbol, $currency ) { switch( $currency ) { case 'CLP': $currency_symbol = '$'; break; - case 'BOB': $currency_symbol = 'Bs'; break; } return $currency_symbol; }