Completed
Push — master ( 184d52...247cd7 )
by Andrii
02:13
created

AbstractRequest::getData()   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 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Generalization over Omnipay and Payum
4
 *
5
 * @link      https://github.com/hiqdev/php-merchant
6
 * @package   php-merchant
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\merchant;
12
13
/**
14
 * AbstractRequest class.
15
 */
16
abstract class AbstractRequest implements RequestInterface
17
{
18
    /**
19
     * @var AbstractMerchant
20
     */
21
    public $merchant;
22
23
    /**
24
     * @var string The type of request. For example:
25
     *  - `purchase`
26
     *  - `completePurchase`
27
     */
28
    public $type;
29
30
    /**
31
     * @var array the data that will be sent to the payment system.
32
     * Might be additionally processed by the implementation of [[AbstractRequest]] class.
33
     */
34
    public $data = [];
35
36
    /**
37
     * The instance of payment processing library.
38
     * @return \Omnipay\Common\Message\AbstractRequest|\Payum\Core\Model\Payment
39
     */
40
    abstract public function getWorker();
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getCurrency()
46
    {
47
        return $this->getWorker()->getCurrency();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getAmount()
54
    {
55
        return $this->getWorker()->getAmount();
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getFee()
62
    {
63
        return $this->data['fee'] ?: '0';
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getCommissionFee()
70
    {
71
        return $this->data['commission_fee'] ?: '0';
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getTotalFee()
78
    {
79
        return $this->getFee() + $this->getCommissionFee();
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getSum()
86
    {
87
        return $this->data['sum'] ?: $this->getAmount() - $this->getTotalFee();
88
    }
89
90
    /**
91
     * @return AbstractResponse
92
     */
93
    public function send()
94
    {
95
        return $this->merchant->response($this);
96
    }
97
98
    /**
99
     * Concrete requests can build type in other way.
100
     *
101
     * @return string
102
     */
103 1
    public function getType()
104
    {
105 1
        return Helper::id2camel($this->type);
106
    }
107
108
    /**
109
     * @return array
110
     */
111
    public function getData()
112
    {
113
        return $this->data;
114
    }
115
116
    /**
117
     * Use worker's method when possible.
118
     *
119
     * @param $name
120
     * @param $args
121
     * @return mixed|null
122
     */
123
    public function __call($name, $args)
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...
124
    {
125
        if (method_exists($this->getWorker(), $name)) {
126
            return call_user_func_array([$this->getWorker(), $name], $args);
127
        }
128
129
        return null;
130
    }
131
}
132