Passed
Push — master ( ca7ad6...579b04 )
by Mykolas
02:00
created

Api   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 13
c 1
b 1
f 0
dl 0
loc 44
ccs 16
cts 18
cp 0.8889
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A doPayment() 0 8 2
A __construct() 0 5 1
A doNotify() 0 3 1
A getApiOptions() 0 3 1
A getApiEndpoint() 0 3 1
1
<?php
2
namespace PTS\Paysera;
3
4
use function League\Uri\create;
5
use Payum\Core\Bridge\Spl\ArrayObject;
6
use Payum\Core\Reply\HttpPostRedirect;
7
use WebToPay;
8
9
class Api
10
{
11
    /**
12
     * @var mixed
13
     */
14
    protected $options = [];
15
16
    /**
17
     * Api constructor.
18
     * @param array $options
19
     */
20 4
    public function __construct(array $options)
21
    {
22 4
        $options = ArrayObject::ensureArrayObject($options);
23 4
        $options->defaults($this->options);
24 4
        $this->options = $options;
25 4
    }
26
27 2
    public function doPayment(array $fields)
28
    {
29 2
        $fields['projectid'] = $this->options['projectid'];
30 2
        $fields['sign_password'] = $this->options['sign_password'];
31 2
        $this->options['test'] ? $fields['test'] = 1 : $fields['test'] = 0;
32 2
        $authorizeTokenUrl = $this->getApiEndpoint();
33 2
        $data = WebToPay::buildRequest($fields);
34 1
        throw new HttpPostRedirect($authorizeTokenUrl, $data);
35
    }
36
37 1
    public function doNotify(array $fields)
38
    {
39 1
        return WebToPay::validateAndParseData($fields, $this->options['projectid'], $this->options['sign_password']);
40
    }
41
42
    /**
43
     * @return string
44
     */
45 2
    protected function getApiEndpoint()
46
    {
47 2
        return WebToPay::PAY_URL;
48
    }
49
50
    public function getApiOptions()
51
    {
52
        return $this->options;
53
    }
54
}
55