1
|
|
|
<?php |
2
|
|
|
namespace PHPSC\PagSeguro\Purchases\Subscriptions; |
3
|
|
|
|
4
|
|
|
use PHPSC\PagSeguro\Purchases\Details; |
5
|
|
|
use PHPSC\PagSeguro\Requests\PreApprovals\ChargeType; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Luís Otávio Cobucci Oblonczyk <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
class Subscription |
11
|
|
|
{ |
12
|
|
|
const INITIATED = 'INITIATED'; |
13
|
|
|
const PENDING = 'PENDING'; |
14
|
|
|
const ACTIVE = 'ACTIVE'; |
15
|
|
|
const CANCELLED = 'CANCELLED'; |
16
|
|
|
const CANCELLED_BY_RECEIVER = 'CANCELLED_BY_RECEIVER'; |
17
|
|
|
const CANCELLED_BY_SENDER = 'CANCELLED_BY_SENDER'; |
18
|
|
|
const EXPIRED = 'EXPIRED'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $name; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var Details |
27
|
|
|
*/ |
28
|
|
|
private $details; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $tracker; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $chargeType; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $name |
42
|
|
|
* @param Details $details |
43
|
|
|
* @param string $tracker |
44
|
|
|
* @param string $chargeType |
45
|
|
|
*/ |
46
|
11 |
|
public function __construct( |
47
|
|
|
$name, |
48
|
|
|
Details $details, |
49
|
|
|
$tracker, |
50
|
|
|
$chargeType |
51
|
|
|
) { |
52
|
11 |
|
$this->name = $name; |
53
|
11 |
|
$this->details = $details; |
54
|
11 |
|
$this->tracker = $tracker; |
55
|
11 |
|
$this->chargeType = $chargeType; |
56
|
11 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
1 |
|
public function getName() |
62
|
|
|
{ |
63
|
1 |
|
return $this->name; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return Details |
68
|
|
|
*/ |
69
|
8 |
|
public function getDetails() |
70
|
|
|
{ |
71
|
8 |
|
return $this->details; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
1 |
|
public function getTracker() |
78
|
|
|
{ |
79
|
1 |
|
return $this->tracker; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return boolean |
84
|
|
|
*/ |
85
|
3 |
|
public function isAutomatic() |
86
|
|
|
{ |
87
|
3 |
|
return $this->chargeType == ChargeType::AUTOMATIC; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return boolean |
92
|
|
|
*/ |
93
|
3 |
|
public function isManual() |
94
|
|
|
{ |
95
|
3 |
|
return $this->chargeType == ChargeType::MANUAL; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return boolean |
100
|
|
|
*/ |
101
|
2 |
|
public function isInitiated() |
102
|
|
|
{ |
103
|
2 |
|
return $this->getDetails()->getStatus() === static::INITIATED; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return boolean |
108
|
|
|
*/ |
109
|
2 |
|
public function isPending() |
110
|
|
|
{ |
111
|
2 |
|
return $this->getDetails()->getStatus() === static::PENDING; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return boolean |
116
|
|
|
*/ |
117
|
2 |
|
public function isActive() |
118
|
|
|
{ |
119
|
2 |
|
return $this->getDetails()->getStatus() === static::ACTIVE; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return boolean |
124
|
|
|
*/ |
125
|
2 |
|
public function isCancelledByAcquirer() |
126
|
|
|
{ |
127
|
2 |
|
return $this->getDetails()->getStatus() === static::CANCELLED; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return boolean |
132
|
|
|
*/ |
133
|
2 |
|
public function isCancelledByReceiver() |
134
|
|
|
{ |
135
|
2 |
|
return $this->getDetails()->getStatus() === static::CANCELLED_BY_RECEIVER; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return boolean |
140
|
|
|
*/ |
141
|
2 |
|
public function isCancelledByCustomer() |
142
|
|
|
{ |
143
|
2 |
|
return $this->getDetails()->getStatus() === static::CANCELLED_BY_SENDER; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return boolean |
148
|
|
|
*/ |
149
|
2 |
|
public function isExpired() |
150
|
|
|
{ |
151
|
2 |
|
return $this->getDetails()->getStatus() === static::EXPIRED; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|