Api::doNotify()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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