Passed
Push — main ( 007e00...f82f47 )
by
unknown
09:50
created

CompletePurchaseRequest::sendData()   A

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
        $this->validate('sessionId');
15
16
        return [
17
            'sessionId' => $this->getSessionId(),
18
        ];
19
    }
20
21
    public function setSessionId($sessionId)
22
    {
23
        return $this->setParameter('sessionId', $sessionId);
24
    }
25
26
    public function getSessionId()
27
    {
28
        return $this->getParameter('sessionId');
29
    }
30
31
    public function sendData($data)
32
    {
33
        if ( !$data['sessionId'] ) {
34
            throw new InvalidRequestException('Session id is required');
35
        }
36
37
        $sessionId = $data['sessionId'];
38
39
        $headers = [
40
            'Accept' => 'application/json',
41
            'Content-Type' => 'application/json',
42
            'Authorization' => 'Basic ' . $this->getAuthorization()
43
        ];
44
45
        try {
46
            $httpResponse = $this->httpClient->request('GET', $this->getEndpoint('sessions/' . $sessionId), $headers);
47
        } catch (\Exception $exception) {
48
            throw new InvalidRequestException($exception->getMessage());
49
        }
50
51
        $transactionData = json_decode($httpResponse->getBody()->getContents(), true);
52
53
        return $this->response = new CompletePurchaseResponse($this, $transactionData);
54
    }
55
}
56