Payment_Adaptive_Refund   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 47
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A refund() 0 4 1
B do_refund() 0 34 7
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