This commit is contained in:
ct
2025-07-03 00:48:06 +08:00
parent 0aa0d9569f
commit db892fc4f5
26 changed files with 807 additions and 59 deletions

View File

@@ -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,
]);
}
}
}
}
}