From 21202d5d0594c3d3bc7eb601bbdc0a2043f8188c Mon Sep 17 00:00:00 2001 From: David Grayston Date: Wed, 16 Oct 2024 23:20:11 +0100 Subject: [PATCH] feat: Revert changes to support optional properties --- src/Notifications/Entities/Adjustment.php | 6 ++--- .../Shared/PayoutTotalsAdjustment.php | 24 +++---------------- .../request/adjustment_updated_payload.json | 7 ++++++ .../_fixtures/request/update_full.json | 9 ++++++- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/Notifications/Entities/Adjustment.php b/src/Notifications/Entities/Adjustment.php index 0865628..ec4e291 100644 --- a/src/Notifications/Entities/Adjustment.php +++ b/src/Notifications/Entities/Adjustment.php @@ -38,7 +38,7 @@ private function __construct( public array $items, public AdjustmentTotals $totals, public PayoutTotalsAdjustment|null $payoutTotals, - public array|null $taxRatesUsed, + public array $taxRatesUsed, public \DateTimeInterface $createdAt, public \DateTimeInterface|null $updatedAt, ) { @@ -59,9 +59,7 @@ public static function from(array $data): self items: array_map(fn (array $item): AdjustmentItem => AdjustmentItem::from($item), $data['items']), totals: AdjustmentTotals::from($data['totals']), payoutTotals: isset($data['payout_totals']) ? PayoutTotalsAdjustment::from($data['payout_totals']) : null, - taxRatesUsed: isset($data['tax_rates_used']) - ? array_map(fn (array $taxRateUsed): AdjustmentTaxRatesUsed => AdjustmentTaxRatesUsed::from($taxRateUsed), $data['tax_rates_used'] ?? []) - : null, + taxRatesUsed: array_map(fn (array $taxRateUsed): AdjustmentTaxRatesUsed => AdjustmentTaxRatesUsed::from($taxRateUsed), $data['tax_rates_used'] ?? []), createdAt: DateTime::from($data['created_at']), updatedAt: isset($data['updated_at']) ? DateTime::from($data['updated_at']) : null, ); diff --git a/src/Notifications/Entities/Shared/PayoutTotalsAdjustment.php b/src/Notifications/Entities/Shared/PayoutTotalsAdjustment.php index eee9407..551c994 100644 --- a/src/Notifications/Entities/Shared/PayoutTotalsAdjustment.php +++ b/src/Notifications/Entities/Shared/PayoutTotalsAdjustment.php @@ -11,19 +11,14 @@ namespace Paddle\SDK\Notifications\Entities\Shared; -use Paddle\SDK\FiltersUndefined; -use Paddle\SDK\Undefined; - -class PayoutTotalsAdjustment implements \JsonSerializable +class PayoutTotalsAdjustment { - use FiltersUndefined; - private function __construct( public string $subtotal, public string $tax, public string $total, public string $fee, - public ChargebackFee|Undefined|null $chargebackFee, + public ChargebackFee|null $chargebackFee, public string $earnings, public CurrencyCodePayouts $currencyCode, ) { @@ -36,22 +31,9 @@ public static function from(array $data): self tax: $data['tax'], total: $data['total'], fee: $data['fee'], - chargebackFee: isset($data['chargeback_fee']) ? ChargebackFee::from($data['chargeback_fee']) : new Undefined(), + chargebackFee: isset($data['chargeback_fee']) ? ChargebackFee::from($data['chargeback_fee']) : null, earnings: $data['earnings'], currencyCode: CurrencyCodePayouts::from($data['currency_code']), ); } - - public function jsonSerialize(): array - { - return $this->filterUndefined([ - 'subtotal' => $this->subtotal, - 'tax' => $this->tax, - 'total' => $this->total, - 'fee' => $this->fee, - 'chargeback_fee' => $this->chargebackFee, - 'earnings' => $this->earnings, - 'currency_code' => $this->currencyCode, - ]); - } } diff --git a/tests/Functional/Resources/Simulations/_fixtures/request/adjustment_updated_payload.json b/tests/Functional/Resources/Simulations/_fixtures/request/adjustment_updated_payload.json index 2b29687..3ec5b3d 100644 --- a/tests/Functional/Resources/Simulations/_fixtures/request/adjustment_updated_payload.json +++ b/tests/Functional/Resources/Simulations/_fixtures/request/adjustment_updated_payload.json @@ -31,6 +31,13 @@ "currency_code": "USD" }, "payout_totals": { + "chargeback_fee": { + "amount": "1", + "original": { + "amount": "2", + "currency_code": "USD" + } + }, "subtotal": "92", "tax": "8", "total": "100", diff --git a/tests/Functional/Resources/Simulations/_fixtures/request/update_full.json b/tests/Functional/Resources/Simulations/_fixtures/request/update_full.json index 6485a62..d9623f3 100644 --- a/tests/Functional/Resources/Simulations/_fixtures/request/update_full.json +++ b/tests/Functional/Resources/Simulations/_fixtures/request/update_full.json @@ -8,7 +8,7 @@ "action": "refund", "transaction_id": "txn_01hvcc93znj3mpqt1tenkjb04y", "subscription_id": "sub_01hvccbx32q2gb40sqx7n42430", - "tax_rates_used": null, + "tax_rates_used": [], "customer_id": "ctm_01hrffh7gvp29kc7xahm8wddwa", "reason": "error", "credit_applied_to_balance": null, @@ -37,6 +37,13 @@ "currency_code": "USD" }, "payout_totals": { + "chargeback_fee": { + "amount": "1", + "original": { + "amount": "2", + "currency_code": "USD" + } + }, "subtotal": "92", "tax": "8", "total": "100",