Actions
2 years ago
Concerns
2 years ago
Contracts
3 years ago
Exceptions
2 years ago
Facades
4 years ago
LegacyNodes
3 years ago
Properties
2 years ago
ValueObjects
2 years ago
Amount.php
2 years ago
Authentication.php
2 years ago
BillingAddress.php
2 years ago
Checkbox.php
2 years ago
Consent.php
2 years ago
Date.php
2 years 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
2 years ago
Form.php
3 years ago
Group.php
3 years ago
Hidden.php
3 years ago
Html.php
3 years ago
MultiSelect.php
2 years ago
Name.php
2 years ago
Option.php
3 years ago
Paragraph.php
2 years ago
Password.php
2 years ago
PaymentGateways.php
2 years ago
Phone.php
2 years ago
Radio.php
2 years ago
Section.php
2 years 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
116 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 int[] |
| 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 levels in minor units. |
| 40 | * |
| 41 | * @since 3.0.0 |
| 42 | */ |
| 43 | public function levels(float ...$levels): self |
| 44 | { |
| 45 | $this->levels = $levels; |
| 46 | |
| 47 | return $this; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @since 3.0.0 |
| 52 | */ |
| 53 | public function getLevels(): array |
| 54 | { |
| 55 | return $this->levels; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @since 3.0.0 |
| 60 | */ |
| 61 | public function allowCustomAmount($allow = true): self |
| 62 | { |
| 63 | $this->allowCustomAmount = $allow; |
| 64 | |
| 65 | return $this; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @since 3.0.0 |
| 70 | */ |
| 71 | public function allowLevels($allow = true): self |
| 72 | { |
| 73 | $this->allowLevels = $allow; |
| 74 | |
| 75 | return $this; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @since 3.0.0 |
| 80 | */ |
| 81 | public function customAmountAllowed(): bool |
| 82 | { |
| 83 | return $this->allowCustomAmount; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @since 3.0.0 |
| 88 | */ |
| 89 | public function customAmountText(string $customAmountText): Amount |
| 90 | { |
| 91 | $this->customAmountText = $customAmountText; |
| 92 | |
| 93 | return $this; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @since 3.0.0 |
| 98 | * |
| 99 | * @param float|int $amount |
| 100 | */ |
| 101 | public function fixedAmountValue($amount): Amount |
| 102 | { |
| 103 | $this->fixedAmountValue = $amount; |
| 104 | |
| 105 | return $this; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @since 3.0.0 |
| 110 | */ |
| 111 | public function getFixedAmountValue() |
| 112 | { |
| 113 | return $this->fixedAmountValue; |
| 114 | } |
| 115 | } |
| 116 |