- <?php
- /*
- * Plugin name: Rybishop LiQpay
- * Plugin URI: http://rybishop.esy.es
- * Description: Плагин для оплаты на моём сайте
- */
- add_action('plugins_loaded', 'LiqPay_init', 0);
- function LiqPay_init(){
- if (!class_exists("WC_Payment_Gateway")) {
- return;
- }
- if (class_exists('LiqPay')) {
- return;
- }
- class LiqPay extends WC_Payment_Gateway {
- public function __construct() {
- global $woocommerce;
- $plugin_dir = plugin_dir_url(__FILE__);
- $this->id = 'LiqPay';
- $this->icon = apply_filters('woocommerce_liqpay_icon', $plugin_dir.'LiqPay.png');
- $this->has_fields = false;
- $this->action_url = 'https://www.liqpay.com/api/checkout';
- $this->init_form_fields();
- $this->init_settings();
- $this->title = $this->get_option('title');
- $this->desription = $this->get_option('description');
- $this->public_key = $this->get_option('public_key');
- $this->private_key = $this->get_option('private_key');
- $this->debug = $this->get_option('debug');
- if ($this->debug == 'yes') {
- $this->log == $woocommerce->logger();
- }
- add_action('woocommerce_receipt_'.$this->id, array($this, 'receipt_page'));
- add_action('woocommerce_api_wc_'.$this->id, array($this, 'check_ipn_response'));
- add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this, 'process_admin_options'));
- }
- public function admin_options() {
- _e('<b>LiqPay</b>', 'woocommerce');
- _e(' for Rybishop<br>', 'woocommerce');
- $this->generate_settings_html();
- }
- public function init_form_fields() {
- $this->form_fields = array(
- 'enabled' => array( 'title' => __('Включить/Выключить', 'woocommerce')
- , 'type' => 'checkbox'
- , 'label' => __('Включен', 'woocommerce')
- , 'default' => 'yes')
- , 'title' => array( 'title' => __('LiqPay', 'woocommerce')
- , 'type' => 'text'
- , 'desription' => __('', 'woocommerce')
- , 'default' => __('LiqPay', 'woocommerce')
- , 'desc_tip' => true)
- , 'description' => array( 'title' => __('Description', 'woocommerce')
- , 'type' => 'textarea'
- , 'desription' => __('Payment method')
- , 'default' => 'Оплата с помощью liqpay')
- , 'instructions' => array( 'title' => __('Instructions', 'woocommerce')
- , 'type' => 'textarea'
- , 'desription' => __('Payment method')
- , 'default' => 'Оплата с помощью liqpay')
- , 'public_key' => array( 'title' => __('Public key', 'woocommerce')
- , 'type' => 'text'
- , 'description' => 'Введите публичный ключ вашего магазина'
- , 'default' => '')
- , 'private_key' => array( 'title' => __('Private key', 'woocommerce')
- , 'type' => 'text'
- , 'description' => 'Введите приватный ключ вашего магазина'
- , 'default' => ''));
- }
- public function process_payment($order_id) {
- global $woocommerce;
- $order = new WC_Order($order_id);
- $order->update_status('on-hold', __('Ждём LiqPay оплаты', 'woocommerce'));
- $order->reduce_order_stock();
- $woocommerce->cart->empty_cart();
- return array('result' => 'success', 'redirect' => $this->get_return_url($order));
- }
- public function generate_form($order_id) {
- global $woocommerce;
- $order = new WC_Order($order_id);
- $data = base64_encode();
- $signature = base64_encode(sha1($this->private_key.$data.$this->private_key));
- $form = '<form action = "$action_url" method = "POST">
- <input type = "hidden" name = "data" value = "">
- <input type = "hidden" name = "signature" value = "">
- <input type = "submit" value = "Оплатить">
- </form>';
- return $form;
- }
- public function receipt_page($order) {
- echo '<p>'.__('Спасибо за Ваш заказ, пожалуйста, нажмите кнопку ниже, чтобы заплатить.'.$order, 'woocommerce').'</p>';
- echo $this->generate_form($order);
- }
- public function check_ipn_response() {
- }
- }
- function add_liqpay_gateway($methods) {
- $methods[] = 'LiqPay';
- return $methods;
- }
- add_filter('woocommerce_payment_gateways', 'add_liqpay_gateway');
- }
- ?>