PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
← All changes | src/Framework/Support/ValueObjects/Money.php +24 -1 2.30.04.16.9 View file →
@@ -2,9 +2,11 @@
2 2
3 3 namespace Give\Framework\Support\ValueObjects;
4 4
5 5 use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
6 +use Give\Framework\Support\Contracts\Arrayable;
6 7 use Give\Framework\Support\Currency;
8 +use JsonSerializable;
7 9 use Money\Currency as VendorCurrency;
8 10 use Money\Money as VendorMoney;
9 11
10 12 /**
@@ -10,8 +12,9 @@
10 12 /**
11 13 * A decorator class for the vendor Money class which adds additional formatting and other convenience methods. Try and
12 14 * keep the vendor Money logic in the Currency facade.
13 15 *
16 + * @since 4.0.0 added JsonSerializable interface
14 17 * @since 2.20.0
15 18 *
16 19 * @method bool equals(Money $money )
17 20 * @method Money subtract(Money $money)
@@ -18,9 +21,9 @@
18 21 * @method Money add(Money $money)
19 22 *
20 23 * @mixin VendorMoney
21 24 */
22 -class Money
25 +class Money implements JsonSerializable, Arrayable
23 26 {
24 27 /**
25 28 * @var VendorMoney
26 29 */
@@ -154,6 +157,26 @@
154 157 */
155 158 public static function fromDecimal($amount, string $currency): Money
156 159 {
157 160 return self::fromMoney(Currency::parseFromDecimal($amount, $currency));
161 + }
162 +
163 + /**
164 + * @since 4.0.0
165 + */
166 + public function toArray(): array
167 + {
168 + return [
169 + 'value' => $this->formatToDecimal(),
170 + 'valueInMinorUnits' => $this->formatToMinorAmount(),
171 + 'currency' => $this->amount->getCurrency()->getCode(),
172 + ];
173 + }
174 +
175 + /**
176 + * @since 4.0.0
177 + */
178 + public function jsonSerialize(): array
179 + {
180 + return $this->toArray();
158 181 }
159 182 }