CompletePurchaseRequest::sendData()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 23
rs 9.8333
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Omnipay\WindcaveHpp\Message;
4
5
use Omnipay\Common\Exception\InvalidRequestException;
6
7
/**
8
 * Windcave HPP Complete Purchase Request
9
 */
10
class CompletePurchaseRequest extends PurchaseRequest
11
{
12
    public function getData()
13
    {
14
        return [
15
            'sessionId' => $this->getParameter('sessionId') ?? $this->httpRequest->query->get('sessionId') ?? $this->httpRequest->request->get('sessionId') ?? '',
16
            'username' => $this->getParameter('username') ?? $this->httpRequest->query->get('username') ?? $this->httpRequest->request->get('username') ?? '',
17
        ];
18
    }
19
    public function sendData($data)
20
    {
21
        if ( !$data['sessionId'] ) {
22
            throw new InvalidRequestException('Session id is required');
23
        }
24
25
        $sessionId = $data['sessionId'];
26
27
        $headers = [
28
            'Accept' => 'application/json',
29
            'Content-Type' => 'application/json',
30
            'Authorization' => 'Basic ' . $this->getAuthorization()
31
        ];
32
33
        try {
34
            $httpResponse = $this->httpClient->request('GET', $this->getEndpoint('sessions/' . $sessionId), $headers);
35
        } catch (\Exception $exception) {
36
            throw new InvalidRequestException($exception->getMessage());
37
        }
38
39
        $transactionData = json_decode($httpResponse->getBody()->getContents(), true);
40
41
        return $this->response = new CompletePurchaseResponse($this, $transactionData);
42
    }
43
}
44