-
Notifications
You must be signed in to change notification settings - Fork 28
/
class.SEPAGroupHeader.php
187 lines (163 loc) · 4.39 KB
/
class.SEPAGroupHeader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
* This class organizes the GrpHdr element of a SEPA message.
*
* @author Johannes Feichtner <[email protected]>
* @copyright http://www.web-wack.at web wack creations
* @license http://creativecommons.org/licenses/by-nc/3.0/ CC Attribution-NonCommercial 3.0 license
* For commercial use please contact [email protected]
*/
class SEPAGroupHeader {
/**
* Point to point reference assigned by the instructing party and sent to the next party in the chain
* to unambiguously identify the message. (Tag: <MsgId>)
*
* @var string
*/
private $messageIdentification = '';
/**
* Date and time at which a (group of) payment instruction(s) was created
* by the instructing party. (Tag: <CreDtTm>)
*
* @var DateTime object
*/
private $creationDateTime = null;
/**
* Number of individual transactions contained in the message. (Tag: <NbOfTxs>)
*
* @var int
*/
private $numberOfTransactions = 0;
/**
* Total of all individual amounts included in the message. (Tag: <CtrlSum>)
*
* @var float
*/
private $controlSum = 0.00;
/**
* Party that initiates the payment. This can either be the creditor or a party that initiates
* the direct debit on behalf of the creditor. (Tag: <InitgPty->Nm>)
*
* @var string
*/
private $initiatingPartyName = '';
/**
* Getter for Message Identification (MsgId)
*
* @return string
*/
public function getMessageIdentification()
{
return $this->messageIdentification;
}
/**
* Setter for Message Identification (MsgId)
*
* @param $msgId
* @throws SEPAException
*/
public function setMessageIdentification($msgId)
{
$msgId = URLify::downcode($msgId, "de");
if (!preg_match("/^([A-Za-z0-9]|[\+|\?|\/|\-|:|\(|\)|\.|,|'| ]){1,35}\z/", $msgId))
throw new SEPAException("MsgId empty, contains invalid characters or too long (max. 35).");
$this->messageIdentification = $msgId;
}
/**
* Getter for Creation Date Time (CreDtTm)
*
* @return DateTime object
*/
public function getCreationDateTime()
{
$creationDate = new DateTime();
if (!$this->creationDateTime)
$this->creationDateTime = $creationDate->format('Y-m-d\TH:i:s');
return $this->creationDateTime;
}
/**
* Setter for Creation Date Time (CreDtTm)
*
* @param string $creDtTm
*/
public function setCreationDateTime($creDtTm)
{
$this->creationDateTime = $creDtTm;
}
/**
* Getter for Number of Transactions (NbOfTxs)
*
* @return int
*/
public function getNumberOfTransactions()
{
return $this->numberOfTransactions;
}
/**
* Setter for Number of Transactions (NbOfTxs)
*
* @param int $nbOfTxs
* @throws SEPAException
*/
public function setNumberOfTransactions($nbOfTxs)
{
if (!preg_match("/^[0-9]{1,15}\z/", $nbOfTxs))
throw new SEPAException("Invalid NbOfTxs value (max. 15 digits).");
$this->numberOfTransactions = $nbOfTxs;
}
/**
* Getter for ControlSum (CtrlSum)
*
* @return float
*/
public function getControlSum()
{
return $this->controlSum;
}
/**
* Setter for ControlSum (CtrlSum)
*
* @param float $ctrlSum
*/
public function setControlSum($ctrlSum)
{
$this->controlSum = floatval($ctrlSum);
}
/**
* Getter for Initiating Party Name (InitgPty->Nm)
*
* @return string
*/
public function getInitiatingPartyName()
{
return $this->initiatingPartyName;
}
/**
* Setter for Initiating Party Name (InitgPty->Nm)
*
* @param string $initgPty
* @throws SEPAException
*/
public function setInitiatingPartyName($initgPty)
{
$initgPty = URLify::downcode($initgPty, "de");
if (strlen($initgPty) == 0 || strlen($initgPty) > 70)
throw new SEPAException("Invalid initiating party name (max. 70).");
$this->initiatingPartyName = $initgPty;
}
/**
* Returns a SimpleXMLElement for the SEPAGroupHeader object.
*
* @return SimpleXMLElement object
*/
public function getXmlGroupHeader()
{
$xml = new SimpleXMLElement("<GrpHdr></GrpHdr>");
$xml->addChild('MsgId', $this->getMessageIdentification());
$xml->addChild('CreDtTm', $this->getCreationDateTime());
$xml->addChild('NbOfTxs', $this->getNumberOfTransactions());
$xml->addChild('CtrlSum', $this->getControlSum());
$xml->addChild('InitgPty')->addChild('Nm', $this->getInitiatingPartyName());
return $xml;
}
}