1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Payments\Models\Methods\Traits; |
4
|
|
|
|
5
|
|
|
use ByTIC\Common\Payments\Models\Methods\Files\MobilpayFile; |
6
|
|
|
use \ByTIC\Models\SmartProperties\RecordsTraits\HasTypes\RecordTrait as HasTypesRecordTrait; |
7
|
|
|
use ByTIC\MediaLibrary\HasMedia\HasMediaTrait; |
8
|
|
|
use ByTIC\MediaLibrary\HasMedia\Traits\AddMediaTrait; |
9
|
|
|
use ByTIC\Payments\Gateways\Providers\AbstractGateway\Traits\GatewayTrait; |
10
|
|
|
use ByTIC\Payments\Models\Methods\Types\AbstractType; |
11
|
|
|
use ByTIC\Payments\Models\Methods\Types\CreditCards; |
12
|
|
|
use Nip\Records\RecordManager; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class MethodTrait |
16
|
|
|
* @package ByTIC\Payments\Models\Methods\Traits |
17
|
|
|
* |
18
|
|
|
* @property string $name |
19
|
|
|
* @property string $internal_name |
20
|
|
|
* @property string $description |
21
|
|
|
* @property string $__notes |
22
|
|
|
* |
23
|
|
|
* @method AbstractType|CreditCards getType |
24
|
|
|
* @method RecordsTrait|RecordManager getManager() |
25
|
|
|
*/ |
26
|
|
|
trait RecordTrait |
27
|
|
|
{ |
28
|
|
|
use HasTypesRecordTrait { |
29
|
|
|
setType as setTypeTrait; |
30
|
|
|
} |
31
|
|
|
use \ByTIC\Common\Records\Traits\HasSerializedOptions\RecordTrait; |
32
|
|
|
|
33
|
|
|
use HasMediaTrait; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param array $data |
37
|
|
|
* @return mixed |
38
|
|
|
*/ |
39
|
|
|
public function fill($data = []) |
40
|
|
|
{ |
41
|
|
|
if (!isset($data['type'])) { |
42
|
|
|
$data['type'] = 'bank-transfer'; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return parent::fill($data); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param bool $type |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
public function getName($type = false) |
53
|
|
|
{ |
54
|
|
|
if ($type == 'internal') { |
55
|
|
|
return $this->getAttributeFromArray('internal_name'); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
return $this->getAttributeFromArray('name'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return bool |
62
|
|
|
*/ |
63
|
|
|
public function checkConfirmRedirect() |
64
|
|
|
{ |
65
|
|
|
if ($this->getType()->checkConfirmRedirect()) { |
66
|
|
|
return true; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return bool|string |
74
|
|
|
*/ |
75
|
|
|
public function getEntryDescription() |
76
|
|
|
{ |
77
|
|
|
$return = $this->getType()->getEntryDescription(); |
78
|
|
|
$return .= $this->getDescription(); |
79
|
|
|
$return .= $this->__notes; |
80
|
|
|
|
81
|
|
|
return $return; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getDescription() |
88
|
|
|
{ |
89
|
|
|
return $this->getAttributeFromArray('description'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return bool |
94
|
|
|
*/ |
95
|
|
|
public function canDelete() |
96
|
|
|
{ |
97
|
|
|
if ($this->getPurchasesCount() > 0) { |
98
|
|
|
return $this->getManager()->getMessage('delete.denied.has-purchases'); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return true; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return int |
106
|
|
|
*/ |
107
|
|
|
abstract public function getPurchasesCount(); |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return bool|GatewayTrait|null |
111
|
|
|
*/ |
112
|
|
|
public function getGateway() |
113
|
|
|
{ |
114
|
|
|
if ($this->getType() instanceof CreditCards) { |
115
|
|
|
return $this->getType()->getGateway(); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return false; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @inheritDoc |
123
|
|
|
*/ |
124
|
24 |
|
public function setType($type = null) |
125
|
|
|
{ |
126
|
24 |
|
$paymentGatewaysNames = \ByTIC\Payments\Gateways\Manager::getAll()->keys(); |
127
|
24 |
|
if (in_array($type, $paymentGatewaysNames)) { |
128
|
2 |
|
$this->setOption('payment_gateway', $type); |
129
|
2 |
|
$type = 'credit-cards'; |
130
|
|
|
} |
131
|
24 |
|
return $this->setTypeTrait($type); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return mixed |
136
|
|
|
*/ |
137
|
1 |
|
public function getPaymentGatewayOptions() |
138
|
|
|
{ |
139
|
1 |
|
$gatewayName = $this->getOption('payment_gateway'); |
140
|
|
|
|
141
|
1 |
|
return $this->getOption($gatewayName); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param array $options |
146
|
|
|
* @param null $gatewayName |
|
|
|
|
147
|
|
|
* @return mixed |
148
|
|
|
*/ |
149
|
1 |
|
public function setPaymentGatewayOptions($options, $gatewayName = null) |
150
|
|
|
{ |
151
|
1 |
|
$gatewayName = $gatewayName? $gatewayName : $this->getOption('payment_gateway'); |
|
|
|
|
152
|
|
|
|
153
|
1 |
|
return $this->setOption($gatewayName, $options); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @param null $type |
|
|
|
|
158
|
|
|
* @return string |
159
|
|
|
*/ |
160
|
|
|
public function getFileModelName($type = null) |
161
|
|
|
{ |
162
|
|
|
if ($type == 'Mobilpay') { |
163
|
|
|
return MobilpayFile::class; |
164
|
|
|
} |
165
|
|
|
return $this->getFileModelNameAbstract($type); |
|
|
|
|
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|