Update
This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
|
||||
class SubscriptionHelper
|
||||
{
|
||||
public static function handleSubscriptionWebhookEvents(WebhookReceived $event)
|
||||
public static function handleWebhookEvents(WebhookReceived $event)
|
||||
{
|
||||
switch ($event->payload['type']) {
|
||||
switch (StripeHelper::getEventType($event)) {
|
||||
case 'customer.subscription.created':
|
||||
case 'customer.subscription.updated':
|
||||
self::handleSubscriptionUpsert($event);
|
||||
@@ -25,7 +25,7 @@ public static function handleSubscriptionWebhookEvents(WebhookReceived $event)
|
||||
|
||||
private static function handleSubscriptionUpsert(WebhookReceived $event)
|
||||
{
|
||||
$object = $event->payload['data']['object'];
|
||||
$object = StripeHelper::getEventObject($event);
|
||||
|
||||
// dump($object);
|
||||
|
||||
@@ -83,6 +83,34 @@ private static function handleSubscriptionUpsert(WebhookReceived $event)
|
||||
|
||||
private static function handleSubscriptionDelete(WebhookReceived $event)
|
||||
{
|
||||
// /
|
||||
$object = StripeHelper::getEventObject($event);
|
||||
|
||||
$user = StripeHelper::getUserByStripeID($object['customer']);
|
||||
|
||||
if ($user) {
|
||||
|
||||
$plan = Plan::where('tier', 'free')->first();
|
||||
|
||||
if ($plan) {
|
||||
$user_plan = UserPlan::where('user_id', $user->id)->first();
|
||||
|
||||
if ($user_plan) {
|
||||
$user_plan->update([
|
||||
'plan_id' => $plan->id,
|
||||
'current_period_end' => null,
|
||||
'cancel_at' => null,
|
||||
'canceled_at' => null,
|
||||
]);
|
||||
} else {
|
||||
$user_plan = UserPlan::create([
|
||||
'user_id' => $user->id,
|
||||
'plan_id' => $plan->id,
|
||||
'current_period_end' => null,
|
||||
'cancel_at' => null,
|
||||
'canceled_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user