Based on the question description, it seems that the user is facing several issues with Spark 4.x webhooks and the 'default' plan. Here's a solution to each problem mentioned:
- Issue with webhooks and updating subscriptions:
It appears that the webhooks are being logged, but the subscriptions table is not getting updated. To resolve this, you need to manually create listeners and add methods for updating subscriptions and subscription items. The
artisan cashier:webhook --urlcommand is not suitable for a development environment. Here's an example of how you can create a listener and update the subscriptions table:
// Create a new listener for the subscription webhook events
php artisan make:listener SubscriptionUpdatedListener
// In the created listener class, handle the subscription updated event
public function handle(SubscriptionUpdated $event)
{
// Update the subscriptions table with the new subscription status
$subscription = $event->subscription;
$subscription->user->personalTeam()->subscription()->update([
'stripe_status' => $subscription->stripe_status,
]);
}
- Issue with retrieving plan details using
sparkPlan(): ThesparkPlan()method does not populate the trial days, price, or other plan details. To retrieve the plan details, you can use theplan()method instead. Here's an example:
$plan = $this->user->personalTeam()->subscription()->plan();
$plan->id; // Get the plan ID
$plan->name; // Get the plan name
$plan->interval; // Get the plan interval
// Retrieve other plan details as needed
- Issue with plan names always being 'default':
It seems that the subscription('default') has been hard-coded in the
CreateSubscriptionaction, causing all plans to have the name 'default'. This means you can only have one subscription per model since changing subscriptions replaces the 'default' subscription. To have different plan names, you need to modify theCreateSubscriptionaction and pass the desired plan name when creating a subscription. Here's an example:
$team->newSubscription('subscription-name', 'plan-id')->create();
Make sure to replace 'subscription-name' with the desired name for the subscription and 'plan-id' with the actual plan ID from Stripe.
Regarding the possibility of the cookbook being out of date, it's recommended to refer to the official Laravel Spark documentation and the Laravel Cashier documentation for the most up-to-date information.
Remember to adjust the code examples according to your specific implementation and requirements.