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