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 card's token data |
25
|
|
|
* @author alxmsl |
26
|
|
|
*/ |
27
|
|
|
final class TokenResponse extends AbstractResponse implements InitializationInterface { |
28
|
|
|
/** |
29
|
|
|
* @var string temporary, 10-minutes card token |
30
|
|
|
*/ |
31
|
|
|
private $id = ''; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var int expiration timestamp |
35
|
|
|
*/ |
36
|
|
|
private $expiresAt = 0; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var null|CardResponse instance with safely card data |
40
|
|
|
*/ |
41
|
|
|
private $Card = null; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return string temporary, 10-minutes card token |
45
|
|
|
*/ |
46
|
1 |
|
public function getId() { |
47
|
1 |
|
return $this->id; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return int expiration timestamp |
52
|
|
|
*/ |
53
|
1 |
|
public function getExpiresAt() { |
54
|
1 |
|
return $this->expiresAt; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return null|CardResponse instance with safely card data |
59
|
|
|
*/ |
60
|
1 |
|
public function getCard() { |
61
|
1 |
|
return $this->Card; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @inheritdoc |
66
|
|
|
* @return TokenResponse card's token instance |
67
|
|
|
*/ |
68
|
1 |
|
public static function initializeByString($string) { |
69
|
1 |
|
$Response = json_decode($string); |
70
|
1 |
|
$Result = new TokenResponse(); |
71
|
1 |
|
$Result->id = (string) $Response->id; |
72
|
1 |
|
$Result->expiresAt = strtotime($Response->expiresAt); |
73
|
1 |
|
$Result->Card = CardResponse::initializeByObject($Response->card); |
74
|
1 |
|
return $Result; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @inheritdoc |
79
|
|
|
*/ |
80
|
1 |
|
public function __toString() { |
81
|
|
|
$format = <<<'EOD' |
82
|
|
|
token's data |
83
|
|
|
id: %s |
84
|
|
|
expiresAt: %s |
85
|
|
|
card |
86
|
|
|
%s |
87
|
1 |
|
EOD; |
88
|
1 |
|
return sprintf($format |
89
|
1 |
|
, $this->getId() |
90
|
1 |
|
, gmdate(DateTime::ISO8601, $this->getExpiresAt()) |
91
|
1 |
|
, (string) $this->getCard()); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|