CompletePurchaseRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 1
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 2 1
A sendData() 0 23 3
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