PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.1.1
GiveWP – Donation Plugin and Fundraising Platform v3.1.1
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / FormMigration / FormMetaDecorator.php
give / src / FormMigration Last commit date
Actions 2 years ago Commands 2 years ago Concerns 2 years ago Contracts 2 years ago Controllers 2 years ago DataTransferObjects 2 years ago Steps 2 years ago FormMetaDecorator.php 2 years ago Pipeline.php 2 years ago ServiceProvider.php 2 years ago StepProcessor.php 2 years ago functions.php 2 years ago
FormMetaDecorator.php
528 lines
1 <?php
2
3 namespace Give\FormMigration;
4
5 use Give\DonationForms\V2\Models\DonationForm;
6 use Give\DonationForms\ValueObjects\GoalType;
7 use Give\FormMigration\Contracts\FormModelDecorator;
8 use Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\StripePaymentElementGateway;
9 use Give_Email_Notification_Util;
10
11 class FormMetaDecorator extends FormModelDecorator
12 {
13 /**
14 * @var DonationForm
15 */
16 protected $form;
17
18 public function __construct(DonationForm $form)
19 {
20 $this->form = $form;
21 }
22
23 public function isLastNameRequired(): bool
24 {
25 return give_is_last_name_required($this->form->id);
26 }
27
28 public function isNameTitlePrefixEnabled(): bool
29 {
30 return give_is_name_title_prefix_enabled($this->form->id);
31 }
32
33 public function getNameTitlePrefixes(): array
34 {
35 return give_get_name_title_prefixes($this->form->id);
36 }
37
38 public function isUserRegistrationEnabled(): bool
39 {
40 // @note In v3 all donors are registered as users, so no need for a registration setting.
41 return in_array(
42 give_get_meta($this->form->id, '_give_show_register_form', true),
43 ['registration', 'login', 'both']
44 );
45 }
46
47 public function isUserLoginRequired(): bool
48 {
49 return !$this->isGuestDonationsEnabled();
50 }
51
52 public function isGuestDonationsEnabled(): bool
53 {
54 // @note The "Guest Donation" setting corresponds to the `_give_logged_in_only` meta, which seems backwards.
55 return give_is_setting_enabled(
56 give_get_meta($this->form->id, '_give_logged_in_only', true)
57 );
58 }
59
60 public function isCompanyFieldEnabled(): bool
61 {
62 return give_is_company_field_enabled($this->form->id);
63 }
64
65 public function isCompanyFieldRequired(): bool
66 {
67 // @note Forked from give/includes/process-donation.php:718
68 if (give_is_company_field_enabled($this->form->id)) {
69 $form_option = give_get_meta($this->form->id, '_give_company_field', true);
70 $global_setting = give_get_option('company_field');
71
72 if (!empty($form_option) && give_is_setting_enabled($form_option, ['required'])) {
73 return true;
74 } elseif ('global' === $form_option && give_is_setting_enabled($global_setting, ['required'])) {
75 return true;
76 } elseif (empty($form_option) && give_is_setting_enabled($global_setting, ['required'])) {
77 return true;
78 }
79 }
80
81 return false;
82 }
83
84 public function getFormTemplate(): string
85 {
86 return give_get_meta($this->form->id, '_give_form_template', true);
87 }
88
89 public function getFormTemplateSettings(): array
90 {
91 $template = $this->getFormTemplate();
92
93 return give_get_meta($this->form->id, "_give_{$template}_form_template_settings", true);
94 }
95
96 public function isDonationGoalEnabled(): bool
97 {
98 return give_is_setting_enabled(
99 give_get_meta($this->form->id, '_give_goal_option', true)
100 );
101 }
102
103 public function getDonationGoalType(): GoalType
104 {
105 $onlyRecurringEnabled = $this->isGoalCountingOnlyRecurringDonations();
106
107 switch (give_get_form_goal_format($this->form->id)) {
108 case 'donors':
109 return $onlyRecurringEnabled ? GoalType::DONORS_FROM_SUBSCRIPTIONS() : GoalType::DONORS();
110 case 'donation': // @note v2: Singular
111 return $onlyRecurringEnabled ? GoalType::SUBSCRIPTIONS() : GoalType::DONATIONS();
112 // @note v3: Plural
113 case 'amount':
114 case 'percentage': // @note `percentage` is not supported in v3 - defaulting to `amount`
115 default:
116 return $onlyRecurringEnabled ? GoalType::AMOUNT_FROM_SUBSCRIPTIONS() : GoalType::AMOUNT();
117 }
118 }
119
120 /**
121 * @return mixed Goal of the form
122 */
123 public function getDonationGoalAmount()
124 {
125 return give_get_form_goal($this->form->id);
126 }
127
128 public function isAutoClosedEnabled()
129 {
130 return give_is_setting_enabled(
131 give_get_meta($this->form->id, '_give_close_form_when_goal_achieved', true, 'disabled')
132 );
133 }
134
135 public function getGoalAchievedMessage()
136 {
137 return give_get_meta($this->form->id, '_give_form_goal_achieved_message', true);
138 }
139
140 public function isTermsEnabled()
141 {
142 return give_is_terms_enabled($this->form->id);
143 }
144
145 public function getTermsAgreementLabel()
146 {
147 // @note Forked from give/includes/forms/template.php:1845
148 return ($label = give_get_meta($this->form->id, '_give_agree_label', true))
149 ? stripslashes($label)
150 : esc_html__('Agree to Terms?', 'give');
151 }
152
153 public function getTermsAgreementText()
154 {
155 return give_get_meta($this->form->id, '_give_agree_text', true);
156 }
157
158 public function isOfflineDonationsCustomized()
159 {
160 return give_is_setting_enabled(
161 give_get_meta($this->form->id, '_give_customize_offline_donations', true),
162 'custom'
163 );
164 }
165
166 public function isOfflineDonationsBillingFieldEnabled()
167 {
168 return give_is_setting_enabled(
169 give_get_meta($this->form->id, '_give_offline_donation_enable_billing_fields_single', true)
170 );
171 }
172
173 public function getOfflineDonationInstructions()
174 {
175 return give_get_meta($this->form->id, '_give_offline_checkout_notes', true);
176 }
177
178 public function isFormGridCustomized()
179 {
180 return give_is_setting_enabled(
181 give_get_meta($this->form->id, '_give_form_grid_option', true),
182 'custom'
183 );
184 }
185
186 public function getFormGridRedirectUrl()
187 {
188 return give_get_meta($this->form->id, '_give_form_grid_redirect_url', true);
189 }
190
191 public function getFormGridDonateButtonText()
192 {
193 return give_get_meta($this->form->id, '_give_form_grid_donate_button_text', true);
194 }
195
196 public function getEmailOptionsStatus(): string
197 {
198 return give_get_meta($this->form->id, '_give_email_options', true);
199 }
200
201 public function getEmailTemplate(): string
202 {
203 return give_get_meta($this->form->id, '_give_email_template', true);
204 }
205
206 public function getEmailLogo(): string
207 {
208 return Give_Email_Notification_Util::get_email_logo($this->form->id);
209 }
210
211 public function getEmailFromName(): string
212 {
213 return give_get_meta($this->form->id, '_give_from_name', true);
214 }
215
216 public function getEmailFromEmail(): string
217 {
218 return give_get_meta($this->form->id, '_give_from_email', true);
219 }
220
221 /**
222 * @since 3.0.0
223 * @return string 'multi', 'set'
224 */
225 public function getDonationOption(): string
226 {
227 return give()->form_meta->get_meta($this->form->id, '_give_price_option', true);
228 }
229
230 /**
231 * @since 3.0.0
232 * @return string 'multi', 'set'
233 */
234 public function isDonationOptionMulti(): string
235 {
236 return 'multi' === $this->getDonationOption();
237 }
238
239 /**
240 * @return string 'multi', 'set'
241 */
242 public function isDonationOptionSet(): string
243 {
244 return 'set' === $this->getDonationOption();
245 }
246
247 /**
248 * @since 3.0.0
249 */
250 public function getDonationLevels(): array
251 {
252 return give()->form_meta->get_meta($this->form->id, '_give_donation_levels', true);
253 }
254
255 /**
256 * @since 3.0.0
257 */
258 public function isRecurringDonationsEnabled(): bool
259 {
260 $_give_recurring = $this->getRecurringDonationsOption();
261
262 return !empty($_give_recurring) && 'no' !== $_give_recurring;
263 }
264
265 /**
266 * Recurring Donations = 'no', 'yes_donor', 'yes_admin'
267 *
268 * @since 3.0.0
269 */
270 public function getRecurringDonationsOption(): string
271 {
272 return give()->form_meta->get_meta($this->form->id, '_give_recurring', true);
273 }
274
275 /**
276 * @since 3.0.0
277 */
278 public function isRecurringDefaultCheckboxEnabled(): bool
279 {
280 return 'yes' === $this->getRecurringDefaultCheckboxOption();
281 }
282
283 /**
284 * 'day', 'week', 'month', 'year'
285 *
286 * @since 3.0.0
287 */
288 public function getRecurringPeriod(): string
289 {
290 return give()->form_meta->get_meta($this->form->id, '_give_period', true);
291 }
292
293 /**
294 * 'day', 'week', 'month', 'year'
295 *
296 * @since 3.0.0
297 */
298 public function getRecurringPeriodDefaultDonorsChoice(): string
299 {
300 return give()->form_meta->get_meta($this->form->id, '_give_period_default_donor_choice', true);
301 }
302
303 /**
304 * @since 3.0.0
305 */
306 public function getRecurringLengthOfTime(): int
307 {
308 return (int)give()->form_meta->get_meta($this->form->id, '_give_times', true);
309 }
310
311 /**
312 * @since 3.0.0
313 */
314 public function getRecurringBillingInterval(): int
315 {
316 return (int)give()->form_meta->get_meta($this->form->id, '_give_period_interval', true);
317 }
318
319 /**
320 * 'yes', 'no'
321 *
322 * @since 3.0.0
323 */
324 public function getRecurringDefaultCheckboxOption(): string
325 {
326 return give()->form_meta->get_meta($this->form->id, '_give_checkbox_default', true);
327 }
328
329 /**
330 * 'donors_choice', 'admin_choice', 'custom' (The "Donor's Choice" option allows the donor to select the time period (commonly also referred as the "frequency") of their subscription. The "Preset Period" option provides only the selected period for the donor's subscription.)
331 *
332 * @since 3.0.0
333 */
334 public function getRecurringPeriodFunctionality(): string
335 {
336 return give()->form_meta->get_meta($this->form->id, '_give_period_functionality', true);
337 }
338
339 /**
340 * @since 3.0.0
341 * @return string 'enabled', 'disabled'
342 */
343 public function getCustomAmountOption(): string
344 {
345 return give()->form_meta->get_meta($this->form->id, '_give_custom_amount', true);
346 }
347
348 /**
349 * @since 3.0.0
350 */
351 public function isCustomAmountOptionEnabled(): bool
352 {
353 return 'enabled' === $this->getCustomAmountOption();
354 }
355
356 /**
357 * @since 3.0.0
358 */
359 public function isRecurringPeriodFunctionalityDonorsChoice(): bool
360 {
361 return 'donors_choice' === $this->getRecurringPeriodFunctionality();
362 }
363
364 /**
365 * @since 3.0.0
366 */
367 public function isRecurringPeriodFunctionalityAdminChoice(): bool
368 {
369 return 'admin_choice' === $this->getRecurringPeriodFunctionality();
370 }
371
372 /**
373 * This used when donation option is 'multi' and custom amount is 'enabled'
374 *
375 * @since 3.0.0
376 */
377 public function getRecurringCustomAmountPeriod(): string
378 {
379 return give()->form_meta->get_meta($this->form->id, '_give_recurring_custom_amount_period', true);
380 }
381
382 /**
383 * This used when donation option is 'multi' and custom amount is 'enabled'
384 *
385 * @since 3.0.0
386 */
387 public function getRecurringCustomAmountInterval(): int
388 {
389 return give()->form_meta->get_meta($this->form->id, '_give_recurring_custom_amount_interval', true);
390 }
391
392 /**
393 * This used when donation option is 'multi' and custom amount is 'enabled'
394 *
395 * @since 3.0.0
396 */
397 public function getRecurringCustomAmountTimes(): int
398 {
399 return give()->form_meta->get_meta($this->form->id, '_give_recurring_custom_amount_times', true);
400 }
401
402 public function getStripeUseGlobalDefault(): bool
403 {
404 return (
405 give_get_meta($this->form->id, 'give_stripe_per_form_accounts', true) !== 'enabled'
406 );
407 }
408
409 public function getStripeAccountId(): string
410 {
411 return give_get_meta($this->form->id, '_give_stripe_default_account', true);
412 }
413
414 public function isGoalCountingOnlyRecurringDonations(): bool
415 {
416 return filter_var(give_get_meta($this->form->id, '_give_recurring_goal_format', true), FILTER_VALIDATE_BOOLEAN);
417 }
418
419 /**
420 * @return array{offlineEnabled: bool, offlineUseGlobalInstructions: bool, offlineDonationInstructions: string}
421 */
422 public function getOfflineAttributes(): array
423 {
424 $customization = give_get_meta($this->form->id, '_give_customize_offline_donations', true);
425 $instructions = give_get_meta($this->form->id, '_give_offline_checkout_notes', true);
426
427 return [
428 'offlineEnabled' => $customization !== 'disabled',
429 'offlineUseGlobalInstructions' => $customization === 'global',
430 'offlineDonationInstructions' => $instructions,
431 ];
432 }
433
434 /**
435 * @since 3.0.0
436 */
437 public function getFormFields(): array
438 {
439 return array_filter((array)give_get_meta($this->form->id, 'give-form-fields', true));
440 }
441
442 /**
443 * @since 3.0.0
444 */
445 public function getFormFieldsPlacement(): string
446 {
447 return give_get_meta($this->form->id, '_give_ffm_placement', true);
448 }
449
450 /**
451 * @since 3.0.2 set correct $gatewayId to be used in getMeta calls
452 * @since 3.0.0
453 */
454 public function getFeeRecoverySettings(): array
455 {
456 $feeRecoveryStatus = $this->getMeta('_form_give_fee_recovery');
457
458 if (empty($feeRecoveryStatus) || $feeRecoveryStatus === 'disabled') {
459 return [];
460 }
461
462 if ($feeRecoveryStatus === 'global') {
463 return [
464 'useGlobalSettings' => true,
465 ];
466 }
467
468 if ($feeRecoveryStatus !== 'enabled') {
469 return [];
470 }
471
472 $perGatewaySettings = [];
473 $gateways = give_get_ordered_payment_gateways(give_get_enabled_payment_gateways());
474 $gatewaysMap = [
475 'stripe' => StripePaymentElementGateway::id(),
476 ];
477
478 if ($gateways) {
479 foreach (array_keys($gateways) as $gatewayId) {
480 $v3GatewayId = $gatewayId;
481 if (array_key_exists($gatewayId, $gatewaysMap)) {
482 $v3GatewayId = $gatewaysMap[$gatewayId];
483 }
484
485 $perGatewaySettings[$v3GatewayId] = [
486 'enabled' => $this->getMeta('_form_gateway_fee_enable_' . $gatewayId) === 'enabled',
487 'feePercentage' => (float)$this->getMeta('_form_gateway_fee_percentage_' . $gatewayId, 2.9),
488 'feeBaseAmount' => (float)$this->getMeta('_form_gateway_fee_base_amount_' . $gatewayId, 0.30),
489 'maxFeeAmount' => (float)$this->getMeta(
490 '_form_gateway_fee_maximum_fee_amount_' . $gatewayId,
491 give_format_decimal(['amount' => '0.00'])
492 ),
493 ];
494 }
495 }
496
497 return [
498 'useGlobalSettings' => false,
499 'feeSupportForAllGateways' => $this->getMeta('_form_give_fee_configuration') === 'all_gateways',
500 'perGatewaySettings' => $perGatewaySettings,
501 'feePercentage' => (float)$this->getMeta('_form_give_fee_percentage'),
502 'feeBaseAmount' => (float)$this->getMeta('_form_give_fee_base_amount'),
503 'maxFeeAmount' => (float)$this->getMeta('_form_give_fee_maximum_fee_amount'),
504 'includeInDonationSummary' => $this->getMeta('_form_breakdown') === 'enabled',
505 'donorOptIn' => $this->getMeta('_form_give_fee_mode') === 'donor_opt_in',
506 'feeCheckboxLabel' => $this->getMeta('_form_give_fee_checkbox_label'),
507 'feeMessage' => $this->getMeta('_form_give_fee_explanation'),
508 ];
509 }
510
511 /**
512 * Retrieves metadata for the current form.
513 *
514 * This method acts as a wrapper for the give_get_meta function, reducing redundancy
515 * and improving code readability when fetching metadata related to the current form.
516 *
517 * @since 3.0.0
518 *
519 * @param string $key
520 * @param mixed $default
521 * @return mixed
522 */
523 private function getMeta(string $key, $default = null)
524 {
525 return give_get_meta($this->form->id, $key, true, $default);
526 }
527 }
528