CompletePurchaseRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
eloc 17
c 2
b 0
f 1
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 5 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
{
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