Overview
This document details the enhancements to the Invoice Payment Reminder functionality in the my application, aimed at reducing manual effort, improving customer communication, and ensuring compliance with email marketing standards.
Background
The Invoice Payment Reminder function alerts customers about upcoming subscription payments. Previously, this function lacked features like an unsubscribe link and required additional descriptive content for better customer communication.
Changes Made
Files Affected
- Email Template (invoice-payment-reminder.blade.php)
- Notification Class (InvoicePaymentReminderNotification.php)
- Command to Send Reminders (SendInvoicePaymentReminder.php)
- Testing Route (web.php)
Detailed Changes
- Email Template (invoice-payment-reminder.blade.php)
html Old Code:
<x-emails.layout>
<tr>
<td style="background-color: #8DC1CF; padding: 20px 100px;">
<p>Hi {{ $customerName }}</p>
<p>The amount to be deducted is {{ $totalWithCurrency }} for your {{ $subscriptionPlanName }} plan.</p>
<p>Thanks again for joining the moo-vement!</p>
</td>
</tr>
</x-emails.layout>
html New Code:
<x-emails.layout :unsubscribe-link="$unsubscribeLink">
<tr>
<td style="background-color: #8DC1CF; padding: 20px 100px;">
<p>Hi {{ $customerName }}</p>
<p>{{ $description }}{{ $nextBillingDate }} (within the next 5 days).</p>
<p>The amount to be deducted is {{ $totalWithCurrency }} for your {{ $subscriptionPlanName }} plan.</p>
<p>Thanks again for joining the moo-vement!</p>
</td>
</tr>
</x-emails.layout>
- Notification Class (InvoicePaymentReminderNotification.php)
php Old Code:
public function toMail(Customer $customer): MailMessage
{
$currency = $this->subscription->plan->currency;
$totalWithSymbol = money(
$this->subscription->plan->base_price * 100,
$currency
);
$nextPaymentAt = $this->subscription->next_payment_at;
$mailMessage = new MailMessage();
return $mailMessage
->view('vendor.mail.html.invoice-payment-reminder', [
'customerName' => $customer->full_name,
'nextBillingDate' => $nextPaymentAt?->format('F d, Y'),
'totalWithCurrency' => $totalWithSymbol,
'subscriptionPlanName' => $this->subscription->plan->name,
])
->subject(self::SUBJECT);
}
php New Code:
public function toMail(Customer $customer): MailMessage
{
return (new MailMessage())
->view('vendor.mail.html.invoice-payment-reminder', [
'customerName' => $customer's full_name,
'description' => 'This is a friendly reminder that your upcoming subscription payment for project will be automatically deducted on ',
'nextBillingDate' => $nextPaymentAt?->format('F d, Y'),
'totalWithCurrency' => $totalWithSymbol,
'subscriptionPlanName' => $this->subscription->plan->name,
'unsubscribeLink' => $this->unsubscribeLink,
])
->subject(self::SUBJECT);
}
- Command to Send Reminders (SendInvoicePaymentReminder.php)
php Old Code:
public function handle(): void
{
Log::info('running send invoice-payment-reminder');
$subscriptions = Subscription::with(['plan', 'customer'])
->where('next_payment_at', '>=', Carbon::now())
->where('next_payment_at', '<=', Carbon::now()->addDays(5))
->whereReminderSent(false)
->get();
foreach ($subscriptions as $subscription) {
$subscription->customer->notify(
new InvoicePaymentReminderNotification($subscription)
);
$subscription->update(['reminder_sent' => true]);
}
}
php New Code:
public function handle(): void
{
Log::info('running send invoice-payment-reminder');
$subscriptions = Subscription::with(['plan', 'customer'])
->where('next_payment_at', '>=', Carbon::now())
->where('next_payment_at', '<=', Carbon::now()->addDays(5))
->whereReminderSent(false)
->get();
foreach ($subscriptions as $subscription) {
$email = $subscription->customer->email;
$unsubscribeUrl = NewsLetterSubscriber::where('email', $email)->first()?->getUnsubscribeLink() ?? '';
$subscription->customer->notify(
new InvoicePaymentReminderNotification($subscription, $unsubscribeUrl)
);
$subscription->update(['reminder_sent' => true]);
}
}
- Testing Route (web.php)
Purpose:
Provides a route to render the email template for testing purposes, ensuring that all dynamic elements are displayed correctly.
New Code Snippet:
php
Route::get('/mail-test', function () {
return view('vendor.mail.html.invoice-payment-reminder', [
'customerName' => "Absadasd",
'description' => 'This is a friendly reminder that your upcoming subscription payment for project will be automatically deducted on ',
'nextBillingDate' => \Carbon\Carbon::now()->format('F d, Y'),
'totalWithCurrency' => "ACD20",
'subscriptionPlanName' => "annually",
'unsubscribeLink' => "https",
]);
});
Benefits of Enhancements
Improved Compliance: Including an unsubscribe link adheres to email marketing standards.
Enhanced Customer Experience: Detailed and personalized emails enhance communication clarity and customer satisfaction.
Efficient Process Management: Automating and enhancing the reminder process reduces manual efforts and ensures timely notifications.
Conclusion
The enhancements to the Invoice Payment Reminder system are crucial for maintaining efficient customer communications and ensuring high standards of customer service. These changes make the system more robust, customer-friendly, and compliant with best practices.