diff --git a/app/Listeners/StripeEventListener.php b/app/Listeners/StripeEventListener.php index 3c4e568..1689261 100644 --- a/app/Listeners/StripeEventListener.php +++ b/app/Listeners/StripeEventListener.php @@ -2,6 +2,7 @@ namespace App\Listeners; +use App\NotifyMe; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; @@ -11,6 +12,7 @@ use Livewire\Livewire; class StripeEventListener { + use NotifyMe; /** * Create the event listener. */ @@ -27,11 +29,26 @@ class StripeEventListener if ($event->payload['type'] === 'invoice.payment_succeeded') { session()->flash('alert', ['type' => 'success', 'message' => 'Payment completed successfully.']); Log::info('Payment succeeded'); + $amount = $event->payload['data']['object']['amount_paid'] / 100 ?? 'Unknown'; // Convert cents to dollars + $email = $event->payload['data']['object']['customer_email'] ?? 'Unknown'; + + $message = "✅ Payment Success\n" . + "Email: {$email}\n" . + "Amount: $" . number_format($amount, 2) . "\n" . + "Time: " . now()->toDateTimeString(); + self::sendTelegramNotification($message); } if ($event->payload['type'] === 'customer.subscription.deleted') { session()->flash('alert', ['type' => 'error', 'message' => 'Subscription canceled.']); Log::info('Subscription canceled'); + + $email = $event->payload['data']['object']['customer_email'] ?? 'Unknown'; + + $message = "❌ Subscription Canceled\n" . + "Email: {$email}\n" . + "Time: " . now()->toDateTimeString(); + self::sendTelegramNotification($message); } } } diff --git a/app/NotifyMe.php b/app/NotifyMe.php new file mode 100644 index 0000000..3aad07c --- /dev/null +++ b/app/NotifyMe.php @@ -0,0 +1,32 @@ + $chatId, + 'text' => $message, + 'parse_mode' => 'HTML' + ]; + + try { + $response = \Http::post($url, $data); + return $response->successful(); + } catch (\Exception $e) { + \Log::error('Failed to send Telegram notification: ' . $e->getMessage()); + return false; + } + } +} diff --git a/config/app.php b/config/app.php index 6b767e9..d89527b 100644 --- a/config/app.php +++ b/config/app.php @@ -36,6 +36,9 @@ return [ 'move_or_delete' => env('MOVE_OR_DELETE', null), 'auto_fetch_mail' => env('AUTO_FETCH_MAIL', false), + 'notify_tg_bot_token' => env('NOTIFY_TG_BOT_TOKEN', ''), + 'notify_tg_chat_id' => env('NOTIFY_TG_CHAT_ID', ''), + /* |-------------------------------------------------------------------------- | Application Debug Mode