1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits; |
4
|
|
|
|
5
|
|
|
use ByTIC\Common\Payments\Models\Purchase\Traits\IsPurchasableModelTrait; |
6
|
|
|
use ByTIC\Common\Records\Traits\HasStatus\RecordTrait; |
7
|
|
|
use Nip\Records\Record; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class HasView |
11
|
|
|
* @package ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
trait HasModelProcessedResponse |
15
|
|
|
{ |
16
|
|
|
protected $modelResponseStatus = null; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @return $this |
20
|
|
|
*/ |
21
|
|
|
public function processModel() |
22
|
|
|
{ |
23
|
|
|
if ($this->canProcessModel()) { |
24
|
|
|
$this->processModelStatus(); |
25
|
|
|
$this->processModelData(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
return $this; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return bool |
33
|
|
|
*/ |
34
|
|
|
protected function canProcessModel() |
35
|
|
|
{ |
36
|
|
|
return false; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
protected function processModelStatus() |
40
|
|
|
{ |
41
|
|
|
$model = $this->getModel(); |
42
|
|
|
$modelStatus = $this->getModel()->getStatus()->getName(); |
|
|
|
|
43
|
|
|
$newModelStatus = $this->getModelResponseStatus(); |
44
|
|
|
if ($newModelStatus && $modelStatus !== $newModelStatus) { |
45
|
|
|
if ($newModelStatus == 'active') { |
46
|
|
|
$model->received = $this->getTransactionDate(); |
|
|
|
|
47
|
|
|
$model->updateStatus($newModelStatus); |
|
|
|
|
48
|
|
|
} elseif ($modelStatus == 'active' && $newModelStatus = 'error') { |
49
|
|
|
// ignore error status after active received |
50
|
|
|
} else { |
51
|
|
|
$model->updateStatus($newModelStatus); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return Record|RecordTrait|IsPurchasableModelTrait |
58
|
|
|
*/ |
59
|
4 |
|
public function getModel() |
60
|
|
|
{ |
61
|
4 |
|
return $this->getDataProperty('model'); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return null|string |
66
|
|
|
*/ |
67
|
4 |
|
public function getModelResponseStatus() |
68
|
|
|
{ |
69
|
4 |
|
if ($this->modelResponseStatus === null) { |
70
|
4 |
|
if ($this->isSuccessful()) { |
|
|
|
|
71
|
|
|
$status = 'active'; |
72
|
4 |
|
} elseif ($this->isCancelled()) { |
|
|
|
|
73
|
|
|
$status = 'canceled'; |
74
|
4 |
|
} elseif ($this->isPending()) { |
|
|
|
|
75
|
1 |
|
$status = 'pending'; |
76
|
|
|
} else { |
77
|
3 |
|
$status = 'error'; |
78
|
|
|
} |
79
|
4 |
|
$this->modelResponseStatus = $status; |
80
|
|
|
} |
81
|
|
|
|
82
|
4 |
|
return $this->modelResponseStatus; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return false|string |
87
|
|
|
*/ |
88
|
|
|
public function getTransactionDate() |
89
|
|
|
{ |
90
|
|
|
if (is_callable('parent::getTransactionDate')) { |
91
|
|
|
return parent::getTransactionDate(); |
92
|
|
|
} |
93
|
|
|
return date('Y-m-d H:i:s'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function processModelData() |
97
|
|
|
{ |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return bool |
102
|
|
|
*/ |
103
|
|
|
public function hasModel() |
104
|
|
|
{ |
105
|
|
|
return is_object($this->getModel()); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|