CaptureRequest::getData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 14
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Omnipay\PaypalRest\Message;
4
5
/**
6
 * @author    Ivan Kerin <[email protected]>
7
 * @copyright 2014, Clippings Ltd.
8
 * @license   http://spdx.org/licenses/BSD-3-Clause
9
 */
10
class CaptureRequest extends AbstractPaypalRequest
11
{
12
    /**
13
     * Requires "transactionReference" parameter
14
     *
15
     * @return string
16
     */
17
    public function getEndpoint()
18
    {
19
        $this->validate('transactionReference');
20
21
        return "/payments/authorization/{$this->getTransactionReference()}/capture";
22
    }
23
24
    /**
25
     * @return string
26
     */
27
    public function getHttpMethod()
28
    {
29
        return 'POST';
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    public function getIsFinalCapture()
36
    {
37
        return $this->getParameter('isFinalCapture');
38
    }
39
40
    /**
41
     * @param string $value
42
     */
43
    public function setIsFinalCapture($value)
44
    {
45
        return $this->setParameter('isFinalCapture', $value);
46
    }
47
48
    /**
49
     * @param  mixed           $data
50
     * @return CaptureResponse
51
     */
52
    public function sendData($data)
53
    {
54
        $httpResponse = $this->sendHttpRequest($data);
55
56
        return $this->response = new CaptureResponse(
57
            $this,
58
            $httpResponse->json(),
59
            $httpResponse->getStatusCode()
60
        );
61
    }
62
63
    /**
64
     * Requires "amount" and "currency" parameters
65
     *
66
     * @return array
67
     */
68
    public function getData()
69
    {
70
        $this->validate('amount', 'currency');
71
72
        $data = array(
73
            'amount' => array(
74
                'total' => $this->getAmount(),
75
                'currency' => $this->getCurrency(),
76
            )
77
        );
78
79
        if ($this->getIsFinalCapture()) {
80
            $data['is_final_capture'] = true;
81
        }
82
83
        return $data;
84
    }
85
}
86