|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Lexik\Bundle\PayboxBundle\Paybox\System\Cancellation; |
|
4
|
|
|
|
|
5
|
|
|
use Lexik\Bundle\PayboxBundle\Paybox\AbstractRequest; |
|
6
|
|
|
use Lexik\Bundle\PayboxBundle\Transport\TransportInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class Request |
|
10
|
|
|
* |
|
11
|
|
|
* @package Lexik\Bundle\PayboxBundle\Paybox\System\Cancellation |
|
12
|
|
|
* |
|
13
|
|
|
* @author Fabien Pomerol <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class Request extends AbstractRequest |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var TransportInterface This is how |
|
19
|
|
|
* you will point to Paybox (via cURL or Shell) |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $transport; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param array $parameters |
|
27
|
|
|
* @param array $servers |
|
28
|
|
|
* @param TransportInterface $transport |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(array $parameters, array $servers, TransportInterface $transport = null) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct($parameters, $servers['system']); |
|
33
|
|
|
|
|
34
|
|
|
$this->transport = $transport; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
*/ |
|
40
|
|
View Code Duplication |
protected function initGlobals(array $parameters) |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$this->globals = array( |
|
43
|
|
|
'production' => isset($parameters['production']) ? $parameters['production'] : false, |
|
44
|
|
|
'currencies' => $parameters['currencies'], |
|
45
|
|
|
'site' => $parameters['site'], |
|
46
|
|
|
'rank' => $parameters['rank'], |
|
47
|
|
|
'login' => $parameters['login'], |
|
48
|
|
|
'hmac_key' => $parameters['hmac']['key'], |
|
49
|
|
|
'hmac_algorithm' => $parameters['hmac']['algorithm'], |
|
50
|
|
|
'hmac_signature_name' => $parameters['hmac']['signature_name'], |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function initParameters() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->setParameter('VERSION', '001'); |
|
60
|
|
|
$this->setParameter('TYPE', '001'); |
|
61
|
|
|
$this->setParameter('SITE', $this->globals['site']); |
|
62
|
|
|
$this->setParameter('MACH', sprintf('%03d', $this->globals['rank'])); |
|
63
|
|
|
$this->setParameter('IDENTIFIANT', $this->globals['login']); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Returns all parameters set for a payment. |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
View Code Duplication |
public function getParameters() |
|
|
|
|
|
|
72
|
|
|
{ |
|
73
|
|
|
if (null === $this->getParameter('HMAC')) { |
|
74
|
|
|
$this->setParameter('TIME', date('c')); |
|
75
|
|
|
$this->setParameter('HMAC', strtoupper($this->computeHmac())); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$resolver = new ParameterResolver(); |
|
79
|
|
|
|
|
80
|
|
|
return $resolver->resolve($this->parameters); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* {@inheritdoc} |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getUrl() |
|
87
|
|
|
{ |
|
88
|
|
|
$server = $this->getServer(); |
|
89
|
|
|
|
|
90
|
|
|
return sprintf( |
|
91
|
|
|
'%s://%s%s', |
|
92
|
|
|
$server['protocol'], |
|
93
|
|
|
$server['host'], |
|
94
|
|
|
$server['cancellation_path'] |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* {@inheritDoc} |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $reference |
|
102
|
|
|
* @param string $subscriptionId |
|
103
|
|
|
* |
|
104
|
|
|
* @throws \RuntimeException On cURL error |
|
105
|
|
|
* |
|
106
|
|
|
* @return string The html of the temporary form |
|
107
|
|
|
*/ |
|
108
|
|
|
public function cancel($reference = null, $subscriptionId = null) |
|
109
|
|
|
{ |
|
110
|
|
|
if ($reference) { |
|
|
|
|
|
|
111
|
|
|
$this->setParameter('REFERENCE', $reference); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
if ($subscriptionId) { |
|
|
|
|
|
|
115
|
|
|
$this->setParameter('ABONNEMENT', $subscriptionId); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
$this->transport->setEndpoint($this->getUrl()); |
|
119
|
|
|
|
|
120
|
|
|
return $this->transport->call($this); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.