feat(billing): renewals, coupons, VAT numbering, billing cycles and invoice payment tracking
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
ea9a53f742
commit
25f23d541e
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Enums\Order\OrderStatus;
|
||||
use App\Models\Order;
|
||||
use App\Repositories\Log\LogRepositoryInterface;
|
||||
use App\Services\Coupon\CouponService;
|
||||
|
||||
class OrderObserver
|
||||
{
|
||||
@@ -31,6 +33,8 @@ class OrderObserver
|
||||
*/
|
||||
public function updated(Order $order): void
|
||||
{
|
||||
$this->syncCouponRedemption($order);
|
||||
|
||||
if ($order->getDirty()) {
|
||||
foreach ($order->getDirty() as $attribute => $value) { {
|
||||
if ($attribute !== 'updated_at') {
|
||||
@@ -53,6 +57,10 @@ class OrderObserver
|
||||
*/
|
||||
public function deleted(Order $order): void
|
||||
{
|
||||
if ($order->coupon_id) {
|
||||
app(CouponService::class)->setReleased($order, true);
|
||||
}
|
||||
|
||||
$this->logRepository->create([
|
||||
'agent' => request()->userAgent(),
|
||||
'client_ip' => request()->getClientIp(),
|
||||
@@ -77,4 +85,13 @@ class OrderObserver
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
private function syncCouponRedemption(Order $order): void
|
||||
{
|
||||
if (! $order->coupon_id || ! $order->wasChanged('status')) {
|
||||
return;
|
||||
}
|
||||
|
||||
app(CouponService::class)->setReleased($order, (int) $order->status === OrderStatus::CANCELLED->value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user