mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-13 16:55:01 +00:00
- scheduler command updates
- Order reminder notification
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Console;
|
||||
|
||||
use App\Console\Commands\SetupDevEnvironment;
|
||||
use App\Services\Oasis\OasisService;
|
||||
use App\Services\SchedulerService;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
@@ -26,11 +27,11 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$scheduler = app()->make(SchedulerService::class);
|
||||
$scheduler = resolve(SchedulerService::class);
|
||||
|
||||
$schedule->call(function () use ($scheduler) {
|
||||
$scheduler->delete_expired_shared_links();
|
||||
})->everyMinute();
|
||||
})->everyTenMinutes();
|
||||
|
||||
$schedule->call(function () use ($scheduler) {
|
||||
$scheduler->delete_old_zips();
|
||||
@@ -40,8 +41,13 @@ class Kernel extends ConsoleKernel
|
||||
}
|
||||
})->everySixHours();
|
||||
|
||||
// Oasis Drive
|
||||
$schedule->call(function () {
|
||||
resolve(OasisService::class)->order_reminder();
|
||||
})->hourly();
|
||||
|
||||
// Run queue jobs every minute
|
||||
$schedule->command('queue:work --tries=3')
|
||||
$schedule->command('queue:work --stop-when-empty')
|
||||
->everyMinute()
|
||||
->withoutOverlapping();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Oasis;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Laravel\Cashier\Cashier;
|
||||
|
||||
class ReminderForPaymentRequiredNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param $order
|
||||
* @param $plan
|
||||
*/
|
||||
public function __construct($order, $plan)
|
||||
{
|
||||
$this->order = $order;
|
||||
$this->plan = $plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
$url = url("/platba/{$this->order['id']}");
|
||||
|
||||
$name = $this->plan['product']['name'];
|
||||
$price = Cashier::formatAmount($this->plan['plan']['amount']);
|
||||
$storage = format_gigabytes($this->plan['product']['metadata']['capacity']);
|
||||
|
||||
return (new MailMessage)
|
||||
->subject('🏝 Potvrzeni Objednavky - OasisDrive')
|
||||
->greeting('Vážený zákazníku,')
|
||||
->line('Děkujeme za Vaši objednávku služby Oasis Drive pro bezpečné uložení Vašich firemních dokumentů.')
|
||||
->line("Vámi vybraný tarif: $name - $storage za $price")
|
||||
->line('Připomínáme dokončení aktivace služby a blížící se konec platnosti registračního odkazu:')
|
||||
->action('Pro aktivaci klikněte zde', $url)
|
||||
->line('Po dokončení registrace v odkazu Vám bude služba automaticky aktivována a lze ji ihned využívat.')
|
||||
->line('S pozdravem a přáním hezkého dne')
|
||||
->salutation('Tým Oasis Drive');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Services\Oasis;
|
||||
|
||||
|
||||
use App\Models\Oasis\SubscriptionRequest;
|
||||
use App\Notifications\Oasis\ReminderForPaymentRequiredNotification;
|
||||
use App\Services\StripeService;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class OasisService
|
||||
{
|
||||
/**
|
||||
* Get requested subscription requests and remind via
|
||||
* email to activate order
|
||||
*/
|
||||
public function order_reminder()
|
||||
{
|
||||
SubscriptionRequest::whereStatus('requested')
|
||||
->get()
|
||||
->each(function ($request) {
|
||||
|
||||
// Get diffInHours
|
||||
$diff = Carbon::parse($request->created_at)
|
||||
->diffInHours(Carbon::now());
|
||||
|
||||
// Delete if file is in local storage more than 24 hours
|
||||
if ($diff >= 8) {
|
||||
|
||||
$plan = resolve(StripeService::class)
|
||||
->getPlan($request->requested_plan);
|
||||
|
||||
$request->user->notify(new ReminderForPaymentRequiredNotification(
|
||||
$request, $plan
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,14 @@
|
||||
|
||||
namespace Tests\Feature\Oasis;
|
||||
|
||||
use App\Models\Oasis\SubscriptionRequest;
|
||||
use App\Models\User;
|
||||
use App\Notifications\Oasis\ReminderForPaymentRequiredNotification;
|
||||
use App\Services\Oasis\OasisService;
|
||||
use Carbon\Carbon;
|
||||
use Cartalyst\Stripe\Stripe;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Laravel\Cashier\Subscription;
|
||||
use Notification;
|
||||
use Tests\TestCase;
|
||||
|
||||
class OasisSubscriptionTest extends TestCase
|
||||
@@ -166,4 +170,33 @@ class OasisSubscriptionTest extends TestCase
|
||||
'status' => 'logged'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_send_email_reminder_to_activate_new_order()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
|
||||
SubscriptionRequest::unguard();
|
||||
|
||||
$user
|
||||
->subscriptionRequest()
|
||||
->create([
|
||||
'requested_plan' => 'virtualni-sanon-basic',
|
||||
'creator' => 'john@doe.com',
|
||||
'status' => 'requested',
|
||||
'created_at' => Carbon::now()->subHours(8),
|
||||
]);
|
||||
|
||||
resolve(OasisService::class)
|
||||
->order_reminder();
|
||||
|
||||
Notification::assertSentTo(
|
||||
$user, ReminderForPaymentRequiredNotification::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user