|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LauLamanApps\eCurring\Resource\Subscription; |
|
6
|
|
|
|
|
7
|
|
|
use DateTimeImmutable; |
|
8
|
|
|
use LauLamanApps\eCurring\Resource\Subscription\Exception\MandateAlreadyAcceptedException; |
|
9
|
|
|
use LauLamanApps\eCurring\Resource\Subscription\Exception\MandateInvalidException; |
|
10
|
|
|
|
|
11
|
|
|
final class Mandate |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var string |
|
15
|
|
|
* |
|
16
|
|
|
* The unique mandate code which is generated when creating a subscription. |
|
17
|
|
|
*/ |
|
18
|
|
|
private $code; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var bool |
|
22
|
|
|
* |
|
23
|
|
|
* Indicates whether the mandate has been accepted. |
|
24
|
|
|
* A mandate can be accepted by the customer or automatically by using the API. |
|
25
|
|
|
*/ |
|
26
|
|
|
private $accepted; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var DateTimeImmutable|null |
|
30
|
|
|
* |
|
31
|
|
|
* The date on which the mandate has been accepted. |
|
32
|
|
|
*/ |
|
33
|
1 |
|
private $acceptedDate; |
|
34
|
|
|
|
|
35
|
1 |
|
/** |
|
36
|
1 |
|
* @throws MandateInvalidException |
|
37
|
1 |
|
*/ |
|
38
|
1 |
|
public function __construct( |
|
39
|
|
|
string $code, |
|
40
|
1 |
|
?bool $accepted = false, |
|
41
|
|
|
?DateTimeImmutable $acceptedDate = null |
|
42
|
1 |
|
) { |
|
43
|
|
|
$this->code = $code; |
|
44
|
|
|
$this->accepted = $accepted; |
|
45
|
1 |
|
$this->acceptedDate = $acceptedDate; |
|
46
|
|
|
|
|
47
|
1 |
|
$this->validate(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
public function getCode(): string |
|
51
|
|
|
{ |
|
52
|
1 |
|
return $this->code; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function isAccepted(): ?bool |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->accepted; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getAcceptedDate(): ?DateTimeImmutable |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->acceptedDate; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @throws MandateAlreadyAcceptedException |
|
67
|
|
|
*/ |
|
68
|
|
|
public function accept(DateTimeImmutable $acceptedDate): void |
|
69
|
|
|
{ |
|
70
|
|
|
if ($this->accepted === true) { |
|
71
|
|
|
throw new MandateAlreadyAcceptedException( |
|
72
|
|
|
sprintf('Mandate already accepted on %s', $this->acceptedDate->format('Y-m-d H:i:s')) |
|
|
|
|
|
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$this->accepted = true; |
|
77
|
|
|
$this->acceptedDate = $acceptedDate; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @throws MandateInvalidException |
|
82
|
|
|
*/ |
|
83
|
|
|
private function validate(): void |
|
84
|
|
|
{ |
|
85
|
|
|
if ($this->accepted && $this->getAcceptedDate() === null) { |
|
86
|
|
|
throw new MandateInvalidException('No AcceptedDate provided although the mandate is accepted.'); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.