Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/fluentformpro/src/Payments/PaymentHelper.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
namespace FluentFormPro\Payments;
4
+
5
+
if (!defined('ABSPATH')) {
6
+
exit; // Exit if accessed directly.
7
+
}
8
+
9
+
use FluentForm\App\Helpers\Helper;
10
+
use FluentForm\App\Modules\Form\FormFieldsParser;
11
+
use FluentForm\App\Services\FormBuilder\ShortCodeParser;
12
+
use FluentForm\Framework\Helpers\ArrayHelper;
13
+
use FluentForm\App\Services\Form\SubmissionHandlerService;
14
+
use FluentFormPro\Payments\PaymentMethods\Square\SquareSettings;
15
+
16
+
class PaymentHelper
17
+
{
18
+
public static function isPaymentCompatible()
19
+
{
20
+
return version_compare(FLUENTFORM_VERSION, FLUENTFORM_MINIMUM_CORE_VERSION, '>=');
21
+
}
22
+
23
+
public static function isPaymentScriptLoadFromFree()
24
+
{
25
+
return version_compare(FLUENTFORM_VERSION, '6.0.4', '>=');
26
+
}
27
+
28
+
public static function getFormCurrency($formId)
29
+
{
30
+
$settings = self::getFormSettings($formId, 'public');
31
+
return $settings['currency'];
32
+
}
33
+
34
+
public static function formatMoney($amountInCents, $currency)
35
+
{
36
+
$currencySettings = self::getCurrencyConfig(false, $currency);
37
+
$symbol = \html_entity_decode($currencySettings['currency_sign']);
38
+
$position = $currencySettings['currency_sign_position'];
39
+
$decimalSeparator = '.';
40
+
$thousandSeparator = ',';
41
+
if ($currencySettings['currency_separator'] != 'dot_comma') {
42
+
$decimalSeparator = ',';
43
+
$thousandSeparator = '.';
44
+
}
45
+
$decimalPoints = 2;
46
+
if ((int) round($amountInCents) % 100 == 0 && $currencySettings['decimal_points'] == 0) {
47
+
$decimalPoints = 0;
48
+
}
49
+
50
+
$amount = number_format($amountInCents / 100, $decimalPoints, $decimalSeparator, $thousandSeparator);
51
+
52
+
if ('left' === $position) {
53
+
return $symbol . $amount;
54
+
} elseif ('left_space' === $position) {
55
+
return $symbol . ' ' . $amount;
56
+
} elseif ('right' === $position) {
57
+
return $amount . $symbol;
58
+
} elseif ('right_space' === $position) {
59
+
return $amount . ' ' . $symbol;
60
+
}
61
+
return $amount;
62
+
}
63
+
64
+
public static function getFormSettings($formId, $scope = 'public')
65
+
{
66
+
static $cachedSettings = [];
67
+
68
+
if (isset($cachedSettings[$scope . '_' . $formId])) {
69
+
return $cachedSettings[$scope . '_' . $formId];
70
+
}
71
+
72
+
73
+
$defaults = [
74
+
'currency' => '',
75
+
'push_meta_to_stripe' => 'no',
76
+
'receipt_email' => self::getFormInput($formId,'input_email'),
77
+
'customer_name' => self::getFormInput($formId,'input_name'),
78
+
'customer_address' => self::getFormInput($formId,'address'),
79
+
'transaction_type' => 'product',
80
+
'stripe_checkout_methods' => ['card'],
81
+
'stripe_meta_data' => [
82
+
[
83
+
'item_value' => '',
84
+
'label' => ''
85
+
]
86
+
],
87
+
'stripe_account_type' => 'global',
88
+
'disable_stripe_payment_receipt' => 'no',
89
+
'stripe_custom_config' => [
90
+
'payment_mode' => 'live',
91
+
'publishable_key' => '',
92
+
'secret_key' => ''
93
+
],
94
+
'custom_paypal_id' => '',
95
+
'custom_paypal_mode' => 'live',
96
+
'paypal_account_type' => 'global'
97
+
];
98
+
$settings = Helper::getFormMeta($formId, '_payment_settings', []);
99
+
$settings = wp_parse_args($settings, $defaults);
100
+
if (empty($settings['receipt_email'])) {
101
+
$settings['receipt_email'] = self::getFormInput($formId, 'input_email');
102
+
}
103
+
if (empty($settings['customer_name'])) {
104
+
$name = self::getFormInput($formId, 'input_name');
105
+
if (!empty($name)) {
106
+
$settings['customer_name'] = sprintf('{inputs.%s}', $name);
107
+
}
108
+
}
109
+
if (empty($settings['customer_address'])) {
110
+
$settings['customer_address'] = self::getFormInput($formId, 'address');
111
+
}
112
+
113
+
$globalSettings = self::getPaymentSettings();
114
+
115
+
if (!$settings['currency']) {
116
+
$settings['currency'] = $globalSettings['currency'];
117
+
}
118
+
119
+
if ($scope == 'public') {
120
+
$settings = wp_parse_args($settings, $globalSettings);
121
+
}
122
+
123
+
124
+
$cachedSettings[$scope . '_' . $formId] = $settings;
125
+
126
+
return $settings;
127
+
128
+
}
129
+
130
+
public static function getCurrencyConfig($formId = false, $currency = false)
131
+
{
132
+
if ($formId) {
133
+
$settings = self::getFormSettings($formId, 'public');
134
+
} else {
135
+
$settings = self::getPaymentSettings();
136
+
}
137
+
138
+
if ($currency) {
139
+
$settings['currency'] = $currency;
140
+
}
141
+
142
+
$settings = ArrayHelper::only($settings, ['currency', 'currency_sign_position', 'currency_separator', 'decimal_points']);
143
+
144
+
$settings['currency_sign'] = self::getCurrencySymbol($settings['currency']);
145
+
return $settings;
146
+
}
147
+
148
+
public static function getPaymentSettings()
149
+
{
150
+
static $paymentSettings;
151
+
if ($paymentSettings) {
152
+
return $paymentSettings;
153
+
}
154
+
155
+
$paymentSettings = get_option('__fluentform_payment_module_settings');
156
+
$defaults = [
157
+
'status' => 'no',
158
+
'currency' => 'USD',
159
+
'currency_sign_position' => 'left',
160
+
'currency_separator' => 'dot_comma',
161
+
'decimal_points' => "2",
162
+
'business_name' => '',
163
+
'business_logo' => '',
164
+
'business_address' => '',
165
+
'debug_log' => 'no',
166
+
'all_payments_page_id' => '',
167
+
'receipt_page_id' => '',
168
+
'user_can_manage_subscription' => 'yes'
169
+
];
170
+
171
+
$paymentSettings = wp_parse_args($paymentSettings, $defaults);
172
+
173
+
return $paymentSettings;
174
+
}
175
+
176
+
public static function updatePaymentSettings($data)
177
+
{
178
+
$existingSettings = self::getPaymentSettings();
179
+
$settings = wp_parse_args($data, $existingSettings);
180
+
update_option('__fluentform_payment_module_settings', $settings, 'yes');
181
+
182
+
return self::getPaymentSettings();
183
+
}
184
+
185
+
/**
186
+
* https://support.stripe.com/questions/which-currencies-does-stripe-support
187
+
*/
188
+
public static function getCurrencies()
189
+
{
190
+
$currencies = [
191
+
'AED' => __('United Arab Emirates Dirham', 'fluentformpro'),
192
+
'AFN' => __('Afghan Afghani', 'fluentformpro'),
193
+
'ALL' => __('Albanian Lek', 'fluentformpro'),
194
+
'AMD' => __('Armenian Dram', 'fluentformpro'),
195
+
'ANG' => __('Netherlands Antillean Gulden', 'fluentformpro'),
196
+
'AOA' => __('Angolan Kwanza', 'fluentformpro'),
197
+
'ARS' => __('Argentine Peso','fluentformpro'), // non amex
198
+
'AUD' => __('Australian Dollar', 'fluentformpro'),
199
+
'AWG' => __('Aruban Florin', 'fluentformpro'),
200
+
'AZN' => __('Azerbaijani Manat', 'fluentformpro'),
201
+
'BAM' => __('Bosnia & Herzegovina Convertible Mark', 'fluentformpro'),
202
+
'BBD' => __('Barbadian Dollar', 'fluentformpro'),
203
+
'BDT' => __('Bangladeshi Taka', 'fluentformpro'),
204
+
'BIF' => __('Burundian Franc', 'fluentformpro'),
205
+
'BGN' => __('Bulgarian Lev', 'fluentformpro'),
206
+
'BMD' => __('Bermudian Dollar', 'fluentformpro'),
207
+
'BND' => __('Brunei Dollar', 'fluentformpro'),
208
+
'BOB' => __('Bolivian Boliviano', 'fluentformpro'),
209
+
'BRL' => __('Brazilian Real', 'fluentformpro'),
210
+
'BSD' => __('Bahamian Dollar', 'fluentformpro'),
211
+
'BWP' => __('Botswana Pula', 'fluentformpro'),
212
+
'BZD' => __('Belize Dollar', 'fluentformpro'),
213
+
'CAD' => __('Canadian Dollar', 'fluentformpro'),
214
+
'CDF' => __('Congolese Franc', 'fluentformpro'),
215
+
'CHF' => __('Swiss Franc', 'fluentformpro'),
216
+
'CLP' => __('Chilean Peso', 'fluentformpro'),
217
+
'CNY' => __('Chinese Renminbi Yuan', 'fluentformpro'),
218
+
'COP' => __('Colombian Peso', 'fluentformpro'),
219
+
'CRC' => __('Costa Rican Colón', 'fluentformpro'),
220
+
'CVE' => __('Cape Verdean Escudo', 'fluentformpro'),
221
+
'CZK' => __('Czech Koruna', 'fluentformpro'),
222
+
'DJF' => __('Djiboutian Franc', 'fluentformpro'),
223
+
'DKK' => __('Danish Krone', 'fluentformpro'),
224
+
'DOP' => __('Dominican Peso', 'fluentformpro'),
225
+
'DZD' => __('Algerian Dinar', 'fluentformpro'),
226
+
'EGP' => __('Egyptian Pound', 'fluentformpro'),
227
+
'ETB' => __('Ethiopian Birr', 'fluentformpro'),
228
+
'EUR' => __('Euro', 'fluentformpro'),
229
+
'FJD' => __('Fijian Dollar', 'fluentformpro'),
230
+
'FKP' => __('Falkland Islands Pound', 'fluentformpro'),
231
+
'GBP' => __('British Pound', 'fluentformpro'),
232
+
'GEL' => __('Georgian Lari', 'fluentformpro'),
233
+
'GHS' => __('Ghanaian Cedi', 'fluentformpro'),
234
+
'GIP' => __('Gibraltar Pound', 'fluentformpro'),
235
+
'GMD' => __('Gambian Dalasi', 'fluentformpro'),
236
+
'GNF' => __('Guinean Franc', 'fluentformpro'),
237
+
'GTQ' => __('Guatemalan Quetzal', 'fluentformpro'),
238
+
'GYD' => __('Guyanese Dollar', 'fluentformpro'),
239
+
'HKD' => __('Hong Kong Dollar', 'fluentformpro'),
240
+
'HNL' => __('Honduran Lempira', 'fluentformpro'),
241
+
'HRK' => __('Croatian Kuna', 'fluentformpro'),
242
+
'HTG' => __('Haitian Gourde', 'fluentformpro'),
243
+
'HUF' => __('Hungarian Forint', 'fluentformpro'),
244
+
'IDR' => __('Indonesian Rupiah', 'fluentformpro'),
245
+
'ILS' => __('Israeli New Sheqel', 'fluentformpro'),
246
+
'INR' => __('Indian Rupee', 'fluentformpro'),
247
+
'ISK' => __('Icelandic Króna', 'fluentformpro'),
248
+
'JMD' => __('Jamaican Dollar', 'fluentformpro'),
249
+
'JPY' => __('Japanese Yen', 'fluentformpro'),
250
+
'KES' => __('Kenyan Shilling', 'fluentformpro'),
251
+
'KGS' => __('Kyrgyzstani Som', 'fluentformpro'),
252
+
'KHR' => __('Cambodian Riel', 'fluentformpro'),
253
+
'KMF' => __('Comorian Franc', 'fluentformpro'),
254
+
'KRW' => __('South Korean Won', 'fluentformpro'),
255
+
'KYD' => __('Cayman Islands Dollar', 'fluentformpro'),
256
+
'KZT' => __('Kazakhstani Tenge', 'fluentformpro'),
257
+
'LAK' => __('Lao Kip', 'fluentformpro'),
258
+
'LBP' => __('Lebanese Pound', 'fluentformpro'),
259
+
'LKR' => __('Sri Lankan Rupee', 'fluentformpro'),
260
+
'LRD' => __('Liberian Dollar', 'fluentformpro'),
261
+
'LSL' => __('Lesotho Loti', 'fluentformpro'),
262
+
'MAD' => __('Moroccan Dirham', 'fluentformpro'),
263
+
'MDL' => __('Moldovan Leu', 'fluentformpro'),
264
+
'MGA' => __('Malagasy Ariary', 'fluentformpro'),
265
+
'MKD' => __('Macedonian Denar', 'fluentformpro'),
266
+
'MNT' => __('Mongolian Tögrög', 'fluentformpro'),
267
+
'MOP' => __('Macanese Pataca', 'fluentformpro'),
268
+
'MRO' => __('Mauritanian Ouguiya', 'fluentformpro'),
269
+
'MUR' => __('Mauritian Rupee', 'fluentformpro'),
270
+
'MVR' => __('Maldivian Rufiyaa', 'fluentformpro'),
271
+
'MWK' => __('Malawian Kwacha', 'fluentformpro'),
272
+
'MXN' => __('Mexican Peso', 'fluentformpro'),
273
+
'MYR' => __('Malaysian Ringgit', 'fluentformpro'),
274
+
'MZN' => __('Mozambican Metical', 'fluentformpro'),
275
+
'NAD' => __('Namibian Dollar', 'fluentformpro'),
276
+
'NGN' => __('Nigerian Naira', 'fluentformpro'),
277
+
'NIO' => __('Nicaraguan Córdoba', 'fluentformpro'),
278
+
'NOK' => __('Norwegian Krone', 'fluentformpro'),
279
+
'NPR' => __('Nepalese Rupee', 'fluentformpro'),
280
+
'NZD' => __('New Zealand Dollar', 'fluentformpro'),
281
+
'PAB' => __('Panamanian Balboa', 'fluentformpro'),
282
+
'PEN' => __('Peruvian Nuevo Sol', 'fluentformpro'),
283
+
'PGK' => __('Papua New Guinean Kina', 'fluentformpro'),
284
+
'PHP' => __('Philippine Peso', 'fluentformpro'),
285
+
'PKR' => __('Pakistani Rupee', 'fluentformpro'),
286
+
'PLN' => __('Polish Złoty', 'fluentformpro'),
287
+
'PYG' => __('Paraguayan Guaraní', 'fluentformpro'),
288
+
'QAR' => __('Qatari Riyal', 'fluentformpro'),
289
+
'RON' => __('Romanian Leu', 'fluentformpro'),
290
+
'RSD' => __('Serbian Dinar', 'fluentformpro'),
291
+
'RUB' => __('Russian Ruble', 'fluentformpro'),
292
+
'RWF' => __('Rwandan Franc', 'fluentformpro'),
293
+
'SAR' => __('Saudi Riyal', 'fluentformpro'),
294
+
'SBD' => __('Solomon Islands Dollar', 'fluentformpro'),
295
+
'SCR' => __('Seychellois Rupee', 'fluentformpro'),
296
+
'SEK' => __('Swedish Krona', 'fluentformpro'),
297
+
'SGD' => __('Singapore Dollar', 'fluentformpro'),
298
+
'SHP' => __('Saint Helenian Pound', 'fluentformpro'),
299
+
'SLL' => __('Sierra Leonean Leone', 'fluentformpro'),
300
+
'SOS' => __('Somali Shilling', 'fluentformpro'),
301
+
'SRD' => __('Surinamese Dollar', 'fluentformpro'),
302
+
'STD' => __('São Tomé and Príncipe Dobra', 'fluentformpro'),
303
+
'SVC' => __('Salvadoran Colón', 'fluentformpro'),
304
+
'SZL' => __('Swazi Lilangeni', 'fluentformpro'),
305
+
'THB' => __('Thai Baht', 'fluentformpro'),
306
+
'TJS' => __('Tajikistani Somoni', 'fluentformpro'),
307
+
'TOP' => __('Tongan Paʻanga', 'fluentformpro'),
308
+
'TRY' => __('Turkish Lira', 'fluentformpro'),
309
+
'TTD' => __('Trinidad and Tobago Dollar', 'fluentformpro'),
310
+
'TWD' => __('New Taiwan Dollar', 'fluentformpro'),
311
+
'TZS' => __('Tanzanian Shilling', 'fluentformpro'),
312
+
'UAH' => __('Ukrainian Hryvnia', 'fluentformpro'),
313
+
'UGX' => __('Ugandan Shilling', 'fluentformpro'),
314
+
'USD' => __('United States Dollar', 'fluentformpro'),
315
+
'UYU' => __('Uruguayan Peso', 'fluentformpro'),
316
+
'UZS' => __('Uzbekistani Som', 'fluentformpro'),
317
+
'VND' => __('Vietnamese Đồng', 'fluentformpro'),
318
+
'VUV' => __('Vanuatu Vatu', 'fluentformpro'),
319
+
'WST' => __('Samoan Tala', 'fluentformpro'),
320
+
'XAF' => __('Central African Cfa Franc', 'fluentformpro'),
321
+
'XCD' => __('East Caribbean Dollar', 'fluentformpro'),
322
+
'XOF' => __('West African Cfa Franc', 'fluentformpro'),
323
+
'XPF' => __('Cfp Franc', 'fluentformpro'),
324
+
'YER' => __('Yemeni Rial', 'fluentformpro'),
325
+
'ZAR' => __('South African Rand', 'fluentformpro'),
326
+
'ZMW' => __('Zambian Kwacha', 'fluentformpro')
327
+
];
328
+
329
+
$currencies = apply_filters_deprecated(
330
+
'fluentform_accepted_currencies',
331
+
[
332
+
$currencies
333
+
],
334
+
FLUENTFORM_FRAMEWORK_UPGRADE,
335
+
'fluentform/accepted_currencies',
336
+
'Use fluentform/accepted_currencies instead of fluentform_accepted_currencies.'
337
+
);
338
+
339
+
return apply_filters('fluentform/accepted_currencies', $currencies);
340
+
}
341
+
342
+
/**
343
+
* Get a specific currency symbol
344
+
*
345
+
* https://support.stripe.com/questions/which-currencies-does-stripe-support
346
+
*/
347
+
public static function getCurrencySymbol($currency = '')
348
+
{
349
+
if (!$currency) {
350
+
// If no currency is passed then default it to USD
351
+
$currency = 'USD';
352
+
}
353
+
$currency = strtoupper($currency);
354
+
355
+
$symbols = self::getCurrencySymbols();
356
+
$currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '';
357
+
358
+
$currency_symbol = apply_filters_deprecated(
359
+
'fluentform_currency_symbol',
360
+
[
361
+
$currency_symbol,
362
+
$currency
363
+
],
364
+
FLUENTFORM_FRAMEWORK_UPGRADE,
365
+
'fluentform/currency_symbol',
366
+
'Use fluentform/currency_symbol instead of fluentform_currency_symbol.'
367
+
);
368
+
369
+
return apply_filters('fluentform/currency_symbol', $currency_symbol, $currency);
370
+
}
371
+
372
+
public static function getCurrencySymbols()
373
+
{
374
+
$symbols = [
375
+
'AED' => 'د.إ',
376
+
'AFN' => '؋',
377
+
'ALL' => 'L',
378
+
'AMD' => 'AMD',
379
+
'ANG' => 'ƒ',
380
+
'AOA' => 'Kz',
381
+
'ARS' => '$',
382
+
'AUD' => '$',
383
+
'AWG' => 'ƒ',
384
+
'AZN' => 'AZN',
385
+
'BAM' => 'KM',
386
+
'BBD' => '$',
387
+
'BDT' => '৳ ',
388
+
'BGN' => 'лв.',
389
+
'BHD' => '.د.ب',
390
+
'BIF' => 'Fr',
391
+
'BMD' => '$',
392
+
'BND' => '$',
393
+
'BOB' => 'Bs.',
394
+
'BRL' => 'R$',
395
+
'BSD' => '$',
396
+
'BTC' => '฿',
397
+
'BTN' => 'Nu.',
398
+
'BWP' => 'P',
399
+
'BYR' => 'Br',
400
+
'BZD' => '$',
401
+
'CAD' => '$',
402
+
'CDF' => 'Fr',
403
+
'CHF' => 'CHF',
404
+
'CLP' => '$',
405
+
'CNY' => '¥',
406
+
'COP' => '$',
407
+
'CRC' => '₡',
408
+
'CUC' => '$',
409
+
'CUP' => '$',
410
+
'CVE' => '$',
411
+
'CZK' => 'Kč',
412
+
'DJF' => 'Fr',
413
+
'DKK' => 'DKK',
414
+
'DOP' => 'RD$',
415
+
'DZD' => 'د.ج',
416
+
'EGP' => 'EGP',
417
+
'ERN' => 'Nfk',
418
+
'ETB' => 'Br',
419
+
'EUR' => '€',
420
+
'FJD' => '$',
421
+
'FKP' => '£',
422
+
'GBP' => '£',
423
+
'GEL' => 'ლ',
424
+
'GGP' => '£',
425
+
'GHS' => '₵',
426
+
'GIP' => '£',
427
+
'GMD' => 'D',
428
+
'GNF' => 'Fr',
429
+
'GTQ' => 'Q',
430
+
'GYD' => '$',
431
+
'HKD' => '$',
432
+
'HNL' => 'L',
433
+
'HRK' => 'Kn',
434
+
'HTG' => 'G',
435
+
'HUF' => 'Ft',
436
+
'IDR' => 'Rp',
437
+
'ILS' => '₪',
438
+
'IMP' => '£',
439
+
'INR' => '₹',
440
+
'IQD' => 'ع.د',
441
+
'IRR' => '﷼',
442
+
'ISK' => 'Kr.',
443
+
'JEP' => '£',
444
+
'JMD' => '$',
445
+
'JOD' => 'د.ا',
446
+
'JPY' => '¥',
447
+
'KES' => 'KSh',
448
+
'KGS' => 'лв',
449
+
'KHR' => '៛',
450
+
'KMF' => 'Fr',
451
+
'KPW' => '₩',
452
+
'KRW' => '₩',
453
+
'KWD' => 'د.ك',
454
+
'KYD' => '$',
455
+
'KZT' => 'KZT',
456
+
'LAK' => '₭',
457
+
'LBP' => 'ل.ل',
458
+
'LKR' => 'රු',
459
+
'LRD' => '$',
460
+
'LSL' => 'L',
461
+
'LYD' => 'ل.د',
462
+
'MAD' => 'د. م.',
463
+
'MDL' => 'L',
464
+
'MGA' => 'Ar',
465
+
'MKD' => 'ден',
466
+
'MMK' => 'Ks',
467
+
'MNT' => '₮',
468
+
'MOP' => 'P',
469
+
'MRO' => 'UM',
470
+
'MUR' => '₨',
471
+
'MVR' => '.ރ',
472
+
'MWK' => 'MK',
473
+
'MXN' => '$',
474
+
'MYR' => 'RM',
475
+
'MZN' => 'MT',
476
+
'NAD' => '$',
477
+
'NGN' => '₦',
478
+
'NIO' => 'C$',
479
+
'NOK' => 'kr',
480
+
'NPR' => '₨',
481
+
'NZD' => '$',
482
+
'OMR' => 'ر.ع.',
483
+
'PAB' => 'B/.',
484
+
'PEN' => 'S/.',
485
+
'PGK' => 'K',
486
+
'PHP' => '₱',
487
+
'PKR' => '₨',
488
+
'PLN' => 'zł',
489
+
'PRB' => 'р.',
490
+
'PYG' => '₲',
491
+
'QAR' => 'ر.ق',
492
+
'RMB' => '¥',
493
+
'RON' => 'lei',
494
+
'RSD' => 'дин.',
495
+
'RUB' => '₽',
496
+
'RWF' => 'Fr',
497
+
'SAR' => 'ر.س',
498
+
'SBD' => '$',
499
+
'SCR' => '₨',
500
+
'SDG' => 'ج.س.',
501
+
'SEK' => 'kr',
502
+
'SGD' => '$',
503
+
'SHP' => '£',
504
+
'SLL' => 'Le',
505
+
'SOS' => 'Sh',
506
+
'SRD' => '$',
507
+
'SSP' => '£',
508
+
'STD' => 'Db',
509
+
'SYP' => 'ل.س',
510
+
'SZL' => 'L',
511
+
'THB' => '฿',
512
+
'TJS' => 'ЅМ',
513
+
'TMT' => 'm',
514
+
'TND' => 'د.ت',
515
+
'TOP' => 'T$',
516
+
'TRY' => '₺',
517
+
'TTD' => '$',
518
+
'TWD' => 'NT$',
519
+
'TZS' => 'Sh',
520
+
'UAH' => '₴',
521
+
'UGX' => 'UGX',
522
+
'USD' => '$',
523
+
'UYU' => '$',
524
+
'UZS' => 'UZS',
525
+
'VEF' => 'Bs F',
526
+
'VND' => '₫',
527
+
'VUV' => 'Vt',
528
+
'WST' => 'T',
529
+
'XAF' => 'Fr',
530
+
'XCD' => '$',
531
+
'XOF' => 'Fr',
532
+
'XPF' => 'Fr',
533
+
'YER' => '﷼',
534
+
'ZAR' => 'R',
535
+
'ZMW' => 'ZK',
536
+
];
537
+
538
+
$symbols = apply_filters_deprecated(
539
+
'fluentform_currency_symbols',
540
+
[
541
+
$symbols
542
+
],
543
+
FLUENTFORM_FRAMEWORK_UPGRADE,
544
+
'fluentform/currencies_symbols',
545
+
'Use fluentform/currencies_symbols instead of fluentform_currency_symbols.'
546
+
);
547
+
548
+
return apply_filters('fluentform/currencies_symbols', $symbols);
549
+
}
550
+
551
+
public static function zeroDecimalCurrencies()
552
+
{
553
+
$zeroDecimalCurrencies = [
554
+
'BIF' => esc_html__('Burundian Franc', 'fluentformpro'),
555
+
'CLP' => esc_html__('Chilean Peso', 'fluentformpro'),
556
+
'DJF' => esc_html__('Djiboutian Franc', 'fluentformpro'),
557
+
'GNF' => esc_html__('Guinean Franc', 'fluentformpro'),
558
+
'JPY' => esc_html__('Japanese Yen', 'fluentformpro'),
559
+
'KMF' => esc_html__('Comorian Franc', 'fluentformpro'),
560
+
'KRW' => esc_html__('South Korean Won', 'fluentformpro'),
561
+
'MGA' => esc_html__('Malagasy Ariary', 'fluentformpro'),
562
+
'PYG' => esc_html__('Paraguayan Guaraní', 'fluentformpro'),
563
+
'RWF' => esc_html__('Rwandan Franc', 'fluentformpro'),
564
+
'VND' => esc_html__('Vietnamese Dong', 'fluentformpro'),
565
+
'VUV' => esc_html__('Vanuatu Vatu', 'fluentformpro'),
566
+
'XAF' => esc_html__('Central African Cfa Franc', 'fluentformpro'),
567
+
'XOF' => esc_html__('West African Cfa Franc', 'fluentformpro'),
568
+
'XPF' => esc_html__('Cfp Franc', 'fluentformpro'),
569
+
];
570
+
571
+
$zeroDecimalCurrencies = apply_filters_deprecated(
572
+
'fluentform_zero_decimal_currencies',
573
+
[
574
+
$zeroDecimalCurrencies
575
+
],
576
+
FLUENTFORM_FRAMEWORK_UPGRADE,
577
+
'fluentform/zero_decimal_currencies',
578
+
'Use fluentform/zero_decimal_currencies instead of fluentform_zero_decimal_currencies.'
579
+
);
580
+
581
+
return apply_filters('fluentform/zero_decimal_currencies', $zeroDecimalCurrencies);
582
+
}
583
+
584
+
public static function isZeroDecimal($currencyCode)
585
+
{
586
+
$currencyCode = strtoupper($currencyCode);
587
+
$zeroDecimals = self::zeroDecimalCurrencies();
588
+
return isset($zeroDecimals[$currencyCode]);
589
+
}
590
+
591
+
public static function getPaymentStatuses()
592
+
{
593
+
$paymentStatuses = [
594
+
'paid' => __('Paid', 'fluentformpro'),
595
+
'processing' => __('Processing', 'fluentformpro'),
596
+
'pending' => __('Pending', 'fluentformpro'),
597
+
'failed' => __('Failed', 'fluentformpro'),
598
+
'refunded' => __('Refunded', 'fluentformpro'),
599
+
'partially-refunded' => __('Partial Refunded', 'fluentformpro'),
600
+
'cancelled' => __('Cancelled', 'fluentformpro')
601
+
];
602
+
603
+
$paymentStatuses = apply_filters_deprecated(
604
+
'fluentform_available_payment_statuses',
605
+
[
606
+
$paymentStatuses
607
+
],
608
+
FLUENTFORM_FRAMEWORK_UPGRADE,
609
+
'fluentform/available_payment_statuses',
610
+
'Use fluentform/available_payment_statuses instead of fluentform_available_payment_statuses.'
611
+
);
612
+
613
+
return apply_filters('fluentform/available_payment_statuses', $paymentStatuses);
614
+
}
615
+
616
+
public static function getFormPaymentMethods($formId)
617
+
{
618
+
$inputs = FormFieldsParser::getInputs($formId, ['element', 'settings']);
619
+
foreach ($inputs as $field) {
620
+
if ($field['element'] == 'payment_method') {
621
+
$methods = ArrayHelper::get($field, 'settings.payment_methods');
622
+
if (is_array($methods)) {
623
+
return array_filter($methods, function ($method) {
624
+
return $method['enabled'] == 'yes';
625
+
});
626
+
}
627
+
}
628
+
}
629
+
return [];
630
+
}
631
+
632
+
public static function getCustomerEmail($submission, $form = false)
633
+
{
634
+
635
+
$formSettings = PaymentHelper::getFormSettings($submission->form_id, 'admin');
636
+
$customerEmailField = ArrayHelper::get($formSettings, 'receipt_email');
637
+
638
+
if ($customerEmailField) {
639
+
$email = ArrayHelper::get($submission->response, $customerEmailField);
640
+
if ($email) {
641
+
return $email;
642
+
}
643
+
}
644
+
645
+
$user = get_user_by('ID', get_current_user_id());
646
+
647
+
if ($user) {
648
+
return $user->user_email;
649
+
}
650
+
651
+
if (!$form) {
652
+
return '';
653
+
}
654
+
655
+
$emailFields = FormFieldsParser::getInputsByElementTypes($form, ['input_email'], ['attributes']);
656
+
657
+
foreach ($emailFields as $field) {
658
+
$fieldName = $field['attributes']['name'];
659
+
if (!empty($submission->response[$fieldName])) {
660
+
return $submission->response[$fieldName];
661
+
}
662
+
}
663
+
664
+
return '';
665
+
666
+
}
667
+
668
+
static function getCustomerPhoneNumber($submission, $form) {
669
+
$phoneFields = FormFieldsParser::getInputsByElementTypes($form, ['phone'], ['attributes']);
670
+
671
+
foreach ($phoneFields as $field) {
672
+
$fieldName = $field['attributes']['name'];
673
+
if (!empty($submission->response[$fieldName])) {
674
+
return $submission->response[$fieldName];
675
+
}
676
+
}
677
+
return '';
678
+
}
679
+
680
+
/**
681
+
* Trim a string and append a suffix.
682
+
*
683
+
* @param string $string String to trim.
684
+
* @param integer $chars Amount of characters.
685
+
* Defaults to 200.
686
+
* @param string $suffix Suffix.
687
+
* Defaults to '...'.
688
+
* @return string
689
+
*/
690
+
public static function formatPaymentItemString($string, $chars = 200, $suffix = '...')
691
+
{
692
+
$string = wp_strip_all_tags($string);
693
+
if (strlen($string) > $chars) {
694
+
if (function_exists('mb_substr')) {
695
+
$string = mb_substr($string, 0, ($chars - mb_strlen($suffix))) . $suffix;
696
+
} else {
697
+
$string = substr($string, 0, ($chars - strlen($suffix))) . $suffix;
698
+
}
699
+
}
700
+
701
+
return html_entity_decode($string, ENT_NOQUOTES, 'UTF-8');
702
+
}
703
+
704
+
/**
705
+
* Limit length of an arg.
706
+
*
707
+
* @param string $string Argument to limit.
708
+
* @param integer $limit Limit size in characters.
709
+
* @return string
710
+
*/
711
+
public static function limitLength($string, $limit = 127)
712
+
{
713
+
$str_limit = $limit - 3;
714
+
if (function_exists('mb_strimwidth')) {
715
+
if (mb_strlen($string) > $limit) {
716
+
$string = mb_strimwidth($string, 0, $str_limit) . '...';
717
+
}
718
+
} else {
719
+
if (strlen($string) > $limit) {
720
+
$string = substr($string, 0, $str_limit) . '...';
721
+
}
722
+
}
723
+
return $string;
724
+
}
725
+
726
+
public static function floatToString($float)
727
+
{
728
+
if (!is_float($float)) {
729
+
return $float;
730
+
}
731
+
732
+
$locale = localeconv();
733
+
$string = strval($float);
734
+
$string = str_replace($locale['decimal_point'], '.', $string);
735
+
736
+
return $string;
737
+
}
738
+
739
+
public static function convertToCents($amount)
740
+
{
741
+
if (!$amount) {
742
+
return 0;
743
+
}
744
+
745
+
$amount = floatval($amount);
746
+
747
+
return intval(round($amount * 100));
748
+
}
749
+
750
+
public static function getCustomerName($submission, $form = false)
751
+
{
752
+
$formSettings = PaymentHelper::getFormSettings($submission->form_id, 'admin');
753
+
$customerNameCode = ArrayHelper::get($formSettings, 'customer_name');
754
+
if ($customerNameCode) {
755
+
$customerName = ShortCodeParser::parse($customerNameCode, $submission->id, $submission->response);
756
+
if ($customerName) {
757
+
return $customerName;
758
+
}
759
+
}
760
+
761
+
$user = get_user_by('ID', get_current_user_id());
762
+
763
+
if ($user) {
764
+
$customerName = trim($user->first_name . ' ' . $user->last_name);
765
+
if (!$customerName) {
766
+
$customerName = $user->display_name;
767
+
}
768
+
if ($customerName) {
769
+
return $customerName;
770
+
}
771
+
}
772
+
773
+
if (!$form) {
774
+
return '';
775
+
}
776
+
777
+
$nameFields = FormFieldsParser::getInputsByElementTypes($form, ['input_name'], ['attributes']);
778
+
779
+
$fieldName = false;
780
+
foreach ($nameFields as $field) {
781
+
if ($field['element'] === 'input_name') {
782
+
$fieldName = $field['attributes']['name'];
783
+
break;
784
+
}
785
+
}
786
+
787
+
$name = '';
788
+
if ($fieldName) {
789
+
if (!empty($submission->response[$fieldName])) {
790
+
$names = array_filter($submission->response[$fieldName]);
791
+
return trim(implode(' ', $names));
792
+
}
793
+
}
794
+
795
+
return $name;
796
+
}
797
+
798
+
public static function getStripeInlineConfig($formId)
799
+
{
800
+
$methods = static::getFormPaymentMethods($formId);
801
+
802
+
$stripe = ArrayHelper::get($methods, 'stripe');
803
+
$stripeInlineStyles = ArrayHelper::get(Helper::getFormMeta($formId, '_ff_form_styles', []), 'stripe_inline_element_style', false);
804
+
if ($stripe) {
805
+
return apply_filters(
806
+
'fluentform/stripe_inline_config',
807
+
[
808
+
'is_inline' => ArrayHelper::get($stripe, 'settings.embedded_checkout.value') == 'yes',
809
+
'inline_styles' => $stripeInlineStyles,
810
+
'verifyZip' => ArrayHelper::get($methods['stripe'], 'settings.verify_zip_code.value') === 'yes',
811
+
'disable_link' => false
812
+
],
813
+
$formId
814
+
);
815
+
}
816
+
817
+
return [];
818
+
}
819
+
820
+
public static function getSquareInlineConfig($formId)
821
+
{
822
+
$methods = static::getFormPaymentMethods($formId);
823
+
824
+
$square = ArrayHelper::get($methods, 'square');
825
+
$squareSettings = SquareSettings::getApiKeys();
826
+
$squareInlineStyles = ArrayHelper::get(Helper::getFormMeta($formId, '_ff_form_styles', []), 'square_inline_element_style', false);
827
+
if ($square) {
828
+
return apply_filters(
829
+
'fluentform/square_inline_config',
830
+
[
831
+
'is_inline' => ArrayHelper::get($square, 'settings.embedded_checkout.value') == 'yes',
832
+
'inline_styles' => $squareInlineStyles,
833
+
'settings' => $squareSettings,
834
+
'locale' => 'en-US'
835
+
],
836
+
$formId
837
+
);
838
+
}
839
+
840
+
return [];
841
+
}
842
+
843
+
public static function log($data, $submission = false, $forceInsert = false)
844
+
{
845
+
if (!$forceInsert) {
846
+
static $paymentSettings;
847
+
if (!$paymentSettings) {
848
+
$paymentSettings = self::getPaymentSettings();
849
+
}
850
+
851
+
if (!isset($paymentSettings['debug_log']) || $paymentSettings['debug_log'] != 'yes') {
852
+
return false;
853
+
}
854
+
}
855
+
856
+
$defaults = [
857
+
'component' => 'Payment',
858
+
'status' => 'info',
859
+
'created_at' => current_time('mysql')
860
+
];
861
+
862
+
if ($submission) {
863
+
$defaults['parent_source_id'] = $submission->form_id;
864
+
$defaults['source_type'] = 'submission_item';
865
+
$defaults['source_id'] = $submission->id;
866
+
} else {
867
+
$defaults['source_type'] = 'system_log';
868
+
}
869
+
870
+
$data = wp_parse_args($data, $defaults);
871
+
872
+
return wpFluent()->table('fluentform_logs')
873
+
->insertGetId($data);
874
+
875
+
}
876
+
877
+
public static function maybeFireSubmissionActionHok($submission)
878
+
{
879
+
if (Helper::getSubmissionMeta($submission->id, 'is_form_action_fired') == 'yes') {
880
+
return false;
881
+
}
882
+
883
+
$form = wpFluent()->table('fluentform_forms')->where('id', $submission->form_id)->first();
884
+
885
+
$formData = $submission->response;
886
+
if (!is_array($formData)) {
887
+
$formData = json_decode($formData, true);
888
+
}
889
+
890
+
(new SubmissionHandlerService())->processSubmissionData(
891
+
$submission->id, $formData, $form
892
+
);
893
+
Helper::setSubmissionMeta($submission->id, 'is_form_action_fired', 'yes');
894
+
return true;
895
+
}
896
+
897
+
public static function loadView($fileName, $data)
898
+
{
899
+
// normalize the filename
900
+
$fileName = str_replace(array('../', './'), '', $fileName);
901
+
902
+
$basePath = FLUENTFORMPRO_DIR_PATH . 'src/views/receipt/';
903
+
$basePath = apply_filters_deprecated(
904
+
'fluentform_payment_receipt_template_base_path',
905
+
[
906
+
$basePath,
907
+
$fileName,
908
+
$data
909
+
],
910
+
FLUENTFORM_FRAMEWORK_UPGRADE,
911
+
'fluentform/payment_receipt_template_base_path',
912
+
'Use fluentform/payment_receipt_template_base_path instead of fluentform_payment_receipt_template_base_path.'
913
+
);
914
+
915
+
$basePath = apply_filters('fluentform/payment_receipt_template_base_path', $basePath, $fileName, $data);
916
+
917
+
$filePath = $basePath . $fileName . '.php';
918
+
extract($data);
919
+
ob_start();
920
+
include $filePath;
921
+
return ob_get_clean();
922
+
}
923
+
924
+
public static function recordSubscriptionCancelled($subscription, $vendorData, $logData = [])
925
+
{
926
+
wpFluent()->table('fluentform_subscriptions')
927
+
->where('id', $subscription->id)
928
+
->update([
929
+
'status' => 'cancelled',
930
+
'updated_at' => current_time('mysql')
931
+
]);
932
+
933
+
$subscription = wpFluent()->table('fluentform_subscriptions')
934
+
->where('id', $subscription->id)
935
+
->first();
936
+
937
+
$submission = wpFluent()->table('fluentform_submissions')
938
+
->where('id', $subscription->submission_id)
939
+
->first();
940
+
941
+
$logDefaults = [
942
+
'parent_source_id' => $subscription->form_id,
943
+
'source_type' => 'submission_item',
944
+
'source_id' => $subscription->submission_id,
945
+
'component' => 'Payment',
946
+
'status' => 'info',
947
+
'title' => __('Subscription has been cancelled', 'fluentformpro'),
948
+
'description' => __('Subscription has been cancelled from ', 'fluentformpro') . $submission->payment_method
949
+
];
950
+
951
+
$logs = wp_parse_args($logData, $logDefaults);
952
+
953
+
do_action('fluentform/log_data', $logs);
954
+
955
+
do_action_deprecated(
956
+
'fluentform_subscription_payment_canceled',
957
+
[
958
+
$subscription,
959
+
$submission,
960
+
$vendorData
961
+
],
962
+
FLUENTFORM_FRAMEWORK_UPGRADE,
963
+
'fluentform/subscription_payment_canceled',
964
+
'Use fluentform/subscription_payment_canceled instead of fluentform_subscription_payment_canceled.'
965
+
);
966
+
// New Payment Made so we have to fire some events here
967
+
do_action('fluentform/subscription_payment_canceled', $subscription, $submission, $vendorData);
968
+
969
+
do_action_deprecated(
970
+
'fluentform_subscription_payment_canceled_' . $submission->payment_method,
971
+
[
972
+
$subscription,
973
+
$submission,
974
+
$vendorData
975
+
],
976
+
FLUENTFORM_FRAMEWORK_UPGRADE,
977
+
'fluentform/subscription_payment_canceled_' . $submission->payment_method,
978
+
'Use fluentform/subscription_payment_canceled_' . $submission->payment_method . ' instead of fluentform_subscription_payment_canceled_' . $submission->payment_method
979
+
);
980
+
do_action('fluentform/subscription_payment_canceled_' . $submission->payment_method, $subscription, $submission, $vendorData);
981
+
}
982
+
983
+
public static function getPaymentSummaryText($plan, $formId, $currency, $withMarkup = true)
984
+
{
985
+
$paymentSummaryText = [
986
+
'has_signup_fee' => __('{first_interval_total} for first {billing_interval} then {subscription_amount} for each {billing_interval}', 'fluentformpro'),
987
+
'has_trial' => __('Free for {trial_days} days then {subscription_amount} for each {billing_interval}', 'fluentformpro'),
988
+
'onetime_only' => __('One time payment of {first_interval_total}', 'fluentformpro'),
989
+
'normal' => __('{subscription_amount} for each {billing_interval}', 'fluentformpro'),
990
+
'bill_times' => __(', for {bill_times} installments', 'fluentformpro'),
991
+
'single_trial' => __('Free for {trial_days} days then {subscription_amount} one time')
992
+
];
993
+
994
+
$paymentSummaryText = apply_filters_deprecated(
995
+
'fluentform_recurring_payment_summary_texts',
996
+
[
997
+
$paymentSummaryText,
998
+
$plan,
999
+
$formId
1000
+
],
1001
+
FLUENTFORM_FRAMEWORK_UPGRADE,
1002
+
'fluentform/recurring_payment_summary_texts',
1003
+
'Use fluentform/recurring_payment_summary_texts instead of fluentform_recurring_payment_summary_texts.'
1004
+
);
1005
+
1006
+
$cases = apply_filters('fluentform/recurring_payment_summary_texts', $paymentSummaryText, $plan, $formId);
1007
+
1008
+
// if is trial
1009
+
$hasTrial = ArrayHelper::get($plan, 'has_trial_days') == 'yes' && ArrayHelper::get($plan, 'trial_days');
1010
+
if ($hasTrial) {
1011
+
$plan['signup_fee'] = 0;
1012
+
}
1013
+
1014
+
$signupFee = 0;
1015
+
$hasSignupFee = ArrayHelper::get($plan, 'has_signup_fee') == 'yes' && ArrayHelper::get($plan, 'signup_fee');
1016
+
if ($hasSignupFee) {
1017
+
$plan['trial_days'] = 0;
1018
+
$signupFee = ArrayHelper::get($plan, 'signup_fee');
1019
+
}
1020
+
1021
+
$firstIntervalTotal = PaymentHelper::formatMoney(
1022
+
PaymentHelper::convertToCents($signupFee + ArrayHelper::get($plan, 'subscription_amount')),
1023
+
$currency
1024
+
);
1025
+
1026
+
if ($signupFee) {
1027
+
$signupFee = PaymentHelper::formatMoney(
1028
+
PaymentHelper::convertToCents($signupFee),
1029
+
$currency
1030
+
);
1031
+
}
1032
+
1033
+
$subscriptionAmount = PaymentHelper::formatMoney(
1034
+
PaymentHelper::convertToCents(ArrayHelper::get($plan, 'subscription_amount')),
1035
+
$currency
1036
+
);
1037
+
1038
+
$billingInterval = $plan['billing_interval'];
1039
+
$billingInterval = ArrayHelper::get(self::getBillingIntervals(), $billingInterval, $billingInterval);
1040
+
$replaces = array(
1041
+
'{signup_fee}' => '<span class="ff_bs ffbs_signup_fee">' . $signupFee . '</span>',
1042
+
'{first_interval_total}' => '<span class="ff_bs ffbs_first_interval_total">' . $firstIntervalTotal . '</span>',
1043
+
'{subscription_amount}' => '<span class="ff_bs ffbs_subscription_amount">' . $subscriptionAmount . '</span>',
1044
+
'{billing_interval}' => '<span class="ff_bs ffbs_billing_interval">' . $billingInterval . '</span>',
1045
+
'{trial_days}' => '<span class="ff_bs ffbs_trial_days">' . $plan['trial_days'] . '</span>',
1046
+
'{bill_times}' => '<span class="ff_bs ffbs_bill_times">' . ArrayHelper::get($plan, 'bill_times') . '</span>'
1047
+
);
1048
+
1049
+
if (ArrayHelper::get($plan, 'user_input') == 'yes') {
1050
+
$cases['{subscription_amount}'] = '<span class="ff_dynamic_input_amount">' . $subscriptionAmount . '</span>';
1051
+
}
1052
+
1053
+
foreach ($cases as $textKey => $text) {
1054
+
$cases[$textKey] = str_replace(array_keys($replaces), array_values($replaces), $text);
1055
+
}
1056
+
1057
+
$customText = '';
1058
+
if ($hasSignupFee) {
1059
+
$customText = $cases['has_signup_fee'];
1060
+
} else if ($hasTrial) {
1061
+
if (ArrayHelper::get($plan, 'bill_times') == 1) {
1062
+
$customText = $cases['single_trial'];
1063
+
} else {
1064
+
$customText = $cases['has_trial'];
1065
+
}
1066
+
} else if (isset($plan['bill_times']) && $plan['bill_times'] == 1) {
1067
+
$customText = $cases['onetime_only'];
1068
+
} else {
1069
+
$customText = $cases['normal'];
1070
+
}
1071
+
1072
+
if (isset($plan['bill_times']) && $plan['bill_times'] > 1) {
1073
+
$customText .= $cases['bill_times'];
1074
+
}
1075
+
if($withMarkup) {
1076
+
$class = $plan['is_default'] === 'yes' ? '' : 'hidden_field';
1077
+
return '<div class="ff_summary_container ff_summary_container_' . $plan['index'] . ' ' . $class . '">' . $customText . '</div>';
1078
+
}
1079
+
return $customText;
1080
+
}
1081
+
1082
+
public static function getCustomerAddress($submission)
1083
+
{
1084
+
$formSettings = PaymentHelper::getFormSettings($submission->form_id, 'admin');
1085
+
$customerAddressField = ArrayHelper::get($formSettings, 'customer_address');
1086
+
1087
+
if ($customerAddressField) {
1088
+
return ArrayHelper::get($submission->response, $customerAddressField);
1089
+
}
1090
+
1091
+
return null;
1092
+
}
1093
+
1094
+
public static function getBillingIntervals()
1095
+
{
1096
+
return [
1097
+
'day' => __('day', 'fluentformpro'),
1098
+
'week' => __('week', 'fluentformpro'),
1099
+
'month' => __('month', 'fluentformpro'),
1100
+
'year' => __('year', 'fluentformpro')
1101
+
];
1102
+
}
1103
+
1104
+
public static function getSubscriptionStatuses()
1105
+
{
1106
+
return [
1107
+
'active' => __('active', 'fluentformpro'),
1108
+
'trialling' => __('trialling', 'fluentformpro'),
1109
+
'failing' => __('failing', 'fluentformpro'),
1110
+
'cancelled' => __('cancelled', 'fluentformpro')
1111
+
];
1112
+
}
1113
+
1114
+
public static function getFormInput($formId,$inputType)
1115
+
{
1116
+
$form = fluentFormApi()->form($formId);
1117
+
$fields = FormFieldsParser::getInputsByElementTypes($form, [$inputType], ['attributes']);
1118
+
if (!empty($fields)) {
1119
+
$field = array_shift($fields);
1120
+
return ArrayHelper::get($field, 'attributes.name');
1121
+
}
1122
+
return '';
1123
+
}
1124
+
1125
+
public static function encryptKey($value)
1126
+
{
1127
+
if(!$value) {
1128
+
return $value;
1129
+
}
1130
+
1131
+
if ( ! extension_loaded( 'openssl' ) ) {
1132
+
return $value;
1133
+
}
1134
+
1135
+
$salt = (defined( 'LOGGED_IN_SALT' ) && '' !== LOGGED_IN_SALT) ? LOGGED_IN_SALT : 'this-is-a-fallback-salt-but-not-secure';
1136
+
$key = ( defined( 'LOGGED_IN_KEY' ) && '' !== LOGGED_IN_KEY ) ? LOGGED_IN_KEY : 'this-is-a-fallback-key-but-not-secure';
1137
+
1138
+
$method = 'aes-256-ctr';
1139
+
$ivlen = openssl_cipher_iv_length( $method );
1140
+
$iv = openssl_random_pseudo_bytes( $ivlen );
1141
+
1142
+
$raw_value = openssl_encrypt( $value . $salt, $method, $key, 0, $iv );
1143
+
if ( ! $raw_value ) {
1144
+
return false;
1145
+
}
1146
+
1147
+
return base64_encode( $iv . $raw_value ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
1148
+
}
1149
+
1150
+
public static function decryptKey( $raw_value ) {
1151
+
1152
+
if(!$raw_value) {
1153
+
return $raw_value;
1154
+
}
1155
+
1156
+
if ( ! extension_loaded( 'openssl' ) ) {
1157
+
return $raw_value;
1158
+
}
1159
+
1160
+
$raw_value = base64_decode( $raw_value, true ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
1161
+
1162
+
$method = 'aes-256-ctr';
1163
+
$ivlen = openssl_cipher_iv_length( $method );
1164
+
$iv = substr( $raw_value, 0, $ivlen );
1165
+
1166
+
$raw_value = substr( $raw_value, $ivlen );
1167
+
1168
+
$salt = (defined( 'LOGGED_IN_SALT' ) && '' !== LOGGED_IN_SALT) ? LOGGED_IN_SALT : 'this-is-a-fallback-salt-but-not-secure';
1169
+
$key = ( defined( 'LOGGED_IN_KEY' ) && '' !== LOGGED_IN_KEY ) ? LOGGED_IN_KEY : 'this-is-a-fallback-key-but-not-secure';
1170
+
1171
+
$value = openssl_decrypt( $raw_value, $method, $key, 0, $iv );
1172
+
if ( ! $value || substr( $value, - strlen( $salt ) ) !== $salt ) {
1173
+
return false;
1174
+
}
1175
+
1176
+
return substr( $value, 0, - strlen( $salt ) );
1177
+
}
1178
+
}
1179
+