1. Go to this page and download the library: Download sepayvn/laravel-sepay library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Listeners;
use App\Models\User;
use SePay\SePay\Events\SePayWebhookEvent;
use SePay\SePay\Notifications\SePayTopUpSuccessNotification;
class SePayWebhookListener
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(SePayWebhookEvent $event): void
{
// Xử lý tiền vào tài khoản
if ($event->sePayWebhookData->transferType === 'in') {
// Trường hợp $info là user id
$user = User::query()->where('id', $event->info)->first();
if ($user instanceof User) {
$user->notify(new SePayTopUpSuccessNotification($event->sePayWebhookData));
}
} else {
// Xử lý tiền ra tài khoản
}
}
}
public function boot(): void
{
\Illuminate\Support\Facades\Event::listen(
\SePay\SePay\Events\SePayWebhookEvent::class,
\App\Listeners\SePayWebhookListener::class,
);
}