RefundRequest::getData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
ccs 8
cts 8
cp 1
crap 1
rs 10
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