PluginProbe
DOKU Payment / trunk
DOKU Payment vtrunk
1.3.30 trunk 1.3.17 1.3.18 1.3.19 1.3.20 1.3.21 1.3.22 1.3.23 1.3.24 1.3.25 1.3.26 1.3.27 1.3.28 1.3.29
doku-payment / Module / JokulMainModule.php

JokulMainModule.php in DOKU Payment trunk, at Module/JokulMainModule.php

123 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 class DokuMainModule extends WC_Payment_Gateway
6 {
7 public $method_name;
8 public $environmentPaymentJokul;
9 public $sandboxClientId;
10 public $sandboxSharedKey;
11 public $prodClientId;
12 public $prodSharedKey;
13 public $expiredTime;
14 public $notifUrl;
15 public $emailNotifications;
16 public $abandonedCart;
17 public $timeRangeAbandonedCart;
18 public $customExpireDate;
19
20 public function __construct()
21 {
22
23 $this->init_form_fields();
24 $this->id = 'doku_gateway';
25 $this->has_fields = true;
26 $this->method_name = 'General Configuration';
27 $this->title = !empty($this->get_option('channel_name')) ? $this->get_option('channel_name') : $this->method_name;
28 $this->method_title = __('DOKU Integration', 'doku-payment');
29 $this->method_description = sprintf(__('Configure your DOKU connection details such as environment, credentials, notification URL, and payment expiry time.', 'doku-payment'));
30
31 $this->init_settings();
32 $this->enabled = $this->get_option('enabled');
33 $this->environmentPaymentJokul = $this->get_option('environment_payment_jokul');
34 $this->sandboxClientId = $this->get_option('sandbox_client_id');
35 $this->sandboxSharedKey = $this->get_option('sandbox_shared_key');
36 $this->prodClientId = $this->get_option('prod_client_id');
37 $this->prodSharedKey = $this->get_option('prod_shared_key');
38 $this->expiredTime = $this->get_option('expired_time');
39 $this->notifUrl = $this->get_option('notif_url');
40 $this->emailNotifications = $this->get_option('email_notifications');
41 $this->abandonedCart = $this->get_option('abandoned_cart');
42 $this->timeRangeAbandonedCart = $this->get_option('time_range_abandoned_cart');
43 $this->customExpireDate = $this->get_option('custom_time_range_abandoned_cart');
44
45 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
46 add_filter('woocommerce_available_payment_gateways', array(&$this, 'check_gateway_status'));
47 }
48
49 public function init_form_fields()
50 {
51 $this->form_fields = require(DOKU_PAYMENT_PLUGIN_PATH . '/Form/JokulPgSetting.php');
52 }
53
54 public function process_admin_options()
55 {
56 $this->init_settings();
57
58 $post_data = $this->get_post_data();
59
60 $abandoned_cart = isset($post_data['woocommerce_' . $this->id . '_abandoned_cart']) ? $post_data['woocommerce_' . $this->id . '_abandoned_cart'] : 'no';
61 $time_range = isset($post_data['woocommerce_' . $this->id . '_time_range_abandoned_cart']) ? $post_data['woocommerce_' . $this->id . '_time_range_abandoned_cart'] : '';
62 $custom_range = isset($post_data['woocommerce_' . $this->id . '_custom_time_range_abandoned_cart']) ? trim($post_data['woocommerce_' . $this->id . '_custom_time_range_abandoned_cart']) : '';
63
64 if ($abandoned_cart === 'yes' && $time_range === 'Custom') {
65 if ($custom_range === '' || !is_numeric($custom_range) || intval($custom_range) < 1 || intval($custom_range) > 30) {
66 \WC_Admin_Settings::add_error(__('Custom Expiry for Abandoned Checkout must be a numeric value between 1 and 30 days.', 'doku-payment'));
67 return false;
68 }
69 }
70
71 foreach ($this->get_form_fields() as $key => $field) {
72 if ('title' !== $this->get_field_type($field)) {
73 try {
74 if ('expired_time' == $key && $post_data['woocommerce_' . $this->id . '_expired_time'] == null) {
75 $this->settings[$key] = $this->get_field_default($field);
76 } else {
77 $this->settings[$key] = $this->get_field_value($key, $field, $post_data);
78 }
79 } catch (Exception $e) {
80 $this->add_error($e->getMessage());
81 }
82 }
83 }
84
85 if (!isset($post_data['woocommerce_' . $this->id . '_enabled']) && $this->get_option_key() == 'woocommerce_' . $this->id . '_settings') {
86 $this->settings['enabled'] = $this->enabled;
87 }
88
89 if (isset($post_data['woocommerce_' . $this->id . '_secret_key']) || isset($post_data['woocommerce_' . $this->id . '_secret_key_dev'])) {
90 delete_transient('main_settings_jokul_pg');
91 }
92 // woocommerce_settings_api_sanitized_fields_ is a WooCommerce core hook, do not modify its name
93 // This hook name is not created or defined by this plugin and cant be modified.
94 return update_option($this->get_option_key(), apply_filters('woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings), 'yes');
95 }
96
97 public function check_gateway_status($gateways)
98 {
99 if ($this->id == 'doku_gateway') {
100 unset($gateways[$this->id]);
101 return $gateways;
102 }
103 }
104
105 public function admin_options()
106 {
107 parent::admin_options();
108
109 wp_enqueue_script(
110 'admin-options-script',
111 plugin_dir_url(__FILE__) . '../Js/admin-options.js',
112 ['jquery'],
113 '1.0.0',
114 true
115 );
116
117 wp_localize_script('admin-options-script', 'woocommerceData', [
118 'id' => $this->id,
119 ]);
120 }
121
122 }
123