Passed
Push — main ( e581bb...d1e597 )
by
unknown
03:06
created

CompletePurchaseRequest::setSessionId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
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 $this->httpRequest->request->all();
15
16
    }
17
    public function sendData($data)
18
    {
19
        if ( !$data['sessionId'] ) {
20
            throw new InvalidRequestException('Session id is required');
21
        }
22
23
        $sessionId = $data['sessionId'];
24
25
        $headers = [
26
            'Accept' => 'application/json',
27
            'Content-Type' => 'application/json',
28
            'Authorization' => 'Basic ' . $this->getAuthorization()
29
        ];
30
31
        try {
32
            $httpResponse = $this->httpClient->request('GET', $this->getEndpoint('sessions/' . $sessionId), $headers);
33
        } catch (\Exception $exception) {
34
            throw new InvalidRequestException($exception->getMessage());
35
        }
36
37
        $transactionData = json_decode($httpResponse->getBody()->getContents(), true);
38
39
        return $this->response = new CompletePurchaseResponse($this, $transactionData);
40
    }
41
}
42