RefundRequest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 29
ccs 18
cts 18
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getData() 0 27 2
1
<?php
2
3
namespace Omnipay\Moneris\Message;
4
5
use Omnipay\Common\Exception\InvalidRequestException;
6
7
class RefundRequest extends AbstractRequest
8
{
9 12
    public function getData()
10
    {
11 12
        $this->validate('amount', 'transactionReference');
12
13
        try {
14 12
            $transactionReference = simplexml_load_string($this->getTransactionReference());
15 3
        } catch (\Exception $e) {
16 3
            throw new InvalidRequestException('Invalid transaction reference');
17
        }
18
19 9
        $transactionReceipt = $transactionReference->receipt;
20
21 9
        $request = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><request></request>');
22 9
        $request->addChild('store_id', $this->getMerchantId());
23 9
        $request->addChild('api_token', $this->getMerchantKey());
24
25 9
        $refund = $request->addChild('refund');
26 9
        $refund->addChild('order_id', $transactionReceipt->ReceiptId);
27 9
        $refund->addChild('amount', $this->getAmount());
28 9
        $refund->addChild('txn_number', $transactionReceipt->TransID);
29 9
        $refund->addChild('crypt_type', $this->getCryptType());
30 9
        $refund->addChild('cust_id', $transactionReceipt->ReferenceNum);
31 9
        $refund->addChild('dynamic_descriptor', 'Refund');
32
33 9
        $data = $request->asXML();
34
35 9
        return preg_replace('/\n/', '', $data);
36
    }
37
}
38