芝麻web文件管理V1.00
编辑当前文件:/home4/randall/public_html/sl/wp-content/plugins/bancard_/bancard.php
id = 'bancard'; $this->has_fields = false; $this->order_button_text = __('Proceder a Bancard', 'woocommerce'); $this->method_title = __('Bancard', 'woocommerce'); $this->method_description = sprintf(__('Bancard standard sends customers to Bancard to enter their payment information. Bancard IPN requires fsockopen/cURL support to update order statuses after payment. Check the %ssystem status%s page for more details.', 'woocommerce'), '
', '
'); $this->supports = array( 'products', 'refunds' ); // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables. $this->title = $this->get_option('title'); $this->description = $this->get_option('description'); $this->testmode = 'yes' === $this->get_option('testmode', 'no'); $this->debug = 'yes' === $this->get_option('debug', 'no'); $this->email = $this->get_option('email'); $this->receiver_email = $this->get_option('receiver_email', $this->email); $this->identity_token = $this->get_option('identity_token'); self::$log_enabled = $this->debug; add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); add_action('woocommerce_thankyou_bancard', array($this, 'thankyou')); add_action('woocommerce_api_bancard_confirm', array($this, 'confirm')); add_action('woocommerce_api_process_refund', array($this, 'process_refund')); if (!$this->is_valid_for_use()) { $this->enabled = 'no'; } } /** * Check if this gateway is enabled and available in the user's country. * @return bool */ public function is_valid_for_use() { return in_array(get_woocommerce_currency(), apply_filters('woocommerce_bancard_supported_currencies', array('PYG'))); } public function confirm() { global $wp; // Accept only POST. if ($_SERVER['REQUEST_METHOD'] != "POST") { status_header(404); exit; } // Parse posted data. try { $post = json_decode(file_get_contents('php://input')); } catch (Exception $e) { status_header(403); exit; } // Is empty? if (empty($post)) { status_header(403); exit; } // Get order. try { $order = wc_get_order($post->operation->shop_process_id); } catch (Exception $e) { status_header(200); exit; } if(!$order) { status_header(200); exit; } $amount = number_format($order->get_total(), 2, ".", ""); if ($amount !== $post->operation->amount) { status_header(403); exit; } $order->add_order_note($post->operation->response_description); $order->payment_complete($post->operation->ticket_number); $order->update_status('completed'); header('Content-type: application/json'); echo json_encode([ "status" => "success", "message" => "Su pago ha sido confirmado y completado su pedido", "developer_message" => "Operation confirmed"]); exit; } public function thankyou() { // If you want to add something, add it here... } /** * Logging method. * @param string $message */ public static function log($message) { if (self::$log_enabled) { if (empty(self::$log)) { self::$log = new WC_Logger(); } self::$log->add('bancard', $message); } } /** * Admin Panel Options. * - Options for bits like 'title' and availability on a country-by-country basis. * * @since 1.0.0 */ public function admin_options() { parent::admin_options(); } /** * Initialise Gateway Settings Form Fields. */ public function init_form_fields() { $this->form_fields = include('includes/settings-bancard.php'); } /** * Get the transaction URL. * @param WC_Order $order * @return string */ // public function get_transaction_url($order) // { // if ($this->testmode) { // $this->view_transaction_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%s'; // } else { // $this->view_transaction_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%s'; // } // return parent::get_transaction_url($order); // } /** * Process the payment and return the result. * @param int $order_id * @return array */ public function process_payment($order_id) { include('includes/Bancard/autoload.php'); $order = wc_get_order($order_id); $amount = number_format($order->get_total(), 2, ".", ""); $data = [ 'shop_process_id' => $order->id, 'amount' => $amount, 'currency' => 'PYG', 'additional_data' => '', 'description' => 'Producto de Servilibro', 'private_key' => $this->get_option('api_private_key'), 'public_key' => $this->get_option('api_public_key'), 'return_url' => $this->get_return_url($order), 'cancel_url' => $order->get_cancel_order_url_raw() ]; if ($this->testmode == 'yes') { $env = Bancard\Bancard\Core\Environments::STAGING_URL; } else { $env = Bancard\Bancard\Core\Environments::PRODUCTION_URL; } $singlebuy = Bancard\Bancard\Operations\SingleBuy\SingleBuy::init($data, $env)->send(); WC()->cart->empty_cart(); return array( 'result' => 'success', 'redirect' => $singlebuy->redirect_to ); } /** * Get gateway icon. * * @access public * @return string */ public function get_icon() { $icon = '
'; return apply_filters('woocommerce_gateway_icon', $icon, $this->id); } /** * Process a refund if supported. * @param int $order_id * @param float $amount * @param string $reason * @return bool True or false based on success, or a WP_Error object */ public function process_refund($order_id, $amount = null, $reason = '') { $order = wc_get_order($order_id); include_once('includes/Bancard/autoload.php'); $data = [ 'shop_process_id' => $order->id, 'private_key' => $this->get_option('api_private_key'), 'public_key' => $this->get_option('api_public_key') ]; if ($this->testmode == 'yes') { $env = Bancard\Bancard\Core\Environments::STAGING_URL; } else { $env = Bancard\Bancard\Core\Environments::PRODUCTION_URL; } try { $rollback = Bancard\Bancard\Operations\SingleBuy\Rollback::init($data, $env)->send(); } catch (Exception $e) { return new WP_Error('error', $e->getMessage()); } $order->add_order_note(__('Refunded amount', 'woocommerce')); return true; } } add_filter('woocommerce_payment_gateways', 'woocommerce_add_bancard_gateway'); function woocommerce_add_bancard_gateway($methods) { $methods[] = 'WC_Gateway_Bancard'; return $methods; } }