Passed
Push — main ( 19313d...a29eaf )
by Dan
01:56 queued 22s
created

RefundRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 16 2
A sendData() 0 17 2
1
<?php
2
3
namespace Omnipay\WindcaveHpp\Message;
4
5
use Omnipay\Common\Exception\InvalidRequestException;
6
use Omnipay\Common\Http\Exception;
7
8
class RefundRequest extends BaseRequest
9
{
10
    public function getData()
11
    {
12
        // Validate required parameters
13
        $this->validate('apiUsername', 'apiKey', 'amount', 'currency', 'transactionReference');
14
15
        $data = [];
16
        $data['type'] = 'refund';
17
        $data['amount'] = $this->getAmount();
18
        $data['currency'] = $this->getCurrency();
19
        $data['transactionId'] = $this->getTransactionReference();
20
21
        if ($this->getMerchantReference()) {
22
            $data['merchantReference'] = $this->getMerchantReference();
23
        }
24
25
        return $data;
26
    }
27
28
    public function sendData($data)
29
    {
30
        $headers = [
31
            'Accept'        => 'application/json',
32
            'Content-Type'  => 'application/json',
33
            'Authorization' => 'Basic ' . $this->getAuthorization(),
34
        ];
35
36
        $httpResponse = $this->httpClient->request('POST', $this->getEndpoint('transactions'), $headers, json_encode($data));
37
38
        try {
39
            $responseData = json_decode($httpResponse->getBody()->getContents());
40
        } catch (\Exception $exception) {
41
            $responseData = [];
42
        }
43
44
        return $this->response = new RefundResponse($this, $responseData ?? []);
45
    }
46
}