PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.2
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.2
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Modules / PaymentMethods / StripeGateway / StripeSettingsBase.php

StripeSettingsBase.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.5.2, at app/Modules/PaymentMethods/StripeGateway/StripeSettingsBase.php

139 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Modules\PaymentMethods\StripeGateway;
4
5 use FluentCart\Api\StoreSettings;
6 use FluentCart\App\Helpers\Helper;
7 use FluentCart\App\Modules\PaymentMethods\Core\BaseGatewaySettings;
8
9 class StripeSettingsBase extends BaseGatewaySettings
10 {
11
12 public $settings;
13
14 public $methodHandler = 'fluent_cart_payment_settings_stripe';
15
16 public function __construct()
17 {
18 parent::__construct();
19 $settings = $this->getCachedSettings();
20 $defaults = static::getDefaults();
21
22 if (!$settings || !is_array($settings) || empty($settings)) {
23 $settings = $defaults;
24 } else {
25 $settings = wp_parse_args($settings, $defaults);
26 }
27
28 //define key's handle
29 $isTestDefined = defined('FCT_STRIPE_TEST_PUBLIC_KEY') && defined('FCT_STRIPE_TEST_SECRET_KEY');
30 $isLiveDefined = defined('FCT_STRIPE_LIVE_PUBLIC_KEY') && defined('FCT_STRIPE_LIVE_SECRET_KEY');
31 if ($isTestDefined || $isLiveDefined) {
32 $settings['define_test_keys'] = $isTestDefined;
33 $settings['define_live_keys'] = $isLiveDefined;
34 $settings['provider'] = 'api_keys';
35 }
36
37
38 $this->settings = apply_filters('fluent_cart/stripe_settings', $settings);
39 }
40
41 /**
42 * @return array with default fields value
43 */
44 public static function getDefaults()
45 {
46 return [
47 'is_active' => 'no',
48 'provider' => 'connect',
49 //define keys
50 'define_test_keys' => false,
51 'define_live_keys' => false,
52 // test keys
53 'test_publishable_key' => '',
54 'test_secret_key' => '',
55 'test_webhook_secret' => '',
56 // Live keys
57 'live_publishable_key' => '',
58 'live_secret_key' => '',
59 'live_webhook_secret' => '',
60 // Others
61 'payment_mode' => 'live',
62 'checkout_mode' => 'onsite',
63 'live_is_encrypted' => 'no',
64 'test_is_encrypted' => 'no',
65 'secure' => 'yes'
66 ];
67 }
68
69 public function isActive(): bool
70 {
71 return $this->settings['is_active'] == 'yes';
72 }
73
74 public function get($key = '')
75 {
76 $settings = $this->settings;
77
78 if ($key && isset($this->settings[$key])) {
79 return $this->settings[$key];
80 }
81 return $settings;
82 }
83
84 public function updateSettings($settings)
85 {
86 $defaults = static::getDefaults();
87 $settings = wp_parse_args($settings, $defaults);
88
89 if (defined('FCT_STRIPE_LIVE_PUBLIC_KEY')) {
90 $settings['live_publishable_key'] = '';
91 }
92
93 if (defined('FCT_STRIPE_TEST_PUBLIC_KEY')) {
94 $settings['test_publishable_key'] = '';
95 }
96
97 if (defined('FCT_STRIPE_LIVE_SECRET_KEY')) {
98 $settings['live_secret_key'] = '';
99 }
100
101 if (defined('FCT_STRIPE_TEST_SECRET_KEY')) {
102 $settings['test_secret_key'] = '';
103 }
104
105 fluent_cart_update_option($this->methodHandler, $settings);
106
107 return $settings;
108 }
109
110 public function getMode()
111 {
112 // return store mode
113 return (new StoreSettings)->get('order_mode');
114 }
115
116 public function getPublicKey()
117 {
118 if ($this->getMode() === 'test') {
119 return defined('FCT_STRIPE_TEST_PUBLIC_KEY') ? FCT_STRIPE_TEST_PUBLIC_KEY : $this->get()['test_publishable_key'] . '';
120 }
121
122 return defined('FCT_STRIPE_LIVE_PUBLIC_KEY') ? FCT_STRIPE_LIVE_PUBLIC_KEY : $this->get()['live_publishable_key'] . '';
123 }
124
125 public function getApiKey($mode = 'current')
126 {
127 if ($mode == 'current' || !$mode) {
128 $mode = $this->getMode();
129 }
130
131 if ($mode === 'test') {
132 return defined('FCT_STRIPE_TEST_SECRET_KEY') ? FCT_STRIPE_TEST_SECRET_KEY : Helper::decryptKey($this->get()['test_secret_key']) . '';
133 }
134
135 return defined('FCT_STRIPE_LIVE_SECRET_KEY') ? FCT_STRIPE_LIVE_SECRET_KEY : Helper::decryptKey($this->get()['live_secret_key']) . '';
136 }
137
138 }
139