1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Larium\Pay\Client; |
4
|
|
|
|
5
|
|
|
use Psr\Http\Message\RequestInterface; |
6
|
|
|
use Psr\Http\Message\ResponseInterface; |
7
|
|
|
use Http\Discovery\HttpClientDiscovery; |
8
|
|
|
use Http\Discovery\MessageFactoryDiscovery; |
9
|
|
|
|
10
|
|
|
class XmlClient extends AbstractClient |
11
|
|
|
{ |
12
|
|
|
private $uri; |
13
|
|
|
|
14
|
|
|
private $rawRequest; |
15
|
|
|
|
16
|
|
|
private $options; |
17
|
|
|
|
18
|
|
|
public function __construct($uri, array $options = []) |
19
|
|
|
{ |
20
|
|
|
$this->uri = $uri; |
21
|
|
|
$this->options = $options; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Post given xml string to remote gateway. |
26
|
|
|
* |
27
|
|
|
* @param string $xml |
28
|
|
|
* @return array @see self::resolveResponse |
29
|
|
|
*/ |
30
|
|
|
public function post($xml) |
31
|
|
|
{ |
32
|
|
|
$factory = $this->getMessageFactory(); |
33
|
|
|
$request = $factory->createRequest('POST', $this->uri, [], $xml); |
34
|
|
|
|
35
|
|
|
return $this->resolveResponse($this->sendRequest($request)); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
private function getMessageFactory() |
39
|
|
|
{ |
40
|
|
|
return MessageFactoryDiscovery::find(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Resolve the response from client. |
45
|
|
|
* |
46
|
|
|
* @param ResponseInterface $response |
47
|
|
|
* @return array An array with following values: |
48
|
|
|
* 'status' : The Http status of response |
49
|
|
|
* 'headers' : An array of response headers |
50
|
|
|
* 'body' : The response string. |
51
|
|
|
* 'raw_response': The raw body response for logging purposes. |
52
|
|
|
* 'raw_request' : The raw body request for logging purposes. |
53
|
|
|
*/ |
54
|
|
|
protected function resolveResponse(ResponseInterface $response) |
55
|
|
|
{ |
56
|
|
|
$body = $response->getBody()->__toString(); |
57
|
|
|
|
58
|
|
|
return array( |
59
|
|
|
'status' => $response->getStatusCode(), |
60
|
|
|
'headers' => $response->getHeaders(), |
61
|
|
|
'body' => $body, |
62
|
|
|
'raw_response' => $body, |
63
|
|
|
'raw_request' => $this->rawRequest, |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function authenticate(RequestInterface $request) |
68
|
|
|
{ |
69
|
|
|
return $request; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|