芝麻web文件管理V1.00
编辑当前文件:/home4/randall/public_html/sl/wp-content/plugins/elegro-payment/elegro-payment.php
id = 'elegro'; $this->has_fields = false; $this->method_title = 'elegro Crypto Payment'; $this->method_description = 'elegro Crypto Payment'; $this->icon = apply_filters('woocommerce_elegro_icon', 'https://elegro-public.s3.eu-central-1.amazonaws.com/elegro_email_logo.png'); $this->init_form_fields(); $this->init_settings(); // Load settings $this->enabled = $this->get_option( 'enabled' ); $this->title = $this->get_option( 'title' ); $this->description = $this->get_option( 'description' ); $this->public_api_key = $this->get_option( 'public_api_key' ); $this->private_api_key = $this->get_option( 'private_api_key' ); // Actions add_action('woocommerce_receipt_'. $this->id, array( $this, 'receipt_page' ) ); add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); add_action('woocommerce_api_wc_elegro_payment', array($this, 'check_ipn_response')); } public function init_form_fields(){ $this->form_fields = array( 'enabled' => array( 'title' => 'On/Off', 'type' => 'checkbox', 'label' => 'On/Off plugin', 'default' => 'yes' ), 'title' => array( 'title' => 'Title', 'type' => 'text', 'description' => 'The title that appears on the checkout page', 'default' => 'elegro Crypto Payment', 'desc_tip' => true, ), 'description' => array( 'title' => 'Description', 'type' => 'textarea', 'description' => 'The description that appears during the payment method selection process', 'default' => 'Pay through the elegro Crypto Payment', ), 'listen_url' => array( 'title' => 'Response server URL', 'type' => 'text', 'description' => 'Copy this url to "Processing Listen URL" field on
dashboard.acceptance.elegro.eu
', 'default' => get_site_url() . '/wc-api/wc_elegro_payment/' ), 'public_api_key' => array( 'title' => 'Public API Key', 'type' => 'text', 'description' => 'Public API Key in elegro system.', 'default' => '', ), 'private_api_key' => array( 'title' => 'Secret API Key', 'type' => 'text', 'description' => 'Secret API Key in elegro system.', 'default' => '', ) ); return true; } function process_payment($order_id) { $order = new WC_Order($order_id); return array( 'result' => 'success', 'redirect' => add_query_arg('order', $order_id, add_query_arg('key', $order->get_order_key(), get_permalink(wc_get_page_id('pay')))) ); } public function receipt_page($order) { echo '
Thank you for your order, please click the button below to pay.
'; echo $this->generate_form($order); } public function generate_form($order_id) { $order = new WC_Order( $order_id ); global $woocommerce; // Mark as on-hold (we're awaiting the payment) $order->update_status('on-hold', 'Awaiting payment response'); // Remove cart $woocommerce->cart->empty_cart(); // Prepare payment request`s data $args = array( 'amount' => $order->get_total(), 'currency' => get_woocommerce_currency(), 'public_api_key' => $this->public_api_key, 'order' => $order_id, 'pay_way' => 'elegro Crypto Payment' ); $orderReceivedPage = get_option("woocommerce_checkout_order_received_endpoint"); return '
' . '
' . '
Buy
' . ''; } /** * When we have a payment`s response */ function check_ipn_response(){ $requestHeaders = getallheaders(); if (!isset($requestHeaders[AUTHHEADER])) { wp_die( 'Access denied!'); } // Get the Private api key from db $private_api_key_client = $this->get_option('private_api_key'); if ($private_api_key_client !== $requestHeaders[AUTHHEADER]) { wp_die( 'Access denied!'); } // Get orderId and order status $request = json_decode(file_get_contents('php://input'), true); $response_order_id = $request['orderId'] ? (int)$request['orderId'] : ''; $response_order_status = $request['status'] ? ($request['status'] === 'success' ? 'processing' : 'cancelled') : ''; $response_order_amount = $request['amount'] ? $request['amount'] : ''; if ($response_order_status !== '' && $response_order_amount !== '') { $order = new WC_Order($response_order_id); if (floatval($order->get_total()) === $response_order_amount) { $order->update_status($response_order_status); $order->add_order_note( 'Order status: ' . $response_order_status ); $response = array('status' => $response_order_status === 'processing' ? 'success' : 'failed'); } else { $order->update_status('failed'); $order->add_order_note( 'Order status: failed. Insufficient funds.' ); $response = array('status' => 'failed', 'reason' => 'insufficient_funds'); } die(json_encode($response)); } else { wp_die('IPN request failed!'); } } } } add_filter( 'woocommerce_payment_gateways', 'add_WC_Elegro_Payment_Gateway' ); function add_WC_Elegro_Payment_Gateway( $methods ){ $methods[] = 'WC_Elegro_Payment'; return $methods; } ?>