Actions
2 years ago
Concerns
9 months ago
Contracts
3 years ago
Exceptions
2 years ago
Facades
4 years ago
LegacyNodes
3 years ago
Properties
1 year ago
ValueObjects
2 years ago
Amount.php
2 years ago
Authentication.php
1 year ago
BillingAddress.php
2 years ago
Checkbox.php
2 years ago
Consent.php
2 years ago
Date.php
1 year ago
DonationAmount.php
2 years ago
DonationForm.php
2 years ago
DonationSummary.php
2 years ago
Element.php
3 years ago
Email.php
2 years ago
Factory.php
4 years ago
Field.php
2 years ago
File.php
1 year ago
Form.php
3 years ago
Group.php
3 years ago
Hidden.php
3 years ago
Honeypot.php
1 year ago
Html.php
3 years ago
MultiSelect.php
1 year ago
Name.php
2 years ago
Option.php
2 years ago
Paragraph.php
2 years ago
Password.php
2 years ago
PaymentGateways.php
2 years ago
Phone.php
1 year ago
Radio.php
2 years ago
Section.php
2 years ago
SecurityChallenge.php
1 year ago
Select.php
2 years ago
Text.php
2 years ago
Textarea.php
2 years ago
Types.php
2 years ago
Url.php
2 years ago
Amount.php
117 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Give\Framework\FieldsAPI; |
| 6 | |
| 7 | use Give\Framework\FieldsAPI\Concerns\HasLabel; |
| 8 | |
| 9 | class Amount extends Field |
| 10 | { |
| 11 | use HasLabel; |
| 12 | |
| 13 | const TYPE = 'amount'; |
| 14 | |
| 15 | /** |
| 16 | * @var array ['label' => string, 'value' => int, 'checked' => bool] |
| 17 | */ |
| 18 | protected $levels = []; |
| 19 | /** |
| 20 | * @var string |
| 21 | */ |
| 22 | protected $customAmountText; |
| 23 | |
| 24 | /** |
| 25 | * @var bool |
| 26 | */ |
| 27 | protected $allowCustomAmount = false; |
| 28 | /** |
| 29 | * @var bool |
| 30 | */ |
| 31 | protected $allowLevels = false; |
| 32 | |
| 33 | /** |
| 34 | * @var float|int |
| 35 | */ |
| 36 | protected $fixedAmountValue; |
| 37 | |
| 38 | /** |
| 39 | * Set the preset donation levels. Provide level amounts in minor units. |
| 40 | * |
| 41 | * @since 3.12.0 Changed to receive an array as a parameter. |
| 42 | * @since 3.0.0 |
| 43 | */ |
| 44 | public function levels(array ...$levels): self |
| 45 | { |
| 46 | $this->levels = $levels; |
| 47 | |
| 48 | return $this; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @since 3.0.0 |
| 53 | */ |
| 54 | public function getLevels(): array |
| 55 | { |
| 56 | return $this->levels; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @since 3.0.0 |
| 61 | */ |
| 62 | public function allowCustomAmount($allow = true): self |
| 63 | { |
| 64 | $this->allowCustomAmount = $allow; |
| 65 | |
| 66 | return $this; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @since 3.0.0 |
| 71 | */ |
| 72 | public function allowLevels($allow = true): self |
| 73 | { |
| 74 | $this->allowLevels = $allow; |
| 75 | |
| 76 | return $this; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @since 3.0.0 |
| 81 | */ |
| 82 | public function customAmountAllowed(): bool |
| 83 | { |
| 84 | return $this->allowCustomAmount; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @since 3.0.0 |
| 89 | */ |
| 90 | public function customAmountText(string $customAmountText): Amount |
| 91 | { |
| 92 | $this->customAmountText = $customAmountText; |
| 93 | |
| 94 | return $this; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @since 3.0.0 |
| 99 | * |
| 100 | * @param float|int $amount |
| 101 | */ |
| 102 | public function fixedAmountValue($amount): Amount |
| 103 | { |
| 104 | $this->fixedAmountValue = $amount; |
| 105 | |
| 106 | return $this; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @since 3.0.0 |
| 111 | */ |
| 112 | public function getFixedAmountValue() |
| 113 | { |
| 114 | return $this->fixedAmountValue; |
| 115 | } |
| 116 | } |
| 117 |