Passed
Pull Request — main (#4)
by
unknown
03:11
created

RefundRequest::sendData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 17
rs 9.9332
cc 2
nc 2
nop 1
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
}