RefundRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 19
c 3
b 0
f 1
dl 0
loc 41
ccs 20
cts 20
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sendData() 0 18 2
A getData() 0 11 1
1
<?php
2
3
namespace Omnipay\IcepayPayments\Message;
4
5
use Omnipay\Common\Exception\InvalidRequestException;
6
use Omnipay\Common\Message\ResponseInterface;
7
use Symfony\Component\HttpFoundation\Request;
8
9
/**
10
 * The request for refunding at Icepay.
11
 */
12
class RefundRequest extends AbstractRequest
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 3
    public function getData(): array
18
    {
19 3
        $data = parent::getData();
20
21 3
        $data['ContractProfileId'] = $this->getContractProfileId();
22 3
        $data['AmountInCents'] = $this->getAmountInteger();
23 3
        $data['CurrencyCode'] = $this->getCurrencyCode();
24 3
        $data['Reference'] = $this->getReference(); // This isn't the payment reference but needs to be unique among refunds.
25 3
        $data['Timestamp'] = $this->getTimestamp()->format(self::TIMESTAMP_FORMAT);
26
27 3
        return $data;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     *
33
     * @throws InvalidRequestException when transaction reference is not set
34
     */
35 2
    public function sendData($data): ResponseInterface
36
    {
37 2
        if (empty($this->getTransactionReference())) {
38 1
            throw new InvalidRequestException('Transaction reference missing for refund request.');
39
        }
40
41 1
        $this->sendRequest(
42 1
            Request::METHOD_POST,
43 1
            sprintf(
44 1
                '/transaction/%s/refund',
45 1
                $this->getTransactionReference()
46
            ),
47 1
            $data
48
        );
49
50 1
        return new RefundResponse(
51 1
            $this,
52 1
            $this->getResponseBody()
53
        );
54
    }
55
}
56