CompletePurchaseRequest::getData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
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