This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Nexylan packages. |
||
5 | * |
||
6 | * (c) Nexylan SAS <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Nexy\PayboxDirect; |
||
13 | |||
14 | use Doctrine\Common\Annotations\AnnotationRegistry; |
||
15 | use Nexy\PayboxDirect\Enum\Activity; |
||
16 | use Nexy\PayboxDirect\Enum\Currency; |
||
17 | use Nexy\PayboxDirect\Enum\Version; |
||
18 | use Nexy\PayboxDirect\Exception\InvalidRequestPropertiesException; |
||
19 | use Nexy\PayboxDirect\HttpClient\AbstractHttpClient; |
||
20 | use Nexy\PayboxDirect\HttpClient\GuzzleHttpClient; |
||
21 | use Nexy\PayboxDirect\Request\InquiryRequest; |
||
22 | use Nexy\PayboxDirect\Request\RequestInterface; |
||
23 | use Nexy\PayboxDirect\Response\DirectPlusResponse; |
||
24 | use Nexy\PayboxDirect\Response\DirectResponse; |
||
25 | use Nexy\PayboxDirect\Response\InquiryResponse; |
||
26 | use Nexy\PayboxDirect\Response\ResponseInterface; |
||
27 | use Symfony\Component\OptionsResolver\OptionsResolver; |
||
28 | use Symfony\Component\Validator\Validation; |
||
29 | use Symfony\Component\Validator\Validator\ValidatorInterface; |
||
30 | |||
31 | /** |
||
32 | * @author Sullivan Senechal <[email protected]> |
||
33 | * |
||
34 | * @see http://www1.paybox.com/espace-integrateur-documentation/les-solutions-paybox-direct-et-paybox-direct-plus/les-operations-de-caisse-direct-plus/ |
||
35 | * @see http://www1.paybox.com/espace-integrateur-documentation/dictionnaire-des-donnees/paybox-direct-et-direct-plus/ |
||
36 | */ |
||
37 | final class Paybox |
||
38 | { |
||
39 | const API_URL_PRODUCTION = 'https://ppps.paybox.com/PPPS.php'; |
||
40 | |||
41 | const API_URL_RESCUE = 'https://ppps1.paybox.com/PPPS.php'; |
||
42 | |||
43 | const API_URL_TEST = 'https://preprod-ppps.paybox.com/PPPS.php'; |
||
44 | |||
45 | /** |
||
46 | * @var ValidatorInterface |
||
47 | */ |
||
48 | private $validator; |
||
49 | |||
50 | /** |
||
51 | * @var AbstractHttpClient |
||
52 | */ |
||
53 | private $httpClient; |
||
54 | |||
55 | /** |
||
56 | * @var array |
||
57 | */ |
||
58 | private $options; |
||
59 | |||
60 | public function __construct(array $options = [], AbstractHttpClient $httpClient = null) |
||
61 | { |
||
62 | $resolver = new OptionsResolver(); |
||
63 | $this->configureOptions($resolver); |
||
64 | |||
65 | $this->options = $resolver->resolve($options); |
||
66 | |||
67 | AnnotationRegistry::registerLoader('class_exists'); |
||
0 ignored issues
–
show
|
|||
68 | $this->validator = Validation::createValidatorBuilder() |
||
69 | ->enableAnnotationMapping() |
||
70 | ->getValidator(); |
||
71 | |||
72 | $this->httpClient = $httpClient ? $httpClient : new GuzzleHttpClient(); |
||
73 | $this->httpClient->setOptions($this->options); |
||
74 | $this->httpClient->init(); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param RequestInterface $request |
||
79 | * |
||
80 | * @return DirectResponse |
||
81 | */ |
||
82 | public function sendDirectRequest(RequestInterface $request) |
||
83 | { |
||
84 | if ($request->getRequestType() >= RequestInterface::SUBSCRIBER_AUTHORIZE) { |
||
85 | throw new \InvalidArgumentException( |
||
86 | 'Direct Plus requests must be passed onto '.__CLASS__.'::sendDirectPlusRequest method.' |
||
87 | ); |
||
88 | } |
||
89 | if ($request instanceof InquiryRequest) { |
||
90 | throw new \InvalidArgumentException( |
||
91 | 'Inquiry requests must be passed onto '.__CLASS__.'::sendInquiryRequest method.' |
||
92 | ); |
||
93 | } |
||
94 | |||
95 | return $this->request($request); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @param RequestInterface $request |
||
100 | * |
||
101 | * @return DirectPlusResponse |
||
102 | */ |
||
103 | public function sendDirectPlusRequest(RequestInterface $request) |
||
104 | { |
||
105 | if ($request->getRequestType() < RequestInterface::SUBSCRIBER_AUTHORIZE) { |
||
106 | throw new \InvalidArgumentException( |
||
107 | 'Direct requests must be passed onto '.__CLASS__.'::sendDirectRequest method.' |
||
108 | ); |
||
109 | } |
||
110 | |||
111 | return $this->request($request, DirectPlusResponse::class); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @param InquiryRequest $request |
||
116 | * |
||
117 | * @return InquiryResponse |
||
118 | */ |
||
119 | public function sendInquiryRequest(InquiryRequest $request) |
||
120 | { |
||
121 | return $this->request($request, InquiryResponse::class); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * @param RequestInterface $request |
||
126 | * @param string $responseClass |
||
127 | * |
||
128 | * @return ResponseInterface |
||
129 | * |
||
130 | * @throws Exception\InvalidRequestPropertiesException |
||
131 | * @throws Exception\PayboxException |
||
132 | */ |
||
133 | private function request(RequestInterface $request, $responseClass = DirectResponse::class) |
||
134 | { |
||
135 | $errors = $this->validator->validate($request); |
||
136 | if ($errors->count() > 0) { |
||
137 | throw new InvalidRequestPropertiesException($request, $errors); |
||
138 | } |
||
139 | |||
140 | return $this->httpClient->call($request->getRequestType(), $request->getParameters(), $responseClass); |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Paybox base options validation. |
||
145 | * |
||
146 | * @param OptionsResolver $resolver |
||
147 | */ |
||
148 | private function configureOptions(OptionsResolver $resolver) |
||
149 | { |
||
150 | $resolver->setDefaults([ |
||
151 | 'timeout' => 10, |
||
152 | 'production' => false, |
||
153 | 'paybox_default_currency' => Currency::EURO, |
||
154 | ]); |
||
155 | $resolver->setDefined([ |
||
156 | 'paybox_default_activity', |
||
157 | ]); |
||
158 | $resolver->setRequired([ |
||
159 | 'paybox_version', // Paybox Direct Plus protocol |
||
160 | 'paybox_site', |
||
161 | 'paybox_rank', |
||
162 | 'paybox_identifier', |
||
163 | 'paybox_key', |
||
164 | ]); |
||
165 | |||
166 | $resolver->setAllowedTypes('timeout', 'int'); |
||
167 | $resolver->setAllowedTypes('production', 'bool'); |
||
168 | $resolver->setAllowedTypes('paybox_version', 'string'); |
||
169 | $resolver->setAllowedTypes('paybox_default_currency', 'int'); |
||
170 | $resolver->setAllowedTypes('paybox_site', 'string'); |
||
171 | $resolver->setAllowedTypes('paybox_rank', 'string'); |
||
172 | $resolver->setAllowedTypes('paybox_identifier', 'string'); |
||
173 | $resolver->setAllowedTypes('paybox_key', 'string'); |
||
174 | |||
175 | $resolver->setAllowedValues('paybox_version', Version::getConstants()); |
||
176 | $resolver->setAllowedValues('paybox_default_activity', Activity::getConstants()); |
||
177 | } |
||
178 | } |
||
179 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.