PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.6
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.6
6.2.15 6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 All 197 releases
fluentform / app / Modules / Payments / PaymentMethods / Stripe / StripeSettings.php

StripeSettings.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.6, at app/Modules/Payments/PaymentMethods/Stripe/StripeSettings.php

238 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Payments\PaymentMethods\Stripe;
4
5 use FluentForm\Framework\Helpers\ArrayHelper;
6 use FluentForm\App\Modules\Payments\PaymentHelper;
7
8 if (!defined('ABSPATH')) {
9 exit; // Exit if accessed directly.
10 }
11
12 class StripeSettings
13 {
14 public static function getSettings($decrypted = true)
15 {
16 $defaults = [
17 'test_publishable_key' => '',
18 'test_secret_key' => '',
19 'live_publishable_key' => '',
20 'live_secret_key' => '',
21 'payment_mode' => 'test',
22 'is_active' => 'no',
23 'provider' => 'api_keys',
24 'test_account_id' => '',
25 'live_account_id' => '',
26 'is_encrypted' => 'no'
27 ];
28
29 $settings = get_option('fluentform_payment_settings_stripe', []);
30
31 if (!$settings) {
32 $defaults['provider'] = 'connect';
33 }
34
35 $settings = wp_parse_args($settings, $defaults);
36
37 if ($settings['provider'] == 'connect' && apply_filters('fluentform/disable_stripe_connect', false)) {
38 $settings['provider'] = 'api_keys';
39 }
40
41 if ($decrypted) {
42 $settings = self::maybeDecryptKeys($settings);
43 }
44
45 return $settings;
46 }
47
48 public static function updateSettings($data)
49 {
50 $settings = self::getSettings();
51 $settings = wp_parse_args($data, $settings);
52
53 $settings = self::encryptKeys($settings);
54 update_option('fluentform_payment_settings_stripe', $settings);
55 return self::getSettings();
56 }
57
58 public static function encryptKeys($settings)
59 {
60 $settings['live_secret_key'] = PaymentHelper::encryptKey($settings['live_secret_key']);
61 $settings['test_secret_key'] = PaymentHelper::encryptKey($settings['test_secret_key']);
62 $settings['is_encrypted'] = 'yes';
63
64 return $settings;
65 }
66
67 public static function maybeDecryptKeys($settings)
68 {
69 if (ArrayHelper::get($settings, 'is_encrypted') == 'yes') {
70 if (!empty($settings['live_secret_key'])) {
71 $settings['live_secret_key'] = PaymentHelper::decryptKey($settings['live_secret_key']);
72 }
73
74 if (!empty($settings['test_secret_key'])) {
75 $settings['test_secret_key'] = PaymentHelper::decryptKey($settings['test_secret_key']);
76 }
77 } else {
78 $encrypted = self::encryptKeys($settings);
79 update_option('fluentform_payment_settings_stripe', $encrypted);
80 }
81
82 $settings['is_encrypted'] = 'yes';
83
84 return $settings;
85 }
86
87 public static function getSecretKey($formId = false)
88 {
89 if ($formId) {
90 $formPaymentSettings = PaymentHelper::getFormSettings($formId, 'admin');
91 if (ArrayHelper::get($formPaymentSettings, 'stripe_account_type') == 'custom') {
92 return ArrayHelper::get($formPaymentSettings, 'stripe_custom_config.secret_key');
93 }
94 }
95
96 $settings = self::getSettings();
97
98 if ($settings['payment_mode'] == 'live') {
99 return $settings['live_secret_key'];
100 }
101
102 return $settings['test_secret_key'];
103 }
104
105 public static function getPublishableKey($formId = false)
106 {
107 if ($formId) {
108 $formPaymentSettings = PaymentHelper::getFormSettings($formId, 'admin');
109 if (ArrayHelper::get($formPaymentSettings, 'stripe_account_type') == 'custom') {
110 return ArrayHelper::get($formPaymentSettings, 'stripe_custom_config.publishable_key');
111 }
112 }
113
114 $settings = self::getSettings();
115 if ($settings['payment_mode'] == 'live') {
116 return $settings['live_publishable_key'];
117 }
118
119 return $settings['test_publishable_key'];
120 }
121
122 public static function isLive($formId = false)
123 {
124 if ($formId) {
125 $formPaymentSettings = PaymentHelper::getFormSettings($formId, 'admin');
126 if (ArrayHelper::get($formPaymentSettings, 'stripe_account_type') == 'custom') {
127 return ArrayHelper::get($formPaymentSettings, 'stripe_custom_config.payment_mode') == 'live';
128 }
129 }
130
131 $settings = self::getSettings();
132 return $settings['payment_mode'] == 'live';
133 }
134
135 public static function getMode($formId = false)
136 {
137 return static::isLive($formId) ? 'live' : 'test';
138 }
139
140 public static function supportedShippingCountries()
141 {
142 $countries = [
143 'AC', 'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR', 'AT', 'AU', 'AW', 'AX', 'AZ',
144 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS',
145 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO',
146 'CR', 'CV', 'CW', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER',
147 'ES', 'ET', 'FI', 'FJ', 'FK', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GL',
148 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HN', 'HR', 'HT', 'HU', 'ID',
149 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IS', 'IT', 'JE', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI',
150 'KM', 'KN', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV',
151 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MK', 'ML', 'MM', 'MN', 'MO', 'MQ', 'MR', 'MS', 'MT',
152 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU',
153 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PY', 'QA',
154 'RE', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM',
155 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SX', 'SZ', 'TA', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK',
156 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'US', 'UY', 'UZ', 'VA', 'VC',
157 'VE', 'VG', 'VN', 'VU', 'WF', 'WS', 'XK', 'YE', 'YT', 'ZA', 'ZM', 'ZW', 'ZZ'
158 ];
159
160 return apply_filters('fluentform/stripe_supported_shipping_countries', $countries);
161 }
162
163 public static function getClientId($paymentMode = 'live')
164 {
165 if ($paymentMode == 'live') {
166 return 'ca_GwAPNUlKAW6EgeTqERQieU3DXLAX3k7N';
167 } else {
168 return 'ca_GwAPhxHwszjhsFRdC4j5DqKHud7JLQ8C';
169 }
170 }
171
172 public static function guessFormIdFromEvent($event)
173 {
174 $eventType = $event->type;
175
176 $metaDataEvents = [
177 'checkout.session.completed',
178 'charge.refunded',
179 'charge.succeeded'
180 ];
181
182 if (in_array($eventType, $metaDataEvents)) {
183 $data = $event->data->object;
184 $metaData = (array)$data->metadata;
185 return ArrayHelper::get($metaData, 'form_id');
186 }
187
188 return false;
189 }
190
191 public static function getPaymentDescriptor($form)
192 {
193 $title = $form->title;
194 $paymentSettings = PaymentHelper::getFormSettings($form->id, 'admin');
195 if ($providedDescriptor = ArrayHelper::get($paymentSettings, 'stripe_descriptor')) {
196 $title = $providedDescriptor;
197 } else {
198 $globalSettings = PaymentHelper::getPaymentSettings();
199 if (!empty($globalSettings['business_name'])) {
200 $title = $globalSettings['business_name'];
201 }
202 }
203
204 $illegal = array('<', '>', '"', "'");
205 // Remove slashes
206 $descriptor = stripslashes($title);
207 // Remove illegal characters
208 $descriptor = str_replace($illegal, '', $descriptor);
209 // Trim to 22 characters max
210 $descriptor = substr($descriptor, 0, 22);
211
212 if (!$descriptor || strlen($descriptor) < 5) {
213 $descriptor = 'FluentForm';
214 }
215
216 return $descriptor;
217
218 }
219
220 public static function isConnectedAndPlatformCountrySame()
221 {
222 $settings = static::getSettings();
223 return ArrayHelper::get($settings, 'connected_account_country') === ArrayHelper::get($settings, 'platform_account_country');
224 }
225
226 public static function getAccountId()
227 {
228 $settings = self::getSettings();
229 $isLive = self::isLive();
230
231 if ($isLive) {
232 return ArrayHelper::get($settings, 'live_account_id');
233 }
234 return ArrayHelper::get($settings, 'test_account_id');
235 }
236
237 }
238