added registration bonus notification

This commit is contained in:
Čarodej
2022-03-12 09:34:26 +01:00
parent ab03b471f7
commit 2bba6dc051
30 changed files with 152 additions and 96 deletions
@@ -2,6 +2,7 @@
namespace App\Users\Actions;
use App\Users\Models\User;
use App\Users\Notifications\RegistrationBonusAddedNotification;
use VueFileManager\Subscription\Domain\Plans\Models\Plan;
class AutoSubscribeForMeteredBillingAction
@@ -36,6 +37,11 @@ class AutoSubscribeForMeteredBillingAction
'currency' => $plan->currency,
'amount' => $settings['registration_bonus_amount'],
]);
// Send user bonus notification
$bonus = format_currency($settings['registration_bonus_amount'], $plan->currency);
$user->notify(new RegistrationBonusAddedNotification($bonus));
} else {
// Create balance with 0 amount
$user->balance()->create([
@@ -0,0 +1,41 @@
<?php
namespace App\Users\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
class RegistrationBonusAddedNotification extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(
public string $bonus
) {
}
/**
* Get the notification's delivery channels.
*/
public function via(mixed $notifiable): array
{
return ['database'];
}
/**
* Get the array representation of the notification.
*/
public function toArray(mixed $notifiable): array
{
return [
'category' => 'gift',
'title' => "You Received {$this->bonus}",
'description' => "You received credit bonus $this->bonus for your registration. Happy spending!",
];
}
}