PaymentMethod::setPurchaseParams()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Models;
4
5
use Sofa\Eloquence\Eloquence;
6
use Sofa\Eloquence\Mappable;
7
8
/**
9
 * Class PaymentMethod.
10
 */
11
class PaymentMethod extends ChocolateyModel
12
{
13
    use Eloquence, Mappable;
14
15
    /**
16
     * Disable Timestamps.
17
     *
18
     * @var bool
19
     */
20
    public $timestamps = false;
21
22
    /**
23
     * Purchase Params.
24
     *
25
     * @var PurchaseParam
26
     */
27
    public $purchaseParams = null;
28
29
    /**
30
     * The table associated with the model.
31
     *
32
     * @var string
33
     */
34
    protected $table = 'chocolatey_shop_payment_methods';
35
36
    /**
37
     * Primary Key of the Table.
38
     *
39
     * @var string
40
     */
41
    protected $primaryKey = 'id';
42
43
    /**
44
     * The Appender(s) of the Model.
45
     *
46
     * @var array
47
     */
48
    protected $appends = ['disclaimerRequired', 'premiumSms', 'purchaseParams', 'requestPath'];
49
50
    /**
51
     * The attributes excluded from the model's JSON form.
52
     *
53
     * @var array
54
     */
55
    protected $hidden = ['disclaimer'];
56
57
    /**
58
     * The attributes that will be mapped.
59
     *
60
     * @var array
61
     */
62
    protected $maps = ['disclaimerRequired' => 'disclaimer'];
63
64
    /**
65
     * Store an Shop Country.
66
     *
67
     * @param string $methodName
68
     * @param string $code
69
     * @param string $buttonImageUrl
70
     * @param string $buttonText
71
     *
72
     * @return PaymentMethod
73
     */
74
    public function store(string $methodName, string $code, string $buttonImageUrl, string $buttonText): PaymentMethod
75
    {
76
        $this->attributes['name'] = $methodName;
77
        $this->attributes['buttonLogoUrl'] = $buttonImageUrl;
78
        $this->attributes['buttonText'] = $buttonText;
79
        $this->attributes['localizationKey'] = $code;
80
        $this->timestamps = false;
81
82
        $this->save();
83
84
        return $this;
85
    }
86
87
    /**
88
     * Get Disclaimer Required Attribute.
89
     *
90
     * @return bool
91
     */
92
    public function getDisclaimerRequiredAttribute(): bool
93
    {
94
        return $this->attributes['disclaimer'] == 1;
95
    }
96
97
    /**
98
     * Get Premium SMS Attribute.
99
     *
100
     * @return bool
101
     */
102
    public function getPremiumSmsAttribute(): bool
103
    {
104
        return false;
105
    }
106
107
    /**
108
     * Get Request Path Attribute.
109
     *
110
     * @return string
111
     */
112
    public function getRequestPathAttribute(): string
113
    {
114
        return 'online';
115
    }
116
117
    /**
118
     * Get the Purchase Params.
119
     *
120
     * @return PurchaseParam
121
     */
122
    public function getPurchaseParamsAttribute(): PurchaseParam
123
    {
124
        return $this->purchaseParams;
125
    }
126
127
    /**
128
     * Set Purchase Params.
129
     *
130
     * @param array $parameters
131
     */
132
    public function setPurchaseParams(array $parameters)
133
    {
134
        $this->purchaseParams = new PurchaseParam($parameters[0], $parameters[1], $this->attributes['id']);
135
    }
136
137
    /**
138
     * Get Category Payment Type.
139
     *
140
     * @return string
141
     */
142
    public function getCategoryAttribute(): string
143
    {
144
        return PaymentCategory::find($this->attributes['category'])->payment_type;
145
    }
146
}
147