BankAccountTrait::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 BankAccountTrait.
12
 *
13
 * @author    Andreas Lange <[email protected]>
14
 * @copyright 2016, Connox GmbH
15
 * @license   MIT
16
 */
17
trait BankAccountTrait
18
{
19
    /**
20
     * Get the payment issuer.
21
     *
22
     * @return string
23
     *
24
     * @codeCoverageIgnore
25
     */
26
    abstract public function getPaymentMethod();
27
28
    /**
29
     * Gets the account holder.
30
     *
31
     * @return string|null Account holder name.
32
     */
33 3
    public function getAccountHolder()
34
    {
35 3
        return $this->getParameter('accountHolder');
36
    }
37
38
    /**
39
     * Gets the account number.
40
     *
41
     * @return string|null Account number, generally IBAN for euro countries
42
     */
43 3
    public function getAccountNumber()
44
    {
45 3
        return $this->getParameter('accountNumber');
46
    }
47
48
    /**
49
     * Gets the account sort code
50
     *
51
     * @return string|null Sort code, generally the BIC
52
     */
53 3
    public function getSortCode()
54
    {
55 3
        return $this->getParameter('sortCode');
56
    }
57
58
    /**
59
     * Sets the account holder.
60
     *
61
     * @param string $value Account Holder
62
     *
63
     * @return AuthorizeRequest
64
     */
65 11
    public function setAccountHolder($value)
66
    {
67 11
        return $this->setParameter('accountHolder', $value);
68
    }
69
70
    /**
71
     * Sets the account number.
72
     *
73
     * @param string $value Account number, generally IBAN number
74
     *
75
     * @return AuthorizeRequest
76
     */
77 11
    public function setAccountNumber($value)
78
    {
79 11
        return $this->setParameter('accountNumber', $value);
80
    }
81
82
    /**
83
     * Sets the sort code.
84
     *
85
     * @param string $value Sort code, generally the BIC
86
     *
87
     * @return AuthorizeRequest
88
     */
89 11
    public function setSortCode($value)
90
    {
91 11
        return $this->setParameter('sortCode', $value);
92
    }
93
94
    /**
95
     * Appends the bank account information to the SimpleXMLElement.
96
     *
97
     * @param SimpleXMLElement $data
98
     *
99
     * @throws InvalidRequestException
100
     */
101 9
    protected function appendBankAccount(SimpleXMLElement $data)
102
    {
103 9
        if ($this->getPaymentMethod() === 'invoice') {
104 7
            return;
105
        }
106
107 2
        $data->addChild('bank_account');
108 2
        $data->bank_account[0]['accountholder'] = $this->getAccountHolder();
109 2
        $data->bank_account[0]['accountnumber'] = $this->getAccountNumber();
110 2
        $data->bank_account[0]['sortcode'] = $this->getSortCode();
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