Hello,
I am looking for a way to extend what the Cashier package for Stripe does when handling a subscription creation in the src/Http/Controllers/WebhookController.php.
Essentially what happens is something like this:
$subscription = $user->subscriptions()->create([
'name' => $data['metadata']['name'] ?? $this->newSubscriptionName($payload),
'stripe_id' => $data['id'],
'stripe_status' => $data['status'],
'stripe_price' => $isSinglePrice ? $firstItem['price']['id'] : null,
'quantity' => $isSinglePrice && isset($firstItem['quantity']) ? $firstItem['quantity'] : null,
'trial_ends_at' => $trialEndsAt,
'ends_at' => null,
]);
foreach ($data['items']['data'] as $item) {
$subscription->items()->create([
'stripe_id' => $item['id'],
'stripe_product' => $item['price']['product'],
'stripe_price' => $item['price']['id'],
'quantity' => $item['quantity'] ?? null,
]);
}
Now I would like to extend that to add more fields from Stripe subscription object. I would like to have current period start and end dates as I need to report usage.
My plan is as follows:
- Drag in that extra period data.
- Collect usage locally.
- Last day of the billing period fire API calls to update the usage on stripe. Maybe a day before just to be on the safe side. Not important right now.
For that I would like to have those dates. Now I can see how I could possibly just write my own controller and extend Webhookone and then override the route and all that. However I can't help but wonder if there is a less messy or annoying way of doing that?
The only other thing I can think of is if I would ditch Cashier (which seems to be super tempting right now) and create my own integration.
What do you think?
Rob