|
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\ObjectInitializedInterface; |
|
21
|
|
|
use stdClass; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class for card's data |
|
25
|
|
|
* @author alxmsl |
|
26
|
|
|
*/ |
|
27
|
|
|
final class CardResponse implements ObjectInitializedInterface { |
|
28
|
|
|
/** |
|
29
|
|
|
* @var string last four digits of credit card number |
|
30
|
|
|
*/ |
|
31
|
|
|
private $lastFour = ''; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string credit card's number mask |
|
35
|
|
|
*/ |
|
36
|
|
|
private $mask = ''; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var int credit card's expiration month |
|
40
|
|
|
*/ |
|
41
|
|
|
private $expirationMonth = 0; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var int credit card's expiration year |
|
45
|
|
|
*/ |
|
46
|
|
|
private $expirationYear = 0; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var string card type |
|
50
|
|
|
*/ |
|
51
|
|
|
private $type = ''; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return string last four digits of credit card number |
|
55
|
|
|
*/ |
|
56
|
4 |
|
public function getLastFour() { |
|
57
|
4 |
|
return $this->lastFour; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return string credit card's number mask |
|
62
|
|
|
*/ |
|
63
|
4 |
|
public function getMask() { |
|
64
|
4 |
|
return $this->mask; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return int credit card's expiration month |
|
69
|
|
|
*/ |
|
70
|
4 |
|
public function getExpirationMonth() { |
|
71
|
4 |
|
return $this->expirationMonth; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return int credit card's expiration year |
|
76
|
|
|
*/ |
|
77
|
4 |
|
public function getExpirationYear() { |
|
78
|
4 |
|
return $this->expirationYear; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return string card's type |
|
83
|
|
|
*/ |
|
84
|
4 |
|
public function getType() { |
|
85
|
4 |
|
return $this->type; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @inheritdoc |
|
90
|
|
|
* @return CardResponse instance with safely card data |
|
91
|
|
|
*/ |
|
92
|
4 |
|
public static function initializeByObject(stdClass $Object) { |
|
93
|
4 |
|
$Result = new CardResponse(); |
|
94
|
4 |
|
$Result->lastFour = (string) $Object->lastFour; |
|
95
|
4 |
|
$Result->mask = (string) $Object->mask; |
|
96
|
4 |
|
$Result->expirationMonth = (int) $Object->expirationMonth; |
|
97
|
4 |
|
$Result->expirationYear = (int) $Object->expirationYear; |
|
98
|
4 |
|
$Result->type = (string) $Object->type; |
|
99
|
4 |
|
return $Result; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @inheritdoc |
|
104
|
|
|
*/ |
|
105
|
4 |
|
public function __toString() { |
|
106
|
|
|
$format = <<<'EOD' |
|
107
|
|
|
four: %s |
|
108
|
|
|
mask: %s |
|
109
|
|
|
type: %s |
|
110
|
|
|
exp. month: %s |
|
111
|
|
|
exp. year: %s |
|
112
|
4 |
|
EOD; |
|
113
|
4 |
|
return sprintf($format |
|
114
|
4 |
|
, $this->getLastFour() |
|
115
|
4 |
|
, $this->getMask() |
|
116
|
4 |
|
, $this->getType() |
|
117
|
4 |
|
, $this->getExpirationMonth() |
|
118
|
4 |
|
, $this->getExpirationYear()); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|