1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2015 Alexey Maslov <[email protected]> |
4
|
|
|
* |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not use this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* |
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
* |
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
* See the License for the specific language governing permissions and |
15
|
|
|
* limitations under the License. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace alxmsl\PaymentNinja\Response; |
19
|
|
|
|
20
|
|
|
use alxmsl\PaymentNinja\InitializationInterface; |
21
|
|
|
use DateTime; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class for process results data |
25
|
|
|
* @author alxmsl |
26
|
|
|
*/ |
27
|
|
|
final class ProcessResponse extends AbstractResponse implements InitializationInterface { |
28
|
|
|
/** |
29
|
|
|
* @var string transaction identifier |
30
|
|
|
*/ |
31
|
|
|
private $id = ''; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var bool request processing result |
35
|
|
|
*/ |
36
|
|
|
private $success = false; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var null|CardResponse instance with safely card data |
40
|
|
|
*/ |
41
|
|
|
private $Card = null; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var null|AccessControlServerResponse instance with ACS data |
45
|
|
|
*/ |
46
|
|
|
private $AccessControlServer = null; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string card's permanent token |
50
|
|
|
*/ |
51
|
|
|
private $permanentToken = ''; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var null|RecurringResponse instance with recurring payments data |
55
|
|
|
*/ |
56
|
|
|
private $Recurring = null; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return string transaction identifier |
60
|
|
|
*/ |
61
|
1 |
|
public function getId() { |
62
|
1 |
|
return $this->id; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return boolean request processing result |
67
|
|
|
*/ |
68
|
1 |
|
public function isSuccess() { |
69
|
1 |
|
return $this->success; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return null|CardResponse instance with safely card data |
74
|
|
|
*/ |
75
|
1 |
|
public function getCard() { |
76
|
1 |
|
return $this->Card; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return null|AccessControlServerResponse instance with ACS data |
81
|
|
|
*/ |
82
|
1 |
|
public function getAccessControlServer() { |
83
|
1 |
|
return $this->AccessControlServer; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string card's permanent token |
88
|
|
|
*/ |
89
|
1 |
|
public function getPermanentToken() { |
90
|
1 |
|
return $this->permanentToken; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return null|RecurringResponse instance with recurring payments data |
95
|
|
|
*/ |
96
|
1 |
|
public function getRecurring() { |
97
|
1 |
|
return $this->Recurring; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @inheritdoc |
102
|
|
|
* @return ProcessResponse instance, that describes payment process result |
103
|
|
|
*/ |
104
|
1 |
|
public static function initializeByString($string) { |
105
|
1 |
|
$Response = json_decode($string); |
106
|
1 |
|
$Result = new ProcessResponse(); |
107
|
1 |
|
$Result->id = (string) $Response->id; |
108
|
1 |
|
$Result->success = (bool) $Response->success; |
109
|
1 |
|
$Result->Card = CardResponse::initializeByObject($Response->card); |
110
|
1 |
|
if (isset($Response->permanentToken)) { |
111
|
1 |
|
$Result->permanentToken = (string) $Response->permanentToken; |
112
|
1 |
|
} |
113
|
1 |
|
if (isset($Response->recurring)) { |
114
|
1 |
|
$Result->Recurring = RecurringResponse::initializeByObject($Response->recurring); |
115
|
1 |
|
} |
116
|
1 |
|
if (isset($Response->acs)) { |
117
|
1 |
|
$Result->AccessControlServer = AccessControlServerResponse::initializeByObject($Response->acs); |
118
|
1 |
|
} |
119
|
1 |
|
return $Result; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @inheritdoc |
124
|
|
|
*/ |
125
|
1 |
|
public function __toString() { |
126
|
|
|
$format = <<<'EOD' |
127
|
|
|
process result |
128
|
|
|
id: %s |
129
|
|
|
success: %s |
130
|
|
|
permanentToken: %s |
131
|
|
|
card |
132
|
|
|
%s |
133
|
|
|
acs |
134
|
|
|
%s |
135
|
|
|
recurring |
136
|
|
|
%s |
137
|
1 |
|
EOD; |
138
|
1 |
|
return sprintf($format |
139
|
1 |
|
, $this->getId() |
140
|
1 |
|
, json_encode($this->isSuccess()) |
141
|
1 |
|
, $this->getPermanentToken() |
142
|
1 |
|
, (string) $this->getCard() |
143
|
1 |
|
, (string) $this->getAccessControlServer() |
144
|
1 |
|
, (string) $this->getRecurring()); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|