Skip to content

Commit

Permalink
fix: Map subscription transaction adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeymike committed Feb 6, 2024
1 parent 05ecdae commit a7e3458
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 254 deletions.
9 changes: 9 additions & 0 deletions src/Entities/Shared/AdjustmentItemTotals.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ public function __construct(
public string $total,
) {
}

public static function from(array $data): self
{
return new self(
subtotal: $data['subtotal'],
tax: $data['tax'],
total: $data['total'],
);
}
}
21 changes: 21 additions & 0 deletions src/Entities/Subscription/SubscriptionAdjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Paddle\SDK\Entities\Subscription;

use Paddle\SDK\Entities\DateTime;
use Paddle\SDK\Entities\Shared\Action;
use Paddle\SDK\Entities\Shared\CurrencyCode;
use Paddle\SDK\Entities\Shared\PayoutTotalsAdjustment;
Expand Down Expand Up @@ -39,4 +40,24 @@ public function __construct(
public \DateTimeInterface $updatedAt,
) {
}

public static function from(array $data): self
{
return new self(
id: $data['id'],
action: Action::from($data['action']),
transactionId: $data['transaction_id'],
subscriptionId: $data['subscription_id'],
customerId: $data['customer_id'],
reason: $data['reason'],
creditAppliedToBalance: $data['credit_applied_to_balance'],
currencyCode: CurrencyCode::from($data['currency_code']),
status: StatusAdjustment::from($data['status']),
items: array_map(fn (array $item) => SubscriptionAdjustmentItem::from($item), $data['items']),
totals: TotalAdjustments::from($data['totals']),
payoutTotals: PayoutTotalsAdjustment::from($data['payout_totals']),
createdAt: DateTime::from($data['created_at']),
updatedAt: DateTime::from($data['updated_at']),
);
}
}
11 changes: 11 additions & 0 deletions src/Entities/Subscription/SubscriptionAdjustmentItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,15 @@ public function __construct(
public AdjustmentItemTotals $totals,
) {
}

public static function from(array $data): self
{
return new self(
itemId: $data['item_id'],
type: AdjustmentType::from($data['type']),
amount: $data['amount'] ?? null,
proration: SubscriptionProration::from($data['proration']),
totals: AdjustmentItemTotals::from($data['totals']),
);
}
}
9 changes: 9 additions & 0 deletions src/Entities/Subscription/SubscriptionAdjustmentPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ public function __construct(
public TotalAdjustments $totals,
) {
}

public static function from(array $data): self
{
return new self(
transactionId: $data['transaction_id'],
items: array_map(fn (array $item) => SubscriptionAdjustmentItem::from($item), $data['items']),
totals: TotalAdjustments::from($data['totals']),
);
}
}
5 changes: 4 additions & 1 deletion src/Entities/Subscription/SubscriptionNextTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public static function from(array $data): self
return new self(
billingPeriod: SubscriptionTimePeriod::from($data['billing_period']),
details: TransactionDetailsPreview::from($data['details']),
adjustments: [],
adjustments: array_map(
fn (array $adjustment) => SubscriptionAdjustmentPreview::from($adjustment),
$data['adjustments'],
),
);
}
}
2 changes: 1 addition & 1 deletion src/Entities/SubscriptionTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static function from(array $data): self
address: Address::from($data['address']),
business: Business::from($data['business']),
discount: Discount::from($data['discount']),
adjustments: $data['adjustments'],
adjustments: array_map(fn (array $adjustment) => SubscriptionAdjustment::from($adjustment), $data['adjustments']),
);
}
}
Loading

0 comments on commit a7e3458

Please sign in to comment.