Completed
Push — master ( c76d1a...b80522 )
by Dmitry
13:01
created

PurchaseRequest::setTime()   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 1
crap 2
1
<?php
2
/**
3
 * RoboKassa driver for Omnipay PHP payment library.
4
 *
5
 * @link      https://github.com/hiqdev/omnipay-robokassa
6
 * @package   omnipay-robokassa
7
 * @license   MIT
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace Omnipay\RoboKassa\Message;
12
13
class PurchaseRequest extends AbstractRequest
14
{
15
    public function getData()
16
    {
17
        $this->validate(
18
            'purse', 'amount', 'currency', 'description'
19
        );
20
21
        return [
22
            'MrchLogin' => $this->getPurse(),
23
            'OutSum' => $this->getAmount(),
24
            'Desc' => $this->getDescription(),
25
            'IncCurrLabel' => $this->getCurrency(),
26
            'SignatureValue' => $this->generateSignature(),
27
        ] + $this->getCustomFields();
28
    }
29
30 View Code Duplication
    public function generateSignature()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        $params = [
33
            $this->getPurse(),
34
            $this->getAmount(),
35
            '',
36
            $this->getSecretKey()
37
        ];
38
39
        foreach ($this->getCustomFields() as $field => $value) {
40
            $params[] = "$field=$value";
41
        }
42
43
        return md5(implode(':', $params));
44
    }
45
46 View Code Duplication
    public function getCustomFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        $fields = array_filter([
49
            'Shp_TransactionId' => $this->getTransactionId(),
50
            'Shp_Client' => $this->getClient(),
51
            'Shp_Currency' => $this->getCurrency()
52
        ]);
53
54
        ksort($fields);
55
56
        return $fields;
57
    }
58
59
    public function sendData($data)
60
    {
61
        return $this->response = new PurchaseResponse($this, $data);
62
    }
63
}
64