DotpayManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
c 3
b 0
f 0
dl 0
loc 65
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A response() 0 3 1
A createPayment() 0 3 1
A refundPayment() 0 2 1
A callback() 0 7 2
1
<?php
2
3
namespace Evilnet\Dotpay;
4
5
use Evilnet\Dotpay\DotpayApi\DotpayApi;
6
use Evilnet\Dotpay\DotpayApi\Response;
7
use InvalidArgumentException;
8
9
/**
10
 * Class DotpayManager
11
 * @package Evilnet\Dotpay
12
 */
13
class DotpayManager
14
{
15
    /**
16
     * @var DotpayApi
17
     */
18
    private $dotpayApi;
19
    /**
20
     * @var
21
     */
22
    private $response;
23
24
    /**
25
     * DotpayManager constructor.
26
     * @param DotpayApi $dotpayApi
27
     */
28
    public function __construct(DotpayApi $dotpayApi)
29
    {
30
        $this->dotpayApi = $dotpayApi;
31
    }
32
33
    //It will return url for dotpay transaction
34
35
    /**
36
     * @param $data
37
     * @return mixed|string
38
     * @throws \GuzzleHttp\Exception\GuzzleException
39
     */
40
    public function createPayment($data)
41
    {
42
        return $this->dotpayApi->createPayment($data);
43
    }
44
45
    /**
46
     * @param $operation_number
47
     * @param $data
48
     * @return mixed
49
     * @throws Exceptions\RequestIntegrityException
50
     * @throws \GuzzleHttp\Exception\GuzzleException
51
     */
52
    public function refundPayment($operation_number, $data){
53
        return $this->dotpayApi->refundPayment($operation_number, $data);
54
    }
55
56
57
    /**
58
     * @return mixed
59
     */
60
    public function response()
61
    {
62
        return $this->response;
63
    }
64
65
    //It will listen for dotpay POST with status. We need to calculate hash and check status
66
67
    /**
68
     * @param array $data
69
     * @return Response
70
     */
71
    public function callback(array $data)
72
    {
73
        if ($this->dotpayApi->verifyCallback($data)) {
74
            return new Response($data);
75
        }
76
77
        throw new InvalidArgumentException('invalid_hash');
78
    }
79
}
80