Test Failed
Branch master (3f2e80)
by Gabriel
03:43 queued 01:39
created

CaptureRequest::getData()   A

Complexity

Conditions 4
Paths 12

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
c 1
b 0
f 1
dl 0
loc 26
rs 9.7666
cc 4
nc 12
nop 0
1
<?php
2
3
namespace ByTIC\Omnipay\Paylike\Message;
4
5
use ByTIC\Omnipay\Paylike\Traits\HasApiTrait;
6
7
/**
8
 * Class CaptureRequest
9
 * @package ByTIC\Omnipay\Paylike\Message
10
 *
11
 * @method CaptureResponse send
12
 */
13
class CaptureRequest extends AbstractRequest
14
{
15
    use HasApiTrait;
16
17
    /**
18
     * @return array
19
     * @throws \Omnipay\Common\Exception\InvalidRequestException
20
     */
21
    public function getData()
22
    {
23
        $this->validate('privateKey', 'transactionId', 'amount');
24
25
        $data = ['success' => false];
26
27
        try {
28
            $transactions = $this->getApi()->transactions();
29
            $transaction = $transactions->capture(
30
                $this->getTransactionId(),
31
                [
32
                    'amount' => $this->getAmount() * 100,
33
//                    'currency' => 'EUR'
34
                ]
35
            );
36
            if (is_array($transaction)) {
0 ignored issues
show
introduced by
The condition is_array($transaction) is always true.
Loading history...
37
                $data['transaction'] = $transaction;
38
                $data['success'] = true;
39
            }
40
        } catch (\Paylike\Exception\NotFound $e) {
41
            $data['message'] = "The transaction was not found";
42
        } catch (\Paylike\Exception\ApiException $e) {
43
            $data['message'] = "Api Error:" . $e->getMessage();
44
        }
45
46
        return $data;
47
    }
48
}
49