RateTrait::getPaymentMethod()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 1
1
<?php
2
3
namespace Omnipay\BillPay\Message\RequestData;
4
5
use Omnipay\BillPay\Message\AuthorizeRequest;
6
use Omnipay\Common\Exception\InvalidRequestException;
7
use Omnipay\Common\Message\AbstractRequest;
8
use SimpleXMLElement;
9
10
/**
11
 * Class RateTrait.
12
 *
13
 * @author    Andreas Lange <[email protected]>
14
 * @copyright 2016, Connox GmbH
15
 * @license   MIT
16
 */
17
trait RateTrait
18
{
19
    /**
20
     * Get the payment issuer.
21
     *
22
     * @return string
23
     *
24
     * @codeCoverageIgnore
25
     */
26
    abstract public function getPaymentMethod();
27
28
    /**
29
     * Gets count of installments to be paid during the term.
30
     *
31
     * @return int|null Count of installments to be paid during the term.
32
     */
33 3
    public function getRateCount()
34
    {
35 3
        return $this->getParameter('rateCount');
36
    }
37
38
    /**
39
     * Gets term of the installment plan.
40
     *
41
     * @return int|null months
42
     */
43 3
    public function getRateTerm()
44
    {
45 3
        return $this->getParameter('rateTerm');
46
    }
47
48
    /**
49
     * Gets total amount of the installments plan including the transaction credit interest / PayLater fee.
50
     *
51
     * @return float|null adjusted amount including all fees and interest
52
     */
53 3
    public function getRateTotalAmount()
54
    {
55 3
        return $this->getParameter('rateTotalAmount');
56
    }
57
58
    /**
59
     * Sets count of installments to be paid during the term.
60
     *
61
     * @param string $value Count of installments to be paid during the term.
62
     *
63
     * @return AuthorizeRequest
64
     */
65 11
    public function setRateCount($value)
66
    {
67 11
        return $this->setParameter('rateCount', $value);
68
    }
69
70
    /**
71
     * Sets term of the installment plan.
72
     *
73
     * @param int $value months
74
     *
75
     * @return AuthorizeRequest
76
     */
77 11
    public function setRateTerm($value)
78
    {
79 11
        return $this->setParameter('rateTerm', $value);
80
    }
81
82
    /**
83
     * Sets total amount of the installments plan including the transaction credit interest / PayLater fee.
84
     *
85
     * @param float $value
86
     *
87
     * @return AuthorizeRequest
88
     */
89 11
    public function setRateTotalAmount($value)
90
    {
91 11
        return $this->setParameter('rateTotalAmount', $value);
92
    }
93
94
    /**
95
     * Appends the rate request node to the SimpleXMLElement.
96
     *
97
     * @param SimpleXMLElement $data
98
     *
99
     * @throws InvalidRequestException
100
     */
101 9 View Code Duplication
    protected function appendRate(SimpleXMLElement $data)
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...
102
    {
103 9
        if ($this->getPaymentMethod() !== 'pay_later') {
104 7
            return;
105
        }
106
107 2
        $data->addChild('rate_request');
108 2
        $data->rate_request[0]['term'] = $this->getRateTerm();
109 2
        $data->rate_request[0]['ratecount'] = $this->getRateCount();
110 2
        $data->rate_request[0]['totalamount'] = round(bcmul($this->getRateTotalAmount(), 100, 8));
111 2
    }
112
113
    /**
114
     * Get a single parameter.
115
     *
116
     * @param string $key The parameter key
117
     *
118
     * @return mixed
119
     *
120
     * @codeCoverageIgnore
121
     */
122
    abstract protected function getParameter($key);
123
124
    /**
125
     * Set a single parameter.
126
     *
127
     * @param string $key   The parameter key
128
     * @param mixed  $value The value to set
129
     *
130
     * @return AbstractRequest Provides a fluent interface
131
     *
132
     * @codeCoverageIgnore
133
     */
134
    abstract protected function setParameter($key, $value);
135
}
136