Completed
Push — master ( a52065...6a2a6b )
by Dmitry
02:22
created

PurchaseRequest::getTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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()
26
    {
27
        return $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
        ]);
52
    }
53
54
    public function calculateSignature()
55
    {
56
        return md5(implode(':', [
57
            $this->getPurse(),
58
            $this->getAmount(),
59
            $this->getSecretKey(),
60
            $this->getTransactionId()
61
        ]));
62
    }
63
64
    public function sendData($data)
65
    {
66
        return $this->response = new PurchaseResponse($this, $data);
67
    }
68
}
69