added notification system for successful payment
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Listeners;
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use App\NotifyMe;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ use Livewire\Livewire;
|
|||||||
|
|
||||||
class StripeEventListener
|
class StripeEventListener
|
||||||
{
|
{
|
||||||
|
use NotifyMe;
|
||||||
/**
|
/**
|
||||||
* Create the event listener.
|
* Create the event listener.
|
||||||
*/
|
*/
|
||||||
@@ -27,11 +29,26 @@ class StripeEventListener
|
|||||||
if ($event->payload['type'] === 'invoice.payment_succeeded') {
|
if ($event->payload['type'] === 'invoice.payment_succeeded') {
|
||||||
session()->flash('alert', ['type' => 'success', 'message' => 'Payment completed successfully.']);
|
session()->flash('alert', ['type' => 'success', 'message' => 'Payment completed successfully.']);
|
||||||
Log::info('Payment succeeded');
|
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') {
|
if ($event->payload['type'] === 'customer.subscription.deleted') {
|
||||||
session()->flash('alert', ['type' => 'error', 'message' => 'Subscription canceled.']);
|
session()->flash('alert', ['type' => 'error', 'message' => 'Subscription canceled.']);
|
||||||
Log::info('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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
app/NotifyMe.php
Normal file
32
app/NotifyMe.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
trait NotifyMe
|
||||||
|
{
|
||||||
|
function sendTelegramNotification($message) {
|
||||||
|
$botToken = config('app.notify_tg_bot_token');
|
||||||
|
$chatId = config('app.notify_tg_chat_id');
|
||||||
|
|
||||||
|
if (!$botToken || !$chatId) {
|
||||||
|
\Log::error('Telegram bot token or chat ID not configured');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = "https://api.telegram.org/bot{$botToken}/sendMessage";
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'chat_id' => $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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,6 +36,9 @@ return [
|
|||||||
'move_or_delete' => env('MOVE_OR_DELETE', null),
|
'move_or_delete' => env('MOVE_OR_DELETE', null),
|
||||||
'auto_fetch_mail' => env('AUTO_FETCH_MAIL', false),
|
'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
|
| Application Debug Mode
|
||||||
|
|||||||
Reference in New Issue
Block a user