Add Woo Manager email notification milestones with shared mail templates.
Deploy Ladill Woo Manager / deploy (push) Successful in 2m11s
Deploy Ladill Woo Manager / deploy (push) Successful in 2m11s
New order, store connected, Pro expiry, and past-due alerts use the Ladill notification layout with woo branding; expiry reminders dedupe per threshold like hosting. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\Woo\WooProExpiryAlertService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class NotifyProExpiringCommand extends Command
|
||||
{
|
||||
protected $signature = 'woo:pro-expiry-alerts';
|
||||
|
||||
protected $description = 'Send Woo Manager Pro/Business expiry milestone emails';
|
||||
|
||||
public function handle(WooProExpiryAlertService $alerts): int
|
||||
{
|
||||
$sent = $alerts->checkAll();
|
||||
$this->info("Sent {$sent} pro expiry alert(s).");
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,17 @@ use App\Http\Controllers\Controller;
|
||||
use App\Jobs\StoreBootstrapSync;
|
||||
use App\Models\WooStore;
|
||||
use App\Services\Woo\InstallTokenService;
|
||||
use App\Services\Woo\WooNotificationService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use RuntimeException;
|
||||
|
||||
class StoreActivationController extends Controller
|
||||
{
|
||||
public function __construct(private InstallTokenService $tokens) {}
|
||||
public function __construct(
|
||||
private InstallTokenService $tokens,
|
||||
private WooNotificationService $notifications,
|
||||
) {}
|
||||
|
||||
public function activate(Request $request): JsonResponse
|
||||
{
|
||||
@@ -35,9 +39,14 @@ class StoreActivationController extends Controller
|
||||
return response()->json(['message' => 'Site URL does not match the connection request.'], 422);
|
||||
}
|
||||
|
||||
$wasPending = $store->status === WooStore::STATUS_PENDING;
|
||||
$pluginToken = $this->tokens->issuePluginToken($store);
|
||||
$store = $store->fresh();
|
||||
|
||||
if ($wasPending) {
|
||||
$this->notifications->storeConnected($store);
|
||||
}
|
||||
|
||||
StoreBootstrapSync::dispatch($store->id)->afterResponse();
|
||||
|
||||
return response()->json([
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Models\WooStore;
|
||||
use App\Services\Woo\CategoryIngestService;
|
||||
use App\Services\Woo\OrderIngestService;
|
||||
use App\Services\Woo\ProductIngestService;
|
||||
use App\Services\Woo\WooNotificationService;
|
||||
use App\Services\Woo\WooWebhookVerifier;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -17,6 +18,7 @@ class WooWebhookController extends Controller
|
||||
private OrderIngestService $orders,
|
||||
private ProductIngestService $products,
|
||||
private CategoryIngestService $categories,
|
||||
private WooNotificationService $notifications,
|
||||
) {}
|
||||
|
||||
public function __invoke(Request $request, string $storePublicId): JsonResponse
|
||||
@@ -46,7 +48,7 @@ class WooWebhookController extends Controller
|
||||
}
|
||||
|
||||
return match (true) {
|
||||
str_starts_with($topic, 'order.') => $this->handleOrder($store, $payload),
|
||||
str_starts_with($topic, 'order.') => $this->handleOrder($store, $topic, $payload),
|
||||
str_starts_with($topic, 'product_category.') => $this->handleCategory($store, $topic, $payload),
|
||||
str_starts_with($topic, 'product.') => $this->handleProduct($store, $topic, $payload),
|
||||
default => response()->json(['ignored' => true]),
|
||||
@@ -54,10 +56,14 @@ class WooWebhookController extends Controller
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $payload */
|
||||
private function handleOrder(WooStore $store, array $payload): JsonResponse
|
||||
private function handleOrder(WooStore $store, string $topic, array $payload): JsonResponse
|
||||
{
|
||||
$order = $this->orders->ingest($store, $payload);
|
||||
|
||||
if ($topic === 'order.created' && $order->wasRecentlyCreated) {
|
||||
$this->notifications->orderReceived($order, $store);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'order_id' => $order->id,
|
||||
|
||||
@@ -23,7 +23,7 @@ class ProSubscription extends Model
|
||||
protected $fillable = [
|
||||
'user_id', 'status', 'plan', 'price_minor', 'currency', 'auto_renew',
|
||||
'started_at', 'current_period_end', 'last_charged_at', 'canceled_at',
|
||||
'last_reference', 'last_error',
|
||||
'last_reference', 'last_error', 'metadata',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@@ -33,6 +33,7 @@ class ProSubscription extends Model
|
||||
'current_period_end' => 'datetime',
|
||||
'last_charged_at' => 'datetime',
|
||||
'canceled_at' => 'datetime',
|
||||
'metadata' => 'array',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Woo;
|
||||
|
||||
use App\Models\WooOrder;
|
||||
use App\Models\WooStore;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class WooOrderReceivedNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
private readonly WooOrder $order,
|
||||
private readonly WooStore $store,
|
||||
) {}
|
||||
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return $this->channels('order_received');
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage())
|
||||
->subject($this->subjectLine())
|
||||
->view('mail.notifications.woo-order-received', [
|
||||
'order' => $this->order,
|
||||
'store' => $this->store,
|
||||
'manageUrl' => route('woo.orders.index'),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
$label = $this->store->site_name ?? parse_url($this->store->site_url, PHP_URL_HOST) ?? 'your store';
|
||||
|
||||
return [
|
||||
'title' => 'New order received',
|
||||
'message' => "Order #{$this->order->order_number} for {$this->order->totalFormatted()} from {$label}.",
|
||||
'icon' => 'order',
|
||||
'milestone' => 'order_received',
|
||||
'url' => route('woo.orders.index'),
|
||||
'order_id' => $this->order->id,
|
||||
'store_id' => $this->store->id,
|
||||
];
|
||||
}
|
||||
|
||||
private function subjectLine(): string
|
||||
{
|
||||
$storeLabel = $this->store->site_name ?? parse_url($this->store->site_url, PHP_URL_HOST) ?? 'WooCommerce store';
|
||||
|
||||
return "New order #{$this->order->order_number} — {$storeLabel}";
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private function channels(string $event): array
|
||||
{
|
||||
$config = (array) config("notifications.woo_events.{$event}", ['mail' => true, 'database' => true]);
|
||||
$channels = [];
|
||||
if ($config['mail'] ?? false) {
|
||||
$channels[] = 'mail';
|
||||
}
|
||||
if ($config['database'] ?? false) {
|
||||
$channels[] = 'database';
|
||||
}
|
||||
|
||||
return $channels ?: ['database'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Woo;
|
||||
|
||||
use App\Models\Woo\ProSubscription;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class WooProExpiringNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
private readonly ProSubscription $subscription,
|
||||
private readonly int $daysRemaining,
|
||||
) {}
|
||||
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return $this->channels('pro_expiring');
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage())
|
||||
->subject($this->subjectLine())
|
||||
->view('mail.notifications.woo-pro-expiring', [
|
||||
'subscription' => $this->subscription,
|
||||
'daysRemaining' => $this->daysRemaining,
|
||||
'planLabel' => $this->planLabel(),
|
||||
'renewUrl' => route('woo.pro.index'),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'title' => $this->headline(),
|
||||
'message' => "Your Woo Manager {$this->planLabel()} plan expires in {$this->daysRemaining} day(s).",
|
||||
'icon' => 'billing',
|
||||
'milestone' => 'pro_expiring',
|
||||
'url' => route('woo.pro.index'),
|
||||
'days_remaining' => $this->daysRemaining,
|
||||
];
|
||||
}
|
||||
|
||||
private function subjectLine(): string
|
||||
{
|
||||
return match (true) {
|
||||
$this->daysRemaining <= 1 => 'Woo Manager plan expires tomorrow',
|
||||
$this->daysRemaining <= 3 => "Woo Manager plan expires in {$this->daysRemaining} days",
|
||||
default => 'Woo Manager plan renewal reminder',
|
||||
};
|
||||
}
|
||||
|
||||
private function headline(): string
|
||||
{
|
||||
return match (true) {
|
||||
$this->daysRemaining <= 1 => 'Plan expires soon',
|
||||
$this->daysRemaining <= 3 => 'Urgent plan renewal',
|
||||
default => 'Plan renewal reminder',
|
||||
};
|
||||
}
|
||||
|
||||
private function planLabel(): string
|
||||
{
|
||||
return $this->subscription->plan === ProSubscription::PLAN_ENTERPRISE ? 'Business' : 'Pro';
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private function channels(string $event): array
|
||||
{
|
||||
$config = (array) config("notifications.woo_events.{$event}", ['mail' => true, 'database' => true]);
|
||||
$channels = [];
|
||||
if ($config['mail'] ?? false) {
|
||||
$channels[] = 'mail';
|
||||
}
|
||||
if ($config['database'] ?? false) {
|
||||
$channels[] = 'database';
|
||||
}
|
||||
|
||||
return $channels ?: ['database'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Woo;
|
||||
|
||||
use App\Models\Woo\ProSubscription;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class WooProPastDueNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(private readonly ProSubscription $subscription) {}
|
||||
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return $this->channels('pro_past_due');
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage())
|
||||
->subject('Woo Manager subscription payment failed')
|
||||
->view('mail.notifications.woo-pro-past-due', [
|
||||
'subscription' => $this->subscription,
|
||||
'planLabel' => $this->planLabel(),
|
||||
'renewUrl' => route('woo.pro.index'),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Subscription payment failed',
|
||||
'message' => "We could not renew your Woo Manager {$this->planLabel()} plan. Top up your wallet to restore access.",
|
||||
'icon' => 'billing',
|
||||
'milestone' => 'pro_past_due',
|
||||
'url' => route('woo.pro.index'),
|
||||
];
|
||||
}
|
||||
|
||||
private function planLabel(): string
|
||||
{
|
||||
return $this->subscription->plan === ProSubscription::PLAN_ENTERPRISE ? 'Business' : 'Pro';
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private function channels(string $event): array
|
||||
{
|
||||
$config = (array) config("notifications.woo_events.{$event}", ['mail' => true, 'database' => true]);
|
||||
$channels = [];
|
||||
if ($config['mail'] ?? false) {
|
||||
$channels[] = 'mail';
|
||||
}
|
||||
if ($config['database'] ?? false) {
|
||||
$channels[] = 'database';
|
||||
}
|
||||
|
||||
return $channels ?: ['database'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Woo;
|
||||
|
||||
use App\Models\WooStore;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class WooStoreConnectedNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(private readonly WooStore $store) {}
|
||||
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return $this->channels('store_connected');
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage())
|
||||
->subject('WooCommerce store connected — '.($this->store->site_name ?? parse_url($this->store->site_url, PHP_URL_HOST)))
|
||||
->view('mail.notifications.woo-store-connected', [
|
||||
'store' => $this->store,
|
||||
'manageUrl' => route('woo.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
$label = $this->store->site_name ?? parse_url($this->store->site_url, PHP_URL_HOST) ?? 'your store';
|
||||
|
||||
return [
|
||||
'title' => 'Store connected',
|
||||
'message' => "{$label} is now linked to Ladill Woo Manager.",
|
||||
'icon' => 'success',
|
||||
'milestone' => 'store_connected',
|
||||
'url' => route('woo.stores.index'),
|
||||
'store_id' => $this->store->id,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private function channels(string $event): array
|
||||
{
|
||||
$config = (array) config("notifications.woo_events.{$event}", ['mail' => true, 'database' => true]);
|
||||
$channels = [];
|
||||
if ($config['mail'] ?? false) {
|
||||
$channels[] = 'mail';
|
||||
}
|
||||
if ($config['database'] ?? false) {
|
||||
$channels[] = 'database';
|
||||
}
|
||||
|
||||
return $channels ?: ['database'];
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,11 @@ use Illuminate\Support\Str;
|
||||
|
||||
class SubscriptionService
|
||||
{
|
||||
public function __construct(private readonly BillingClient $billing) {}
|
||||
public function __construct(
|
||||
private readonly BillingClient $billing,
|
||||
private readonly WooNotificationService $notifications,
|
||||
private readonly WooProExpiryAlertService $expiryAlerts,
|
||||
) {}
|
||||
|
||||
public function gatingActive(): bool
|
||||
{
|
||||
@@ -238,13 +242,18 @@ class SubscriptionService
|
||||
'last_reference' => $reference,
|
||||
'last_error' => null,
|
||||
])->save();
|
||||
$this->expiryAlerts->resetAlerts($sub->fresh());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$graceEnd = optional($sub->current_period_end)->addDays((int) config('woo.pro.grace_days', 3));
|
||||
if ($graceEnd && $graceEnd->isPast()) {
|
||||
$wasPastDue = $sub->status === ProSubscription::STATUS_PAST_DUE;
|
||||
$sub->forceFill(['status' => ProSubscription::STATUS_PAST_DUE, 'last_error' => $result['error']])->save();
|
||||
if (! $wasPastDue) {
|
||||
$this->notifications->proPastDue($sub->fresh());
|
||||
}
|
||||
} else {
|
||||
$sub->forceFill(['last_error' => $result['error']])->save();
|
||||
}
|
||||
@@ -282,9 +291,15 @@ class SubscriptionService
|
||||
'canceled_at' => null,
|
||||
'last_reference' => $reference,
|
||||
'last_error' => null,
|
||||
'metadata' => null,
|
||||
],
|
||||
);
|
||||
|
||||
$subscription = $this->subscriptionFor($user);
|
||||
if ($subscription) {
|
||||
$this->expiryAlerts->resetAlerts($subscription);
|
||||
}
|
||||
|
||||
return [true, $successMessage.' Your subscription is active.'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Woo;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Woo\ProSubscription;
|
||||
use App\Models\WooOrder;
|
||||
use App\Models\WooStore;
|
||||
use App\Notifications\Woo\WooOrderReceivedNotification;
|
||||
use App\Notifications\Woo\WooProExpiringNotification;
|
||||
use App\Notifications\Woo\WooProPastDueNotification;
|
||||
use App\Notifications\Woo\WooStoreConnectedNotification;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class WooNotificationService
|
||||
{
|
||||
public function orderReceived(WooOrder $order, WooStore $store): void
|
||||
{
|
||||
$order->loadMissing('store');
|
||||
$user = $store->user;
|
||||
if (! $user) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->send($user, 'order_received', new WooOrderReceivedNotification($order, $store));
|
||||
}
|
||||
|
||||
public function storeConnected(WooStore $store): void
|
||||
{
|
||||
$user = $store->user;
|
||||
if (! $user) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->send($user, 'store_connected', new WooStoreConnectedNotification($store));
|
||||
}
|
||||
|
||||
public function proExpiring(ProSubscription $subscription, int $daysRemaining): void
|
||||
{
|
||||
$user = $subscription->user;
|
||||
if (! $user) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->send($user, 'pro_expiring', new WooProExpiringNotification($subscription, $daysRemaining));
|
||||
}
|
||||
|
||||
public function proPastDue(ProSubscription $subscription): void
|
||||
{
|
||||
$user = $subscription->user;
|
||||
if (! $user) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->send($user, 'pro_past_due', new WooProPastDueNotification($subscription));
|
||||
}
|
||||
|
||||
private function send(User $user, string $event, Notification $notification): void
|
||||
{
|
||||
$channels = (array) config("notifications.woo_events.{$event}", ['mail' => true, 'database' => true]);
|
||||
if (! ($channels['mail'] ?? false) && ! ($channels['database'] ?? false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user->notify($notification);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Woo;
|
||||
|
||||
use App\Models\Woo\ProSubscription;
|
||||
|
||||
/** Sends one-time Woo Manager Pro/Business expiry reminders. */
|
||||
class WooProExpiryAlertService
|
||||
{
|
||||
public function __construct(private readonly WooNotificationService $notifications) {}
|
||||
|
||||
/** @return list<int> */
|
||||
public function milestones(): array
|
||||
{
|
||||
return array_values(array_map(
|
||||
'intval',
|
||||
(array) config('notifications.pro_expiry_milestones', [7, 3, 1])
|
||||
));
|
||||
}
|
||||
|
||||
public function checkAll(): int
|
||||
{
|
||||
$sent = 0;
|
||||
|
||||
ProSubscription::query()
|
||||
->whereIn('status', [ProSubscription::STATUS_ACTIVE, ProSubscription::STATUS_CANCELED])
|
||||
->whereNotNull('current_period_end')
|
||||
->where('current_period_end', '>', now())
|
||||
->with('user')
|
||||
->each(function (ProSubscription $subscription) use (&$sent): void {
|
||||
if ($this->checkSubscription($subscription)) {
|
||||
$sent++;
|
||||
}
|
||||
});
|
||||
|
||||
return $sent;
|
||||
}
|
||||
|
||||
public function checkSubscription(ProSubscription $subscription): bool
|
||||
{
|
||||
if (! $subscription->current_period_end || ! $subscription->user || $subscription->current_period_end->isPast()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($subscription->auto_renew && $subscription->status === ProSubscription::STATUS_ACTIVE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$daysRemaining = $this->daysUntilExpiry($subscription);
|
||||
if (! in_array($daysRemaining, $this->milestones(), true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$metadata = is_array($subscription->metadata) ? $subscription->metadata : [];
|
||||
$sent = array_map('intval', (array) ($metadata['expiry_alerts_sent'] ?? []));
|
||||
if (in_array($daysRemaining, $sent, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->notifications->proExpiring($subscription, $daysRemaining);
|
||||
|
||||
$metadata['expiry_alerts_sent'] = array_values(array_unique([...$sent, $daysRemaining]));
|
||||
$subscription->update(['metadata' => $metadata]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function resetAlerts(ProSubscription $subscription): void
|
||||
{
|
||||
$metadata = is_array($subscription->metadata) ? $subscription->metadata : [];
|
||||
unset($metadata['expiry_alerts_sent']);
|
||||
$subscription->update(['metadata' => $metadata]);
|
||||
}
|
||||
|
||||
private function daysUntilExpiry(ProSubscription $subscription): int
|
||||
{
|
||||
return (int) now()->startOfDay()->diffInDays(
|
||||
$subscription->current_period_end->copy()->startOfDay(),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -119,5 +119,15 @@ return [
|
||||
'support_path' => '/support',
|
||||
'home_label' => 'servers.ladill.com',
|
||||
],
|
||||
'woo' => [
|
||||
'name' => 'Ladill Woo Manager',
|
||||
'logo' => 'ladillwoomanager-logo.svg',
|
||||
'logo_class' => 'email-logo',
|
||||
'app_url' => env('APP_URL', 'https://woo.ladill.com'),
|
||||
'footer_account' => 'a Ladill Woo Manager account',
|
||||
'dashboard_path' => '/dashboard',
|
||||
'support_path' => '/support',
|
||||
'home_label' => 'woo.ladill.com',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -4,14 +4,37 @@ return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| FCM push for Ladill Mini Android
|
||||
| FCM push (legacy Mini scaffolding)
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Sellers receive instant payment alerts when a device token is registered
|
||||
| and the account was active in the app within this window.
|
||||
|
|
||||
*/
|
||||
|
||||
'fcm_active_user_within_days' => (int) env('NOTIFICATIONS_FCM_ACTIVE_USER_DAYS', 60),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Woo Manager Pro — days before period end to send one-time reminder emails
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'pro_expiry_milestones' => array_values(array_map(
|
||||
'intval',
|
||||
explode(',', (string) env('WOO_PRO_EXPIRY_MILESTONES', '7,3,1'))
|
||||
)),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Woo Manager notification events
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| milestone keys are stored on in-app notifications for filtering/history.
|
||||
|
|
||||
*/
|
||||
|
||||
'woo_events' => [
|
||||
'order_received' => ['mail' => true, 'database' => true],
|
||||
'store_connected' => ['mail' => true, 'database' => true],
|
||||
'pro_expiring' => ['mail' => true, 'database' => true],
|
||||
'pro_past_due' => ['mail' => true, 'database' => true],
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('woo_pro_subscriptions', function (Blueprint $table) {
|
||||
$table->json('metadata')->nullable()->after('last_error');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('woo_pro_subscriptions', function (Blueprint $table) {
|
||||
$table->dropColumn('metadata');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,80 @@
|
||||
@extends('mail.notifications.layout')
|
||||
|
||||
@section('email-header')
|
||||
@include('mail.partials.brand-header', ['brand' => 'woo'])
|
||||
@endsection
|
||||
|
||||
@section('email-footer')
|
||||
@include('mail.partials.brand-footer', ['brand' => 'woo'])
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="highlight-box highlight-box-success">
|
||||
<p class="highlight-box-text">New order received</p>
|
||||
<p class="highlight-box-subtext">Order #{{ $order->order_number }}</p>
|
||||
</div>
|
||||
|
||||
<h1 class="email-title">You have a new WooCommerce order</h1>
|
||||
|
||||
<p class="email-text">
|
||||
A customer placed an order on <strong>{{ $store->site_name ?? parse_url($store->site_url, PHP_URL_HOST) }}</strong>.
|
||||
Review it in Woo Manager to confirm and fulfill.
|
||||
</p>
|
||||
|
||||
<div class="email-details">
|
||||
<p class="email-details-title">Order details</p>
|
||||
<div class="email-details-row">
|
||||
<p class="email-details-label">Order number</p>
|
||||
<p class="email-details-value">#{{ $order->order_number }}</p>
|
||||
</div>
|
||||
<div class="email-details-row">
|
||||
<p class="email-details-label">Store</p>
|
||||
<p class="email-details-value">{{ $store->site_name ?? $store->site_url }}</p>
|
||||
</div>
|
||||
@if($order->customer_name)
|
||||
<div class="email-details-row">
|
||||
<p class="email-details-label">Customer</p>
|
||||
<p class="email-details-value">{{ $order->customer_name }}</p>
|
||||
</div>
|
||||
@endif
|
||||
@if($order->customer_email)
|
||||
<div class="email-details-row">
|
||||
<p class="email-details-label">Email</p>
|
||||
<p class="email-details-value">{{ $order->customer_email }}</p>
|
||||
</div>
|
||||
@endif
|
||||
<div class="email-details-row">
|
||||
<p class="email-details-label">Status</p>
|
||||
<p class="email-details-value"><span class="status-badge status-info">{{ ucfirst($order->wc_status ?: 'pending') }}</span></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if(is_array($order->line_items) && count($order->line_items) > 0)
|
||||
<div class="email-details">
|
||||
<p class="email-details-title">Items</p>
|
||||
@foreach($order->line_items as $item)
|
||||
<div class="email-details-row">
|
||||
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td style="color: #0f172a; font-size: 14px;">
|
||||
{{ $item['name'] ?? 'Product' }} × {{ $item['quantity'] ?? 1 }}
|
||||
</td>
|
||||
<td style="color: #0f172a; font-size: 14px; text-align: right; font-weight: 600;">
|
||||
{{ strtoupper($order->currency ?: 'GHS') }} {{ number_format(($item['total_minor'] ?? 0) / 100, 2) }}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div style="text-align: center; padding: 24px 0; background-color: #f8fafc; border-radius: 12px; margin: 24px 0;">
|
||||
<p class="email-text-sm" style="margin-bottom: 8px;">Order total</p>
|
||||
<p class="amount-large">{{ $order->totalFormatted() }}</p>
|
||||
</div>
|
||||
|
||||
<p style="text-align: center;">
|
||||
<a href="{{ $manageUrl }}" class="email-button">View orders</a>
|
||||
</p>
|
||||
@endsection
|
||||
@@ -0,0 +1,48 @@
|
||||
@extends('mail.notifications.layout')
|
||||
|
||||
@section('email-header')
|
||||
@include('mail.partials.brand-header', ['brand' => 'woo'])
|
||||
@endsection
|
||||
|
||||
@section('email-footer')
|
||||
@include('mail.partials.brand-footer', ['brand' => 'woo'])
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="highlight-box highlight-box-warning">
|
||||
<p class="highlight-box-text">Plan expiring soon</p>
|
||||
<p class="highlight-box-subtext">Woo Manager {{ $planLabel }}</p>
|
||||
</div>
|
||||
|
||||
<h1 class="email-title">Your Woo Manager {{ $planLabel }} plan is expiring</h1>
|
||||
|
||||
<p class="email-text">
|
||||
Your subscription ends soon. Renew to keep multiple stores, unlimited products, and Pro features.
|
||||
</p>
|
||||
|
||||
<div class="email-details">
|
||||
<p class="email-details-title">Subscription</p>
|
||||
<div class="email-details-row">
|
||||
<p class="email-details-label">Plan</p>
|
||||
<p class="email-details-value">Woo Manager {{ $planLabel }}</p>
|
||||
</div>
|
||||
<div class="email-details-row">
|
||||
<p class="email-details-label">Expires</p>
|
||||
<p class="email-details-value">{{ $subscription->current_period_end?->format('F j, Y') ?? 'N/A' }}</p>
|
||||
</div>
|
||||
<div class="email-details-row">
|
||||
<p class="email-details-label">Days remaining</p>
|
||||
<p class="email-details-value"><span class="status-badge status-warning">{{ $daysRemaining }} days</span></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p style="text-align: center; margin-top: 24px;">
|
||||
<a href="{{ $renewUrl }}" class="email-button">Renew plan</a>
|
||||
</p>
|
||||
|
||||
<div class="email-divider"></div>
|
||||
|
||||
<p class="email-text-sm">
|
||||
If auto-renew is enabled and your wallet has enough balance, your plan may renew automatically on the expiry date.
|
||||
</p>
|
||||
@endsection
|
||||
@@ -0,0 +1,37 @@
|
||||
@extends('mail.notifications.layout')
|
||||
|
||||
@section('email-header')
|
||||
@include('mail.partials.brand-header', ['brand' => 'woo'])
|
||||
@endsection
|
||||
|
||||
@section('email-footer')
|
||||
@include('mail.partials.brand-footer', ['brand' => 'woo'])
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="highlight-box highlight-box-warning">
|
||||
<p class="highlight-box-text">Payment failed</p>
|
||||
<p class="highlight-box-subtext">Woo Manager {{ $planLabel }}</p>
|
||||
</div>
|
||||
|
||||
<h1 class="email-title">We could not renew your subscription</h1>
|
||||
|
||||
<p class="email-text">
|
||||
Your Woo Manager {{ $planLabel }} renewal did not go through.
|
||||
Top up your Ladill wallet and renew to restore full access.
|
||||
</p>
|
||||
|
||||
@if($subscription->last_error)
|
||||
<div class="email-details">
|
||||
<p class="email-details-title">Details</p>
|
||||
<div class="email-details-row">
|
||||
<p class="email-details-label">Reason</p>
|
||||
<p class="email-details-value">{{ $subscription->last_error }}</p>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<p style="text-align: center; margin-top: 24px;">
|
||||
<a href="{{ $renewUrl }}" class="email-button">Manage subscription</a>
|
||||
</p>
|
||||
@endsection
|
||||
@@ -0,0 +1,39 @@
|
||||
@extends('mail.notifications.layout')
|
||||
|
||||
@section('email-header')
|
||||
@include('mail.partials.brand-header', ['brand' => 'woo'])
|
||||
@endsection
|
||||
|
||||
@section('email-footer')
|
||||
@include('mail.partials.brand-footer', ['brand' => 'woo'])
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="highlight-box highlight-box-success">
|
||||
<p class="highlight-box-text">Store connected</p>
|
||||
<p class="highlight-box-subtext">{{ $store->site_name ?? parse_url($store->site_url, PHP_URL_HOST) }}</p>
|
||||
</div>
|
||||
|
||||
<h1 class="email-title">Your WooCommerce store is linked</h1>
|
||||
|
||||
<p class="email-text">
|
||||
<strong>{{ $store->site_name ?? $store->site_url }}</strong> is now connected to Ladill Woo Manager.
|
||||
Orders, products, and categories will sync from your store.
|
||||
</p>
|
||||
|
||||
<div class="email-details">
|
||||
<p class="email-details-title">Connection details</p>
|
||||
<div class="email-details-row">
|
||||
<p class="email-details-label">Store URL</p>
|
||||
<p class="email-details-value">{{ $store->site_url }}</p>
|
||||
</div>
|
||||
<div class="email-details-row">
|
||||
<p class="email-details-label">Connected</p>
|
||||
<p class="email-details-value">{{ $store->connected_at?->format('F j, Y \a\t g:i A') ?? now()->format('F j, Y \a\t g:i A') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p style="text-align: center; margin-top: 24px;">
|
||||
<a href="{{ $manageUrl }}" class="email-button">Open Woo Manager</a>
|
||||
</p>
|
||||
@endsection
|
||||
@@ -26,6 +26,7 @@
|
||||
'email' => 'bg-pink-50',
|
||||
'billing' => 'bg-amber-50',
|
||||
'success' => 'bg-green-50',
|
||||
'order' => 'bg-indigo-50',
|
||||
default => 'bg-slate-100',
|
||||
};
|
||||
$iconColor = match ($icon) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
@section('content')
|
||||
@include('notifications._list', [
|
||||
'subtitle' => 'Hosting activity for your account.',
|
||||
'emptyMessage' => "You're all caught up. We'll notify you when something happens with your hosting.",
|
||||
'subtitle' => 'Orders, stores, and subscription activity for Woo Manager.',
|
||||
'emptyMessage' => "You're all caught up. We'll notify you when you receive orders or account updates.",
|
||||
])
|
||||
@endsection
|
||||
|
||||
@@ -9,3 +9,4 @@ Artisan::command('inspire', function () {
|
||||
})->purpose('Display an inspiring quote');
|
||||
|
||||
Schedule::command('woo:pro-renew')->dailyAt('02:50')->withoutOverlapping();
|
||||
Schedule::command('woo:pro-expiry-alerts')->dailyAt('08:00')->withoutOverlapping();
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Woo\ProSubscription;
|
||||
use App\Models\WooOrder;
|
||||
use App\Models\WooStore;
|
||||
use App\Notifications\Woo\WooOrderReceivedNotification;
|
||||
use App\Notifications\Woo\WooProExpiringNotification;
|
||||
use App\Notifications\Woo\WooStoreConnectedNotification;
|
||||
use App\Services\Woo\InstallTokenService;
|
||||
use App\Services\Woo\WooProExpiryAlertService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WooNotificationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_order_created_webhook_sends_order_received_notification(): void
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$store = WooStore::create([
|
||||
'user_id' => $user->id,
|
||||
'site_url' => 'https://shop.example.com',
|
||||
'site_name' => 'Example Shop',
|
||||
'status' => WooStore::STATUS_ACTIVE,
|
||||
'connected_at' => now(),
|
||||
'plugin_token_hash' => hash('sha256', 'test-token'),
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'id' => 99,
|
||||
'number' => '1099',
|
||||
'status' => 'processing',
|
||||
'currency' => 'GHS',
|
||||
'total' => '75.00',
|
||||
'billing' => ['first_name' => 'Kofi', 'last_name' => 'Annan', 'email' => 'kofi@example.com'],
|
||||
'line_items' => [['name' => 'Cap', 'quantity' => 1, 'total' => '75.00']],
|
||||
'needs_payment' => false,
|
||||
'date_modified_gmt' => now()->utc()->format('Y-m-d H:i:s'),
|
||||
];
|
||||
|
||||
$body = json_encode($payload, JSON_THROW_ON_ERROR);
|
||||
$signature = base64_encode(hash_hmac('sha256', $body, (string) $store->webhook_secret, true));
|
||||
|
||||
$this->call(
|
||||
'POST',
|
||||
route('woo.webhooks.woocommerce', $store->public_id),
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[
|
||||
'CONTENT_TYPE' => 'application/json',
|
||||
'HTTP_X_WC_WEBHOOK_SIGNATURE' => $signature,
|
||||
'HTTP_X_WC_WEBHOOK_TOPIC' => 'order.created',
|
||||
],
|
||||
$body,
|
||||
)->assertOk();
|
||||
|
||||
Notification::assertSentTo($user, WooOrderReceivedNotification::class);
|
||||
}
|
||||
|
||||
public function test_order_updated_webhook_does_not_send_order_received_notification(): void
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$store = WooStore::create([
|
||||
'user_id' => $user->id,
|
||||
'site_url' => 'https://shop.example.com',
|
||||
'status' => WooStore::STATUS_ACTIVE,
|
||||
'connected_at' => now(),
|
||||
'plugin_token_hash' => hash('sha256', 'test-token'),
|
||||
]);
|
||||
|
||||
WooOrder::create([
|
||||
'woo_store_id' => $store->id,
|
||||
'external_order_id' => 42,
|
||||
'order_number' => '1042',
|
||||
'line_items' => [],
|
||||
'currency' => 'GHS',
|
||||
'total_minor' => 5000,
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'id' => 42,
|
||||
'number' => '1042',
|
||||
'status' => 'completed',
|
||||
'currency' => 'GHS',
|
||||
'total' => '50.00',
|
||||
'billing' => [],
|
||||
'line_items' => [],
|
||||
'needs_payment' => false,
|
||||
'date_modified_gmt' => now()->utc()->format('Y-m-d H:i:s'),
|
||||
];
|
||||
|
||||
$body = json_encode($payload, JSON_THROW_ON_ERROR);
|
||||
$signature = base64_encode(hash_hmac('sha256', $body, (string) $store->webhook_secret, true));
|
||||
|
||||
$this->call(
|
||||
'POST',
|
||||
route('woo.webhooks.woocommerce', $store->public_id),
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[
|
||||
'CONTENT_TYPE' => 'application/json',
|
||||
'HTTP_X_WC_WEBHOOK_SIGNATURE' => $signature,
|
||||
'HTTP_X_WC_WEBHOOK_TOPIC' => 'order.updated',
|
||||
],
|
||||
$body,
|
||||
)->assertOk();
|
||||
|
||||
Notification::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_store_activation_sends_store_connected_notification(): void
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$store = WooStore::create([
|
||||
'user_id' => $user->id,
|
||||
'site_url' => 'https://shop.example.com',
|
||||
'site_name' => 'Example Shop',
|
||||
'status' => WooStore::STATUS_PENDING,
|
||||
]);
|
||||
|
||||
$token = app(InstallTokenService::class)->issue($store)['token'];
|
||||
|
||||
$this->postJson('/api/v1/stores/activate', [
|
||||
'install_token' => $token,
|
||||
'site_url' => 'https://shop.example.com',
|
||||
])->assertOk();
|
||||
|
||||
Notification::assertSentTo($user, WooStoreConnectedNotification::class);
|
||||
}
|
||||
|
||||
public function test_pro_expiry_alert_sent_once_per_milestone(): void
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$subscription = ProSubscription::create([
|
||||
'user_id' => $user->id,
|
||||
'status' => ProSubscription::STATUS_CANCELED,
|
||||
'plan' => ProSubscription::PLAN_PRO,
|
||||
'price_minor' => 4900,
|
||||
'currency' => 'GHS',
|
||||
'auto_renew' => false,
|
||||
'current_period_end' => now()->addDays(7)->startOfDay(),
|
||||
]);
|
||||
|
||||
$service = app(WooProExpiryAlertService::class);
|
||||
$service->checkSubscription($subscription);
|
||||
$service->checkSubscription($subscription->fresh());
|
||||
|
||||
Notification::assertSentTo($user, WooProExpiringNotification::class, 1);
|
||||
$this->assertSame([7], $subscription->fresh()->metadata['expiry_alerts_sent']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user