Skip to content

Commit eb820c9

Browse files
committed
Add current period start and end to StripeSubscriptionItem (#69)
1 parent 12355c5 commit eb820c9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ f5037b59ad70b9cec45fda109e63af97ba610cf0
3737
1b1e37e7f6d565e758ec33a47f33bcb38c67f2a7
3838
5e45268b58773ec58cfc871ff3298590897132a1
3939
426268d51a96299fea45ba3059e8f9c2a04e777d
40+
9b456f26dc1b90e64097086295c9f17da98b40ab

src/php/Objects/Subscription/StripeSubscription.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ private static function extractItems(Subscription $stripeSubscription): ?Collect
172172
$subscriptionItem = $subscriptionItem->withMetadata($item->metadata->toArray());
173173
}
174174

175+
$currentPeriodStart = self::timestampToCarbon($item->current_period_start ?? null);
176+
if (!is_null($currentPeriodStart)) {
177+
$subscriptionItem = $subscriptionItem->withCurrentPeriodStart($currentPeriodStart);
178+
}
179+
180+
$currentPeriodEnd = self::timestampToCarbon($item->current_period_end ?? null);
181+
if (!is_null($currentPeriodEnd)) {
182+
$subscriptionItem = $subscriptionItem->withCurrentPeriodEnd($currentPeriodEnd);
183+
}
184+
175185
$items[] = $subscriptionItem;
176186
}
177187

@@ -281,7 +291,7 @@ public function toArray(): array
281291
{
282292
$items = null;
283293
if ($this->items instanceof Collection) {
284-
$items = $this->items->map(fn (StripeSubscriptionItem $item): array => $item->toArray())->all();
294+
$items = $this->items->map(fn(StripeSubscriptionItem $item): array => $item->toArray())->all();
285295
}
286296

287297
$array = [

0 commit comments

Comments
 (0)