Payment_Adaptive_Refund::do_refund()   B
last analyzed

Complexity

Conditions 7
Paths 13

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 0
cts 28
cp 0
rs 8.4426
c 0
b 0
f 0
cc 7
nc 13
nop 3
crap 56
1
<?php
2
3
namespace OpenBuildings\PayPal;
4
5
class Payment_Adaptive_Refund extends Payment_Adaptive {
6
7
	const API_OPERATION_REFUND = 'Refund';
8
9
	/**
10
	 * Perform a low-level Refund API request.
11
	 */
12
	public function refund($data)
13
	{
14
		return $this->_request(self::API_OPERATION_REFUND, $data);
15
	}
16
17
	public function do_refund(array $transaction, array $receivers = NULL, $chained = FALSE)
18
	{
19
		if (empty($transaction['payKey']) AND empty($transaction['trackingId']))
20
			throw new Exception('You must provide either "payKey" or "trackingId" to Refund API operation.');
21
22
		$data = array(
23
			'currencyCode' => $this->config('currency')
24
		);
25
26
		if (isset($transaction['payKey']))
27
		{
28
			$data['payKey'] = $transaction['payKey'];
29
		}
30
		elseif (isset($transaction['trackingId']))
31
		{
32
			$data['trackingId'] = $transaction['trackingId'];
33
		}
34
35
		if (isset($transaction['transactionId']))
36
		{
37
			$data['transactionId'] = $transaction['transactionId'];
38
		}
39
40
		if ($receivers)
41
		{
42
			$data['receiverList'] = Util::receiver_list($receivers, $chained);
43
44
			$receiver_list = Util::array_to_nvp($data, 'receiverList', 'receiver');
45
			unset($data['receiverList']);
46
			$data = array_merge_recursive($data, $receiver_list);
47
		}
48
49
		return $this->refund($data);
50
	}
51
}
52