Transaction   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 14
eloc 32
c 5
b 1
f 2
dl 0
loc 50
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A parent() 0 3 1
B getGatewayAttribute() 0 17 7
A getTomanAttribute() 0 3 1
A getStatusLabelAttribute() 0 13 5
1
<?php
2
3
namespace Dizatech\Transaction\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'];
13
    protected $appends = ['gateway','toman','status_label'];
14
15
    public function parent()
16
    {
17
        return $this->belongsTo( config('dizatech_transaction.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
            case 'zarinpal' :
28
                return 'زرین پال';
29
            case 'sadad' :
30
                return 'سداد';
31
            case 'mahamax' :
32
                return 'مهامکس';
33
            case 'saman' :
34
                return 'سامان';
35
            default:
36
                return $this->driver;
37
        }
38
    }
39
40
    public function getTomanAttribute()
41
    {
42
        return $this->amount / 10;
43
    }
44
45
    public function getStatusLabelAttribute()
46
    {
47
        switch ($this->status) {
48
            case 'pending':
49
                return 'در انتظار پرداخت';
50
            case 'failed':
51
                return 'ناموفق';
52
            case  'refunded':
53
                return 'برگشت خورده';
54
            case 'successful':
55
                return 'موفقیت‌آمیز';
56
            default:
57
                return 'نامشخص';
58
        }
59
    }
60
}
61