PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / ValueObjects / Form / PaymentSettings.php

PaymentSettings.php in The Innovative Form Builder – IvyForms 1.5, at backend/src/ValueObjects/Form/PaymentSettings.php

55 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\ValueObjects\Form;
4
5 use IvyForms\Common\Constants\SupportedCurrencyCodes;
6 use IvyForms\Services\Template\TemplateDefaults;
7
8 /**
9 * Form-level payment display settings (currency for product fields, totals, etc.).
10 */
11 final class PaymentSettings
12 {
13 private string $currency;
14
15 /**
16 * @param array<string, mixed>|null $settings Raw settings (typically already sanitized).
17 */
18 public function __construct($settings = null)
19 {
20 if (!is_array($settings) || empty($settings)) {
21 $settings = TemplateDefaults::getDefaultPaymentSettings();
22 }
23
24 $code = isset($settings['currency'])
25 ? strtoupper(trim((string) $settings['currency']))
26 : SupportedCurrencyCodes::DEFAULT_CODE;
27 $this->currency = SupportedCurrencyCodes::isAllowed($code) ? $code : SupportedCurrencyCodes::DEFAULT_CODE;
28 }
29
30 public function getCurrency(): string
31 {
32 return $this->currency;
33 }
34
35 public function setCurrency(string $code): void
36 {
37 $normalized = strtoupper(trim($code));
38 $this->currency = SupportedCurrencyCodes::isAllowed($normalized)
39 ? $normalized
40 : SupportedCurrencyCodes::DEFAULT_CODE;
41 }
42
43 /**
44 * @return mixed[]
45 */
46 public function toArray(): array
47 {
48 return [
49 'paymentSettings' => [
50 'currency' => $this->currency,
51 ],
52 ];
53 }
54 }
55