Skip to content

Commit

Permalink
feat: Revert changes to support optional properties
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston-paddle committed Oct 16, 2024
1 parent 217cad0 commit 21202d5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
6 changes: 2 additions & 4 deletions src/Notifications/Entities/Adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand All @@ -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,
);
Expand Down
24 changes: 3 additions & 21 deletions src/Notifications/Entities/Shared/PayoutTotalsAdjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand All @@ -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,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 21202d5

Please sign in to comment.