PurchaseRequest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 11
Bugs 0 Features 2
Metric Value
eloc 32
c 11
b 0
f 2
dl 0
loc 58
ccs 0
cts 42
cp 0
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A generateSignature() 0 20 4
A sendData() 0 3 1
A getData() 0 17 1
A getCustomFields() 0 10 1
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
            'InvId' => $this->getInvId(),
23
            'MerchantLogin' => $this->getPurse(),
24
            'OutSum' => $this->getAmount(),
25
            'Description' => $this->getDescription(),
26
            'IncCurrLabel' => $this->getCurrencyLabel(),
27
            'OutSumCurrency' => $this->getCurrency(),
28
            'SignatureValue' => $this->generateSignature(),
29
            'IsTest' => (int) $this->getTestMode(),
30
            'Receipt' => $this->getReceipt(),
31
        ] + $this->getCustomFields();
32
    }
33
34
    public function generateSignature()
35
    {
36
        $params = [
37
            $this->getPurse(),
38
            $this->getAmount(),
39
            $this->getInvId()
40
        ];
41
        if ($this->getCurrency()) {
42
            $params[] = $this->getCurrency();
43
        }
44
        if ($this->getReceipt()) {
45
            $params[] = $this->getReceipt();
46
        }
47
        $params[] = $this->getSecretKey();
48
49
        foreach ($this->getCustomFields() as $field => $value) {
50
            $params[] = "$field=$value";
51
        }
52
53
        return md5(implode(':', $params));
54
    }
55
56
    public function getCustomFields()
57
    {
58
        $fields = array_filter([
59
            'Shp_TransactionId' => $this->getTransactionId(),
60
            'Shp_Client' => $this->getClient()
61
        ]);
62
63
        ksort($fields);
64
65
        return $fields;
66
    }
67
68
    public function sendData($data)
69
    {
70
        return $this->response = new PurchaseResponse($this, $data);
71
    }
72
}
73