1. <?php
  2. /*
  3. * Plugin name: Rybishop LiQpay
  4. * Plugin URI: http://rybishop.esy.es
  5. * Description: Плагин для оплаты на моём сайте
  6. */
  7. add_action('plugins_loaded', 'LiqPay_init', 0);
  8. function LiqPay_init(){
  9. if (!class_exists("WC_Payment_Gateway")) {
  10. return;
  11. }
  12. if (class_exists('LiqPay')) {
  13. return;
  14. }
  15. class LiqPay extends WC_Payment_Gateway {
  16. public function __construct() {
  17. global $woocommerce;
  18. $plugin_dir = plugin_dir_url(__FILE__);
  19. $this->id = 'LiqPay';
  20. $this->icon = apply_filters('woocommerce_liqpay_icon', $plugin_dir.'LiqPay.png');
  21. $this->has_fields = false;
  22. $this->action_url = 'https://www.liqpay.com/api/checkout';
  23. $this->init_form_fields();
  24. $this->init_settings();
  25. $this->title = $this->get_option('title');
  26. $this->desription = $this->get_option('description');
  27. $this->public_key = $this->get_option('public_key');
  28. $this->private_key = $this->get_option('private_key');
  29. $this->debug = $this->get_option('debug');
  30. if ($this->debug == 'yes') {
  31. $this->log == $woocommerce->logger();
  32. }
  33. add_action('woocommerce_receipt_'.$this->id, array($this, 'receipt_page'));
  34. add_action('woocommerce_api_wc_'.$this->id, array($this, 'check_ipn_response'));
  35. add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this, 'process_admin_options'));
  36. }
  37. public function admin_options() {
  38. _e('<b>LiqPay</b>', 'woocommerce');
  39. _e(' for Rybishop<br>', 'woocommerce');
  40. $this->generate_settings_html();
  41. }
  42. public function init_form_fields() {
  43. $this->form_fields = array(
  44. 'enabled' => array( 'title' => __('Включить/Выключить', 'woocommerce')
  45. , 'type' => 'checkbox'
  46. , 'label' => __('Включен', 'woocommerce')
  47. , 'default' => 'yes')
  48. , 'title' => array( 'title' => __('LiqPay', 'woocommerce')
  49. , 'type' => 'text'
  50. , 'desription' => __('', 'woocommerce')
  51. , 'default' => __('LiqPay', 'woocommerce')
  52. , 'desc_tip' => true)
  53. , 'description' => array( 'title' => __('Description', 'woocommerce')
  54. , 'type' => 'textarea'
  55. , 'desription' => __('Payment method')
  56. , 'default' => 'Оплата с помощью liqpay')
  57. , 'instructions' => array( 'title' => __('Instructions', 'woocommerce')
  58. , 'type' => 'textarea'
  59. , 'desription' => __('Payment method')
  60. , 'default' => 'Оплата с помощью liqpay')
  61. , 'public_key' => array( 'title' => __('Public key', 'woocommerce')
  62. , 'type' => 'text'
  63. , 'description' => 'Введите публичный ключ вашего магазина'
  64. , 'default' => '')
  65. , 'private_key' => array( 'title' => __('Private key', 'woocommerce')
  66. , 'type' => 'text'
  67. , 'description' => 'Введите приватный ключ вашего магазина'
  68. , 'default' => ''));
  69. }
  70. public function process_payment($order_id) {
  71. global $woocommerce;
  72. $order = new WC_Order($order_id);
  73. $order->update_status('on-hold', __('Ждём LiqPay оплаты', 'woocommerce'));
  74. $order->reduce_order_stock();
  75. $woocommerce->cart->empty_cart();
  76. return array('result' => 'success', 'redirect' => $this->get_return_url($order));
  77. }
  78. public function generate_form($order_id) {
  79. global $woocommerce;
  80. $order = new WC_Order($order_id);
  81. $data = base64_encode();
  82. $signature = base64_encode(sha1($this->private_key.$data.$this->private_key));
  83. $form = '<form action = "$action_url" method = "POST">
  84. <input type = "hidden" name = "data" value = "">
  85. <input type = "hidden" name = "signature" value = "">
  86. <input type = "submit" value = "Оплатить">
  87. </form>';
  88. return $form;
  89. }
  90. public function receipt_page($order) {
  91. echo '<p>'.__('Спасибо за Ваш заказ, пожалуйста, нажмите кнопку ниже, чтобы заплатить.'.$order, 'woocommerce').'</p>';
  92. echo $this->generate_form($order);
  93. }
  94. public function check_ipn_response() {
  95. }
  96. }
  97. function add_liqpay_gateway($methods) {
  98. $methods[] = 'LiqPay';
  99. return $methods;
  100. }
  101. add_filter('woocommerce_payment_gateways', 'add_liqpay_gateway');
  102. }
  103. ?>