Reputation: 33
I was wonder if someone could help point in the right direction with laravels cashier (stripe) webhook.
I want to be able to update a column in the subscription database. I have tried over riding the webhook like the laravel documentation says however i believe what i am trying do isnt going to work because the route is using post when I need to use put/patch.
My code below what i have put in the override controller.
namespace App\Http\Controllers\FrontEnd;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Laravel\Cashier\Http\Controllers\WebhookController;
class StripeWebHookController extends WebHookController
{
public function handleCustomerSubscriptionDeleted( array $payload )
{
$user = $this->getUserByStripeId($payload['data']['object']['customer']);
if ($user) {
$user->subscriptions->filter(function ($subscription) use ($payload) {
return $subscription->stripe_id === $payload['data']['object']['id'];
})->each(function ($subscription) {
$sub = Subscription::where('stripe_id', $subscription->stripe_id)->update([
'url' => '',
]);
$subscription->markAsCancelled();
});
}
return new Response('Webhook Handled', 200);
}
}
so how can i go about doing what i want to do when the event is fired from stripes webhook. Thanks
Upvotes: 1
Views: 1443
Reputation: 33
So someone pointed out i wasn't importing the model for subscription :/ . Now its working as expected.
Upvotes: 0