diff --git a/src/Http/Controllers/WebhookController.php b/src/Http/Controllers/WebhookController.php index 6e98fb31..70f9b3af 100644 --- a/src/Http/Controllers/WebhookController.php +++ b/src/Http/Controllers/WebhookController.php @@ -106,7 +106,7 @@ protected function handleCustomerSubscriptionUpdated(array $payload) }); } - return new Response('Webhook Handled', 200); + return $this->successMethod(); } /** @@ -125,7 +125,7 @@ protected function handleCustomerSubscriptionDeleted(array $payload) }); } - return new Response('Webhook Handled', 200); + return $this->successMethod(); } /** @@ -140,7 +140,7 @@ protected function handleCustomerUpdated(array $payload) $user->updateDefaultPaymentMethodFromStripe(); } - return new Response('Webhook Handled', 200); + return $this->successMethod(); } /** @@ -164,7 +164,7 @@ protected function handleCustomerDeleted(array $payload) ])->save(); } - return new Response('Webhook Handled', 200); + return $this->successMethod(); } /** @@ -175,8 +175,11 @@ protected function handleCustomerDeleted(array $payload) */ protected function handleInvoicePaymentActionRequired(array $payload) { - if (config('cashier.payment_emails') && - $user = $this->getUserByStripeId($payload['data']['object']['customer'])) { + if (! config('cashier.payment_emails')) { + return $this->successMethod(); + } + + if ($user = $this->getUserByStripeId($payload['data']['object']['customer'])) { $payment = new Payment( StripePaymentIntent::retrieve($payload['data']['object']['payment_intent'], Cashier::stripeOptions()) ); @@ -184,7 +187,7 @@ protected function handleInvoicePaymentActionRequired(array $payload) Mail::to($user)->send(new ConfirmPayment($user, $payment)); } - return new Response('Webhook Handled', 200); + return $this->successMethod(); } /** @@ -204,13 +207,24 @@ protected function getUserByStripeId($stripeId) return (new $model)->where('stripe_id', $stripeId)->first(); } + /** + * Handle successful calls on the controller. + * + * @param array $parameters + * @return \Symfony\Component\HttpFoundation\Response + */ + protected function successMethod($parameters = []) + { + return new Response('Webhook Handled', 200); + } + /** * Handle calls to missing methods on the controller. * * @param array $parameters * @return \Symfony\Component\HttpFoundation\Response */ - public function missingMethod($parameters = []) + protected function missingMethod($parameters = []) { return new Response; }