dunning implementation of the notifications

This commit is contained in:
Čarodej
2022-06-09 18:08:49 +02:00
parent f3bfe9a0cc
commit 9bc8a9b27c
4 changed files with 113 additions and 2 deletions

View File

@@ -267,6 +267,19 @@ return [
'synchronizing_plans' => 'Synchronizing Plans...',
'plans_are_synchronizing' => 'Your plans are synchronizing with the payment gateways',
'plans_was_synchronized' => 'Plans was successfully synchronized',
'limit_usage_in_new_accounts_1_subject' => 'Please make first payment for your account to fund your usage',
'limit_usage_in_new_accounts_1_line' => 'We are happy you are using our service. To continue to using our service, please make first payment for your account balance to fund your usage.',
'limit_usage_in_new_accounts_2_subject' => '📆 Reminder: Please make first payment for your account to fund your usage',
'limit_usage_in_new_accounts_2_line' => 'We are happy you are using our service. To continue to using our service, please make first payment for your account balance to fund your usage.',
'limit_usage_in_new_accounts_3_subject' => '‼️ Uh-oh! Your functionality was restricted. Please make payment to continue using your account',
'limit_usage_in_new_accounts_3_line' => 'We are sorry for the inconvenience with using our service. To continue to using our service, please make first payment for your account balance to fund your usage and your functionality will be allowed as soon as possible.',
'usage_bigger_than_balance_1_subject' => "⚠️ You don't have sufficient funds in your account, please increase your account balance",
'usage_bigger_than_balance_1_line' => 'We are happy you are using our service. To continue to using our service, please increase your funds for your account balance to cover your usage.',
'usage_bigger_than_balance_2_subject' => "📆 Reminder: You don't have sufficient funds in your account, please increase your account balance",
'usage_bigger_than_balance_2_line' => 'We are happy you are using our service. To continue to using our service, please increase your funds for your account balance to cover your usage.',
'usage_bigger_than_balance_3_subject' => '‼️ Uh-oh! Your functionality was restricted. Please increase your funds for your account balance to cover your usage',
'usage_bigger_than_balance_3_line' => 'We are sorry for the inconvenience with using our service. To continue to using our service, please increase your funds for your account balance to cover your usage and your functionality will be allowed as soon as possible.',
'dunning_notification_description' => 'Please resolve your billing as soon as possible. Your functions can be restricted.',
],
'regular' => [
'type' => 'Type',

View File

@@ -23,6 +23,7 @@ return [
],
'notifications' => [
'DunningEmailToCoverAccountUsageNotification' => \Domain\Subscriptions\Notifications\DunningEmailToCoverAccountUsageNotification::class,
'ChargeFromCreditCardFailedAgainNotification' => \Domain\Subscriptions\Notifications\ChargeFromCreditCardFailedAgainNotification::class,
'ChargeFromCreditCardFailedNotification' => \Domain\Subscriptions\Notifications\ChargeFromCreditCardFailedNotification::class,
'SubscriptionWasCreatedNotification' => \Domain\Subscriptions\Notifications\SubscriptionWasCreatedNotification::class,
@@ -32,8 +33,18 @@ return [
'BonusCreditAddedNotification' => \Domain\Subscriptions\Notifications\BonusCreditAddedNotification::class,
],
'metered_billing' => [
'metered_billing' => [
'settlement_period' => 30,
'fraud_prevention_mechanism' => [
'usage_bigger_than_balance' => [
'active' => true,
],
'limit_usage_in_new_accounts' => [
'active' => true,
'amount' => 5,
],
],
],
'paystack' => [
@@ -48,4 +59,5 @@ return [
],
'is_demo' => env('APP_DEMO', false),
'is_local' => env('APP_ENV', 'production') === 'local',
];

View File

@@ -19,7 +19,7 @@
class="vue-feather text-theme shrink-0"
/>
<alert-triangle-icon
v-if="['billing-alert', 'insufficient-balance'].includes(notification.data.attributes.category)"
v-if="['billing-alert', 'insufficient-balance', 'payment-alert'].includes(notification.data.attributes.category)"
size="22"
class="vue-feather text-theme shrink-0"
/>

View File

@@ -0,0 +1,86 @@
<?php
namespace Domain\Subscriptions\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use VueFileManager\Subscription\Domain\DunningEmails\Models\Dunning;
class DunningEmailToCoverAccountUsageNotification extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(
private Dunning $dunning
) {
}
public function via(): array
{
return ['mail', 'database', 'broadcast'];
}
public function toMail(): MailMessage
{
$message = $this->dunningMessages();
return (new MailMessage)
->subject($message[$this->dunning->type][$this->dunning->sequence]['subject'])
->greeting(__('Hi there'))
->line($message[$this->dunning->type][$this->dunning->sequence]['line'])
->salutation(__('Regards'));
}
public function toArray(): array
{
$message = $this->dunningMessages();
return [
'category' => 'payment-alert',
'title' => $message[$this->dunning->type][$this->dunning->sequence]['subject'],
'description' => __t('dunning_notification_description'),
'action' => [
'type' => 'route',
'params' => [
'route' => __t('billing'),
'button' => __t('show_billing'),
],
],
];
}
private function dunningMessages(): array
{
return [
'limit_usage_in_new_accounts' => [
[
'subject' => __t('limit_usage_in_new_accounts_1_subject'),
'line' => __t('limit_usage_in_new_accounts_1_line'),
],
[
'subject' => __t('limit_usage_in_new_accounts_2_subject'),
'line' => __t('limit_usage_in_new_accounts_2_line'),
],
[
'subject' => __t('limit_usage_in_new_accounts_3_subject'),
'line' => __t('limit_usage_in_new_accounts_3_line'),
],
],
'usage_bigger_than_balance' => [
[
'subject' => __t("usage_bigger_than_balance_1_subject"),
'line' => __t('usage_bigger_than_balance_1_line'),
],
[
'subject' => __t('usage_bigger_than_balance_2_subject'),
'line' => __t('usage_bigger_than_balance_2_line'),
],
[
'subject' => __t('usage_bigger_than_balance_3_subject'),
'line' => __t('usage_bigger_than_balance_3_line'),
],
],
];
}
}