PurchaseRequest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 2
dl 0
loc 57
ccs 0
cts 46
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getLanguage() 0 4 1
A setLanguage() 0 4 1
A getClient() 0 4 1
A setClient() 0 4 1
A getData() 0 19 1
A calculateSignature() 0 9 1
A sendData() 0 4 1
1
<?php
2
/**
3
 * FreeKassa driver for Omnipay PHP payment library
4
 *
5
 * @link      https://github.com/hiqdev/omnipay-freekassa
6
 * @package   omnipay-freekassa
7
 * @license   MIT
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace Omnipay\FreeKassa\Message;
12
13
class PurchaseRequest extends AbstractRequest
14
{
15
    public function getLanguage()
16
    {
17
        return $this->getParameter('language');
18
    }
19
20
    public function setLanguage($value)
21
    {
22
        return $this->setParameter('language', $value);
23
    }
24
25
    public function getClient(): string
26
    {
27
        return (string) $this->getParameter('client');
28
    }
29
30
    public function setClient($value)
31
    {
32
        return $this->setParameter('client', $value);
33
    }
34
35
    public function getData()
36
    {
37
        $this->validate(
38
            'purse', 'secretKey',
39
            'amount', 'currency', 'transactionId'
40
        );
41
42
        return array_filter([
43
            'm' => $this->getPurse(),
44
            'oa' => $this->getAmount(),
45
            'o' => $this->getTransactionId(),
46
            'i' => strtolower($this->getCurrency()),
47
            's' => $this->calculateSignature(),
48
            'lang' => $this->getLanguage(),
49
            'us_client' => $this->getClient(),
50
            'us_system' => 'freekassa',
51
            'us_currency' => strtoupper($this->getCurrency() ?? 'RUB'),
52
        ]);
53
    }
54
55
    public function calculateSignature()
56
    {
57
        return md5(implode(':', [
58
            $this->getPurse(),
59
            $this->getAmount(),
60
            $this->getSecretKey(),
61
            $this->getTransactionId()
62
        ]));
63
    }
64
65
    public function sendData($data)
66
    {
67
        return $this->response = new PurchaseResponse($this, $data);
68
    }
69
}
70