Passed
Push — main ( f60e44...b1b5d7 )
by
unknown
08:37
created

AcceptNotification::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Omnipay\WindcaveHpp\Message;
4
5
use Omnipay\Common\Exception\InvalidRequestException;
6
use Omnipay\Common\Message\AbstractRequest;
7
use Omnipay\Common\Message\NotificationInterface;
8
9
class AcceptNotification extends PurchaseRequest {
10
    public function getData()
11
    {
12
        return [
13
            'sessionId' => $this->httpRequest->query->get('sessionId') ?? $this->httpRequest->request->get('sessionId') ?? '',
14
            'username' => $this->httpRequest->query->get('username') ?? $this->httpRequest->request->get('username') ?? '',
15
        ];
16
    }
17
    public function sendData($data)
18
    {
19
        if ( empty($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
}