1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits; |
4
|
|
|
|
5
|
|
|
use ByTIC\Models\SmartProperties\RecordsTraits\HasStatus\RecordTrait; |
6
|
|
|
use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait; |
7
|
|
|
use ByTIC\Payments\Models\Transactions\Statuses\Active; |
8
|
|
|
use ByTIC\Payments\Models\Transactions\Statuses\Canceled; |
9
|
|
|
use ByTIC\Payments\Models\Transactions\Statuses\Error; |
10
|
|
|
use ByTIC\Payments\Models\Transactions\Statuses\Pending; |
11
|
|
|
use Nip\Records\Record; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class HasView |
15
|
|
|
* @package ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
trait HasModelProcessedResponse |
19
|
|
|
{ |
20
|
|
|
protected $modelResponseStatus = null; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return $this |
24
|
|
|
*/ |
25
|
|
|
public function processModel() |
26
|
|
|
{ |
27
|
|
|
if ($this->canProcessModel()) { |
28
|
|
|
$this->processModelStatus(); |
29
|
|
|
$this->processModelData(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return bool |
37
|
|
|
*/ |
38
|
|
|
protected function canProcessModel() |
39
|
|
|
{ |
40
|
|
|
return false; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function processModelStatus() |
44
|
|
|
{ |
45
|
|
|
$model = $this->getModel(); |
46
|
|
|
$modelStatus = $this->getModel()->getStatus()->getName(); |
|
|
|
|
47
|
|
|
$newModelStatus = $this->getModelResponseStatus(); |
48
|
|
|
if (!$newModelStatus || $modelStatus === $newModelStatus) { |
49
|
|
|
return; |
50
|
|
|
} |
51
|
|
|
if ($modelStatus == 'active' && $newModelStatus == 'error') { |
52
|
|
|
// ignore error status after active received |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
if ($newModelStatus == 'active') { |
56
|
|
|
$model->received = $this->getTransactionDate(); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
$model->updateStatus($newModelStatus); |
|
|
|
|
59
|
4 |
|
} |
60
|
|
|
|
61
|
4 |
|
/** |
62
|
|
|
* @return Record|RecordTrait|IsPurchasableModelTrait |
63
|
|
|
*/ |
64
|
|
|
public function getModel() |
65
|
|
|
{ |
66
|
|
|
return $this->getDataProperty('model'); |
|
|
|
|
67
|
4 |
|
} |
68
|
|
|
|
69
|
4 |
|
/** |
70
|
4 |
|
* @return null|string |
71
|
|
|
*/ |
72
|
4 |
|
public function getModelResponseStatus(): ?string |
73
|
|
|
{ |
74
|
4 |
|
if ($this->modelResponseStatus === null) { |
75
|
1 |
|
if ($this->isSuccessful()) { |
|
|
|
|
76
|
|
|
$status = Active::NAME; |
77
|
3 |
|
} elseif ($this->isCancelled()) { |
|
|
|
|
78
|
|
|
$status = Canceled::NAME; |
79
|
4 |
|
} elseif ($this->isPending()) { |
|
|
|
|
80
|
|
|
$status = Pending::NAME; |
81
|
|
|
} else { |
82
|
4 |
|
$status = Error::NAME; |
83
|
|
|
} |
84
|
|
|
$this->modelResponseStatus = $status; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $this->modelResponseStatus; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return false|string |
92
|
|
|
*/ |
93
|
|
|
public function getTransactionDate() |
94
|
|
|
{ |
95
|
|
|
if (is_callable('parent::getTransactionDate')) { |
96
|
|
|
/** @noinspection PhpUndefinedMethodInspection @phpstan-ignore-next-line */ |
97
|
|
|
return parent::getTransactionDate(); |
98
|
|
|
} |
99
|
|
|
return date('Y-m-d H:i:s'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function processModelData() |
103
|
|
|
{ |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return bool |
108
|
|
|
*/ |
109
|
|
|
public function hasModel() |
110
|
|
|
{ |
111
|
|
|
return is_object($this->getModel()); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.