|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nexy\PayboxDirect\Request; |
|
4
|
|
|
|
|
5
|
|
|
use Nexy\PayboxDirect\Enum\Activity; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @author Sullivan Senechal <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
abstract class AbstractRequest implements RequestInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var int |
|
14
|
|
|
*/ |
|
15
|
|
|
private $activity = Activity::WEB_REQUEST; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var \DateTime |
|
19
|
|
|
*/ |
|
20
|
|
|
private $date = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var bool |
|
24
|
|
|
*/ |
|
25
|
|
|
private $showCountry = false; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string|null |
|
29
|
|
|
*/ |
|
30
|
|
|
private $subscriberRef = null; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param null|string $subscriberRef |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct($subscriberRef = null) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->subscriberRef = $subscriberRef; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param int $activity |
|
42
|
|
|
* |
|
43
|
|
|
* @return $this |
|
44
|
|
|
*/ |
|
45
|
|
|
final public function setActivity($activity) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->activity = $activity; |
|
48
|
|
|
|
|
49
|
|
|
return $this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param \DateTime|null $date |
|
54
|
|
|
* |
|
55
|
|
|
* @return $this |
|
56
|
|
|
*/ |
|
57
|
|
|
final public function setDate(\DateTime $date = null) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->date = $date; |
|
60
|
|
|
|
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param bool $showCountry |
|
66
|
|
|
*/ |
|
67
|
|
|
final public function setShowCountry($showCountry) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->showCountry = $showCountry; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return null|string |
|
74
|
|
|
*/ |
|
75
|
|
|
final protected function getSubscriberRef() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->subscriberRef; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritdoc} |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getParameters() |
|
84
|
|
|
{ |
|
85
|
|
|
$parameters = [ |
|
86
|
|
|
'ACTIVITE' => $this->activity, |
|
87
|
|
|
'DATEQ' => $this->date instanceof \DateTime ? $this->date->format('dmYHis') : null, |
|
88
|
|
|
]; |
|
89
|
|
|
|
|
90
|
|
|
if ($this->showCountry) { |
|
91
|
|
|
$parameters['PAYS'] = ''; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if (method_exists($this, 'getTransactionNumber')) { |
|
95
|
|
|
$parameters['NUMTRANS'] = $this->getTransactionNumber(); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
if (method_exists($this, 'getCallNumber')) { |
|
98
|
|
|
$parameters['NUMAPPEL'] = $this->getCallNumber(); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
// Direct Plus requests special case. |
|
102
|
|
|
if (null !== $this->getSubscriberRef()) { |
|
103
|
|
|
$parameters['REFABONNE'] = $this->getSubscriberRef(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $parameters; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: