CurrencySwitcherSetting.php
123 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI\Properties\DonationForm; |
| 4 | |
| 5 | use JsonSerializable; |
| 6 | |
| 7 | /** |
| 8 | * @since 3.0.0 |
| 9 | */ |
| 10 | class CurrencySwitcherSetting implements JsonSerializable |
| 11 | { |
| 12 | /** |
| 13 | * @var string |
| 14 | */ |
| 15 | protected $id; |
| 16 | /** |
| 17 | * @var float |
| 18 | */ |
| 19 | protected $exchangeRate; |
| 20 | /** |
| 21 | * @var string[] |
| 22 | */ |
| 23 | protected $gateways = []; |
| 24 | /** |
| 25 | * @var int |
| 26 | */ |
| 27 | protected $exchangeRateFractionDigits; |
| 28 | |
| 29 | /** |
| 30 | * @since 3.0.0 |
| 31 | */ |
| 32 | public function __construct( |
| 33 | string $id, |
| 34 | float $exchangeRate = 0, |
| 35 | array $gateways = [], |
| 36 | int $exchangeRateFractionDigits = 2 |
| 37 | ) { |
| 38 | $this->id = $id; |
| 39 | $this->exchangeRate = $exchangeRate; |
| 40 | $this->gateways = $gateways; |
| 41 | $this->exchangeRateFractionDigits = $exchangeRateFractionDigits; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @since 3.0.0 |
| 46 | */ |
| 47 | public function jsonSerialize() |
| 48 | { |
| 49 | return get_object_vars($this); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @since 3.0.0 |
| 54 | */ |
| 55 | public function id(string $id): CurrencySwitcherSetting |
| 56 | { |
| 57 | $this->id = $id; |
| 58 | |
| 59 | return $this; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @since 3.0.0 |
| 64 | */ |
| 65 | public function getId(): string |
| 66 | { |
| 67 | return $this->id; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @since 3.0.0 |
| 72 | */ |
| 73 | public function exchangeRate(float $rate): CurrencySwitcherSetting |
| 74 | { |
| 75 | $this->exchangeRate = $rate; |
| 76 | |
| 77 | return $this; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @since 3.0.0 |
| 82 | */ |
| 83 | public function getExchangeRate(): float |
| 84 | { |
| 85 | return $this->exchangeRate; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @since 3.0.0 |
| 90 | */ |
| 91 | public function exchangeRateFractionDigits(int $exchangeRateFractionDigits): CurrencySwitcherSetting |
| 92 | { |
| 93 | $this->exchangeRateFractionDigits = $exchangeRateFractionDigits; |
| 94 | |
| 95 | return $this; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @since 3.0.0 |
| 100 | */ |
| 101 | public function getExchangeRateFractionDigits(): int |
| 102 | { |
| 103 | return $this->exchangeRateFractionDigits; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @since 3.0.0 |
| 108 | */ |
| 109 | public function gateways(array $gateways): CurrencySwitcherSetting |
| 110 | { |
| 111 | $this->gateways = $gateways; |
| 112 | |
| 113 | return $this; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @return array|string[] |
| 118 | */ |
| 119 | public function getGateways(): array |
| 120 | { |
| 121 | return $this->gateways; |
| 122 | } |
| 123 | } |