InvoiceTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 94
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
getAmount() 0 1 ?
getCurrency() 0 1 ?
getTransactionId() 0 1 ?
getParameter() 0 1 ?
setParameter() 0 1 ?
A getDelayInDays() 0 4 2
A setDelayInDays() 0 4 1
A appendInvoice() 0 8 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 InvoiceTrait.
12
 *
13
 * @author    Andreas Lange <[email protected]>
14
 * @copyright 2016, Connox GmbH
15
 * @license   MIT
16
 */
17
trait InvoiceTrait
18
{
19
    /**
20
     * Validates and returns the formated amount.
21
     *
22
     * @throws InvalidRequestException on any validation failure.
23
     *
24
     * @return string The amount formatted to the correct number of decimal places for the selected currency.
25
     *
26
     * @codeCoverageIgnore
27
     */
28
    abstract public function getAmount();
29
30
    /**
31
     * Get the payment currency code.
32
     *
33
     * @return string
34
     *
35
     * @codeCoverageIgnore
36
     */
37
    abstract public function getCurrency();
38
39
    /**
40
     * Gets amount of days that will be added to the payment due date (e.g. in case of delayed shipping).
41
     *
42
     * @return int Days
43
     */
44 2
    public function getDelayInDays()
45
    {
46 2
        return $this->getParameter('delayInDays') ? : 5;
47
    }
48
49
    /**
50
     * Get the transaction ID.
51
     *
52
     * The transaction ID is the identifier generated by the merchant website.
53
     *
54
     * @return string
55
     *
56
     * @codeCoverageIgnore
57
     */
58
    abstract public function getTransactionId();
59
60
    /**
61
     * Amount of days that will be added to the payment due date (e.g. in case of delayed shipping).
62
     *
63
     * @param int $value
64
     *
65
     * @return AuthorizeRequest
66
     */
67 1
    public function setDelayInDays($value)
68
    {
69 1
        return $this->setParameter('delayInDays', $value);
70
    }
71
72
    /**
73
     * Appends the rate request node to the SimpleXMLElement.
74
     *
75
     * @param SimpleXMLElement $data
76
     *
77
     * @throws InvalidRequestException
78
     */
79 2
    protected function appendInvoice(SimpleXMLElement $data)
80
    {
81 2
        $data->addChild('invoice_params');
82 2
        $data->invoice_params[0]['carttotalgross'] = round(bcmul($this->getAmount(), 100, 8));
83 2
        $data->invoice_params[0]['currency'] = $this->getCurrency();
84 2
        $data->invoice_params[0]['reference'] = $this->getTransactionId();
85 2
        $data->invoice_params[0]['delayindays'] = $this->getDelayInDays();
86 2
    }
87
88
    /**
89
     * Get a single parameter.
90
     *
91
     * @param string $key The parameter key
92
     *
93
     * @return mixed
94
     *
95
     * @codeCoverageIgnore
96
     */
97
    abstract protected function getParameter($key);
98
99
    /**
100
     * Set a single parameter.
101
     *
102
     * @param string $key   The parameter key
103
     * @param mixed  $value The value to set
104
     *
105
     * @return AbstractRequest Provides a fluent interface
106
     *
107
     * @codeCoverageIgnore
108
     */
109
    abstract protected function setParameter($key, $value);
110
}
111