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