Passed
Pull Request — master (#13)
by
unknown
03:46
created

DotpayApi::refundPayment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Evilnet\Dotpay\DotpayApi;
4
5
use Evilnet\Dotpay\DotpayApi\Requests\CreatePaymentLink;
6
use Evilnet\Dotpay\DotpayApi\Requests\CreateRefund;
7
8
/**
9
 * Class DotpayApi
10
 * @package Evilnet\Dotpay\DotpayApi
11
 */
12
class DotpayApi
13
{
14
    /**
15
     * @var
16
     */
17
    private $config;
18
    /**
19
     * @var Client
20
     */
21
    private $client;
22
    /**
23
     * @var Validator
24
     */
25
    private $validator;
26
    /**
27
     * @var UrlCreator
28
     */
29
    private $url_creator;
30
31
    /**
32
     * DotpayApi constructor.
33
     * @param $config
34
     */
35
    public function __construct($config)
36
    {
37
        $this->config = $config;
38
        $this->client = new Client($this->config['username'], $this->config['password'], $this->config['base_url']);
39
        $this->validator = new Validator($this->config['pin']);
40
        $this->url_creator = new UrlCreator($this->config['pin']);
41
    }
42
43
    /**
44
     * @param $payment
45
     * @return mixed|string
46
     */
47
    public function createPayment($payment)
48
    {
49
        return $this->getPaymentUrl($this->client->makeRequest(new CreatePaymentLink($this->config['shop_id'], $payment)));
50
    }
51
52
    /**
53
     * @param $payment
54
     * @return mixed
55
     */
56
    public function refundPayment($payment){
57
        return $this->client->makeRequest(new CreateRefund($this->config['shop_id'], $payment));
58
    }
59
60
    /**
61
     * @param $payment
62
     * @return mixed|string
63
     */
64
    public function getPaymentUrl($payment)
65
    {
66
        switch ($this->config['api_version']) {
67
            case 'dev':
68
            default:
69
                return $this->url_creator->getPaymentUrlWithCHK($payment);
70
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
71
            case 'legacy':
72
                return $this->url_creator->getPaymentUrl($payment);
73
                break;
74
        }
75
    }
76
77
    /**
78
     * @param $data
79
     * @return bool
80
     */
81
    public function verifyCallback($data)
82
    {
83
        return $this->validator->verify($data);
84
    }
85
86
}
87