Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
PaymentRecordObserver
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
5.39
0.00% covered (danger)
0.00%
0 / 1
 created
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 updated
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
4.12
1<?php
2
3namespace App\Observers;
4
5use App\Enums\PaymentStatus;
6use App\Models\PaymentRecord;
7use App\Services\NotificationService;
8
9class PaymentRecordObserver
10{
11    public function created(PaymentRecord $paymentRecord): void
12    {
13        if ($paymentRecord->status === PaymentStatus::Paid) {
14            app(NotificationService::class)->notifyPaymentPaid($paymentRecord);
15        }
16    }
17
18    public function updated(PaymentRecord $paymentRecord): void
19    {
20        if ($paymentRecord->wasChanged('status') && $paymentRecord->status === PaymentStatus::Paid) {
21            app(NotificationService::class)->notifyPaymentPaid($paymentRecord);
22        }
23    }
24}