Transaction   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 16
eloc 35
c 2
b 0
f 0
dl 0
loc 58
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A parent() 0 3 1
A getGatewayAttribute() 0 9 3
A getStatusLabelAttribute() 0 13 5
A getStatusBadgeAttribute() 0 13 6
A getTomanAttribute() 0 3 1
1
<?php
2
3
namespace Sinarajabpour1998\Gateway\Models;
4
5
use Illuminate\Database\Eloquent\Factories\HasFactory;
6
use Illuminate\Database\Eloquent\Model;
7
8
class Transaction extends Model
9
{
10
    use HasFactory;
11
12
    protected $fillable = ['order_id', 'status', 'amount', 'driver', 'ref_no', 'token', 'description'];
13
    protected $appends = ['gateway','toman','status_label','status_badge'];
14
15
    public function parent()
16
    {
17
        return $this->belongsTo( config('gateway.model'), 'order_id' );
18
    }
19
20
    public function getGatewayAttribute()
21
    {
22
        switch ($this->driver) {
23
            case 'pasargad':
24
                return 'بانک پاسارگاد';
25
            case 'parsian':
26
                return 'بانک پارسیان';
27
            default:
28
                return 'نامشخص';
29
        }
30
    }
31
32
    public function getTomanAttribute()
33
    {
34
        return $this->amount / 10;
35
    }
36
37
    public function getStatusLabelAttribute()
38
    {
39
        switch ($this->status) {
40
            case 'pending':
41
                return 'در انتظار پرداخت';
42
            case 'failed':
43
                return 'ناموفق';
44
            case  'refunded':
45
                return 'برگشت خورده';
46
            case 'successful':
47
                return 'موفقیت‌آمیز';
48
            default:
49
                return 'نامشخص';
50
        }
51
    }
52
53
    public function getStatusBadgeAttribute()
54
    {
55
        switch ($this->status) {
56
            case 'pending':
57
                return 'badge-warning';
58
            case 'failed':
59
                return 'badge-danger';
60
            case 'refunded':
61
                return 'badge-dark';
62
            case 'successful':
63
                return 'badge-success';
64
            case 'default':
65
                return 'badge-light';
66
        }
67
    }
68
}
69