DotpayApi::getPaymentUrl()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 10
rs 10
cc 3
nc 3
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
     * @throws \GuzzleHttp\Exception\GuzzleException
47
     */
48
    public function createPayment($payment)
49
    {
50
        return $this->getPaymentUrl($this->client->makeRequest(new CreatePaymentLink($this->config['shop_id'], $payment)));
51
    }
52
53
    /**
54
     * @param $payment
55
     * @param $operation_number
56
     * @return mixed
57
     * @throws \Evilnet\Dotpay\Exceptions\RequestIntegrityException
58
     * @throws \GuzzleHttp\Exception\GuzzleException
59
     */
60
    public function refundPayment($operation_number, $payment){
61
        return $this->client->makeRequest(new CreateRefund($operation_number, $payment));
62
    }
63
64
    /**
65
     * @param $payment
66
     * @return mixed|string
67
     */
68
    public function getPaymentUrl($payment)
69
    {
70
        switch ($this->config['api_version']) {
71
            case 'dev':
72
            default:
73
                return $this->url_creator->getPaymentUrlWithCHK($payment);
74
                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...
75
            case 'legacy':
76
                return $this->url_creator->getPaymentUrl($payment);
77
                break;
78
        }
79
    }
80
81
    /**
82
     * @param $data
83
     * @return bool
84
     */
85
    public function verifyCallback($data)
86
    {
87
        return $this->validator->verify($data);
88
    }
89
}
90