Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.0] Refactor webhook responses #722

Merged
merged 1 commit into from
Jul 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/Http/Controllers/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function handleCustomerSubscriptionUpdated(array $payload)
});
}

return new Response('Webhook Handled', 200);
return $this->successMethod();
}

/**
Expand All @@ -125,7 +125,7 @@ protected function handleCustomerSubscriptionDeleted(array $payload)
});
}

return new Response('Webhook Handled', 200);
return $this->successMethod();
}

/**
Expand All @@ -140,7 +140,7 @@ protected function handleCustomerUpdated(array $payload)
$user->updateDefaultPaymentMethodFromStripe();
}

return new Response('Webhook Handled', 200);
return $this->successMethod();
}

/**
Expand All @@ -164,7 +164,7 @@ protected function handleCustomerDeleted(array $payload)
])->save();
}

return new Response('Webhook Handled', 200);
return $this->successMethod();
}

/**
Expand All @@ -175,16 +175,19 @@ 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())
);

Mail::to($user)->send(new ConfirmPayment($user, $payment));
}

return new Response('Webhook Handled', 200);
return $this->successMethod();
}

/**
Expand All @@ -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;
}
Expand Down