| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\DonationForms\Rules\Concerns; |
| 4 |
|
| 5 |
use function in_array; |
| 6 |
use function is_numeric; |
| 7 |
|
| 8 |
/** |
| 9 |
* Amounts an admin configured on the donation amount block, such as the donation levels or the fixed set |
| 10 |
* price. The custom amount minimum and maximum only constrain what a donor types into the custom amount |
| 11 |
* input, so those amounts are always accepted. |
| 12 |
* |
| 13 |
* @since 4.16.8 |
| 14 |
*/ |
| 15 |
trait HasExemptAmounts |
| 16 |
{ |
| 17 |
/** |
| 18 |
* @since 4.16.8 |
| 19 |
* |
| 20 |
* @var float[] |
| 21 |
*/ |
| 22 |
protected $exemptAmounts = []; |
| 23 |
|
| 24 |
/** |
| 25 |
* @since 4.16.8 |
| 26 |
*/ |
| 27 |
public function exemptAmounts(float ...$amounts): self |
| 28 |
{ |
| 29 |
$this->exemptAmounts = $amounts; |
| 30 |
|
| 31 |
return $this; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* @since 4.16.8 |
| 36 |
* |
| 37 |
* @return float[] |
| 38 |
*/ |
| 39 |
public function getExemptAmounts(): array |
| 40 |
{ |
| 41 |
return $this->exemptAmounts; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* @since 4.16.8 |
| 46 |
* |
| 47 |
* @param mixed $value |
| 48 |
*/ |
| 49 |
protected function isExemptAmount($value): bool |
| 50 |
{ |
| 51 |
return is_numeric($value) && in_array((float)$value, $this->exemptAmounts, true); |
| 52 |
} |
| 53 |
} |
| 54 |
|