Skip to content

Commit 6f443b2

Browse files
committed
feat: add info in the additional customer reference for bpost statistics
1 parent 77428d8 commit 6f443b2

13 files changed

+86
-30
lines changed

src/Bpost/Order/Box.php

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ class Box
5959
/** @var string */
6060
private $additionalCustomerReference;
6161

62+
/** @var string */
63+
private $additionalCustomerReferenceSuffix;
64+
65+
public function __construct()
66+
{
67+
$this->setAdditionalCustomerReferenceSuffix(sprintf('PHP%d.%d', PHP_MAJOR_VERSION, PHP_MINOR_VERSION));
68+
}
69+
6270
/**
6371
* @param \Bpost\BpostApiClient\Bpost\Order\Box\International $internationalBox
6472
*/
@@ -178,6 +186,24 @@ public function getAdditionalCustomerReference()
178186
return $this->additionalCustomerReference;
179187
}
180188

189+
/**
190+
* @return string
191+
*/
192+
public function getAdditionalCustomerReferenceSuffix()
193+
{
194+
return $this->additionalCustomerReferenceSuffix;
195+
}
196+
197+
/**
198+
* Must be used only for phpunit
199+
*
200+
* @param string $additionalCustomerReferenceSuffix
201+
*/
202+
public function setAdditionalCustomerReferenceSuffix($additionalCustomerReferenceSuffix)
203+
{
204+
$this->additionalCustomerReferenceSuffix = (string) $additionalCustomerReferenceSuffix;
205+
}
206+
181207
/**
182208
* @return array
183209
*/
@@ -361,13 +387,16 @@ private function remarkToXML(DOMDocument $document, $prefix, DOMElement $box)
361387
*/
362388
private function additionalCustomerReferenceToXML(DOMDocument $document, $prefix, DOMElement $box)
363389
{
364-
if ($this->getAdditionalCustomerReference() !== null) {
365-
$box->appendChild(
366-
$document->createElement(
367-
XmlHelper::getPrefixedTagName('additionalCustomerReference', $prefix),
368-
$this->getAdditionalCustomerReference()
369-
)
370-
);
371-
}
390+
$additionalCustomerReference = $this->getAdditionalCustomerReference()
391+
. '+' . $this->getAdditionalCustomerReferenceSuffix();
392+
$additionalCustomerReferenceSplits = str_split($additionalCustomerReference, 50);
393+
$additionalCustomerReference = $additionalCustomerReferenceSplits[0];
394+
$box->appendChild(
395+
$document->createElement(
396+
XmlHelper::getPrefixedTagName('additionalCustomerReference', $prefix),
397+
$additionalCustomerReference
398+
)
399+
);
400+
372401
}
373402
}

tests/Bpost/HttpRequestBuilder/CreateOrReplaceOrderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ private function getOrder()
114114
$box->setSender($sender);
115115
$box->setNationalBox($atBpost);
116116
$box->setRemark('bpack@bpost VAS 038 - COD+SAT+iD');
117-
$box->setAdditionalCustomerReference('Reference that can be used for cross-referencing');
117+
$box->setAdditionalCustomerReference('Reference used for bpost statistics');
118+
$box->setAdditionalCustomerReferenceSuffix('PHPx.y');
118119

119120
$order->setBoxes(array());
120121
$this->assertCount(0, $order->getBoxes());
@@ -188,7 +189,7 @@ private function getOrderXml()
188189
</atBpost>
189190
</tns:nationalBox>
190191
<tns:remark>bpack@bpost VAS 038 - COD+SAT+iD</tns:remark>
191-
<tns:additionalCustomerReference>Reference that can be used for cross-referencing</tns:additionalCustomerReference>
192+
<tns:additionalCustomerReference>Reference used for bpost statistics+PHPx.y</tns:additionalCustomerReference>
192193
</tns:box>
193194
</tns:order>
194195

tests/Bpost/Order/BoxTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function testNationalToXML()
6969
),
7070
),
7171
'remark' => 'remark',
72+
'additionalCustomerReferenceSuffix' => 'PHPx.y',
7273
'barcode' => 'BARCODE',
7374
);
7475

@@ -120,6 +121,12 @@ public function testNationalToXML()
120121
$box->appendChild($sender);
121122
$box->appendChild($nationalBox);
122123
$box->appendChild($expectedDocument->createElement('remark', $data['remark']));
124+
$box->appendChild(
125+
$expectedDocument->createElement(
126+
'additionalCustomerReference',
127+
'+' . $data['additionalCustomerReferenceSuffix']
128+
)
129+
);
123130
$box->appendChild($expectedDocument->createElement('barcode', $data['barcode']));
124131

125132
$actualDocument = self::createDomDocument();
@@ -165,6 +172,7 @@ public function testNationalToXML()
165172
$box->setNationalBox($atHome);
166173
$box->setRemark($data['remark']);
167174
$box->setBarcode($data['barcode']);
175+
$box->setAdditionalCustomerReferenceSuffix($data['additionalCustomerReferenceSuffix']);
168176

169177
$actualDocument->appendChild(
170178
$box->toXML($actualDocument, null)
@@ -212,6 +220,7 @@ public function testInternationalToXML()
212220
),
213221
),
214222
'remark' => 'remark',
223+
'additionalCustomerReferenceSuffix' => 'PHPx.y',
215224
'barcode' => 'BARCODE',
216225
);
217226
$expectedDocument = self::createDomDocument();
@@ -266,6 +275,12 @@ public function testInternationalToXML()
266275
$box->appendChild($sender);
267276
$box->appendChild($nationalBox);
268277
$box->appendChild($expectedDocument->createElement('remark', $data['remark']));
278+
$box->appendChild(
279+
$expectedDocument->createElement(
280+
'additionalCustomerReference',
281+
'+' . $data['additionalCustomerReferenceSuffix']
282+
)
283+
);
269284
$box->appendChild($expectedDocument->createElement('barcode', $data['barcode']));
270285

271286
$actualDocument = self::createDomDocument();
@@ -309,6 +324,7 @@ public function testInternationalToXML()
309324
$box->setSender($sender);
310325
$box->setInternationalBox($international);
311326
$box->setRemark($data['remark']);
327+
$box->setAdditionalCustomerReferenceSuffix($data['additionalCustomerReferenceSuffix']);
312328
$box->setBarcode($data['barcode']);
313329

314330
$actualDocument->appendChild(

tests/Bpost/OrderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public function testToXml()
7474
$box->setSender($sender);
7575
$box->setNationalBox($atBpost);
7676
$box->setRemark('bpack@bpost VAS 038 - COD+SAT+iD');
77-
$box->setAdditionalCustomerReference('Reference that can be used for cross-referencing');
77+
$box->setAdditionalCustomerReference('Reference used for bpost statistics');
78+
$box->setAdditionalCustomerReferenceSuffix('PHPx.y');
7879

7980
$self->setBoxes(array());
8081
$this->assertCount(0, $self->getBoxes());
@@ -330,7 +331,7 @@ private function getCreateOrderXml()
330331
</atBpost>
331332
</tns:nationalBox>
332333
<tns:remark>bpack@bpost VAS 038 - COD+SAT+iD</tns:remark>
333-
<tns:additionalCustomerReference>Reference that can be used for cross-referencing</tns:additionalCustomerReference>
334+
<tns:additionalCustomerReference>Reference used for bpost statistics+PHPx.y</tns:additionalCustomerReference>
334335
</tns:box>
335336
</tns:order>
336337

tests/BpostApiExamples/CreateOrder/International/BpackEuropeBusinessSecondPresentationAndAdditionalInsurance3Test.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ private function getOrder()
4444
$box->setSender($sender = new Sender());
4545
$box->setInternationalBox($internationalBox = new International());
4646
$box->setRemark('bpack Europe Business - Ins(El)');
47-
$box->setAdditionalCustomerReference('Reference that can be used for cross-referencing');
47+
$box->setAdditionalCustomerReference('Reference used for bpost statistics');
48+
$box->setAdditionalCustomerReferenceSuffix('PHPx.y');
4849

4950
$sender->setName('SENDER NAME');
5051
$sender->setCompany('SENDER COMPANY');
@@ -150,7 +151,7 @@ private function getXml()
150151
</international:international>
151152
</tns:internationalBox>
152153
<tns:remark>bpack Europe Business - Ins(El)</tns:remark>
153-
<tns:additionalCustomerReference>Reference that can be used for cross-referencing</tns:additionalCustomerReference>
154+
<tns:additionalCustomerReference>Reference used for bpost statistics+PHPx.y</tns:additionalCustomerReference>
154155
</tns:box>
155156
</tns:order>
156157

tests/BpostApiExamples/CreateOrder/International/BpackEuropeBusinessSecondPresentationAndBasicInsuranceTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ private function getOrder()
4444
$box->setSender($sender = new Sender());
4545
$box->setInternationalBox($internationalBox = new International());
4646
$box->setRemark('bpack Europe Business - Ins+2ndPr');
47-
$box->setAdditionalCustomerReference('Reference that can be used for cross-referencing');
47+
$box->setAdditionalCustomerReference('Reference used for bpost statistics');
48+
$box->setAdditionalCustomerReferenceSuffix('PHPx.y');
4849

4950
$sender->setName('SENDER NAME');
5051
$sender->setCompany('SENDER COMPANY');
@@ -148,7 +149,7 @@ private function getXml()
148149
</international:international>
149150
</tns:internationalBox>
150151
<tns:remark>bpack Europe Business - Ins+2ndPr</tns:remark>
151-
<tns:additionalCustomerReference>Reference that can be used for cross-referencing</tns:additionalCustomerReference>
152+
<tns:additionalCustomerReference>Reference used for bpost statistics+PHPx.y</tns:additionalCustomerReference>
152153
</tns:box>
153154
</tns:order>
154155

tests/BpostApiExamples/CreateOrder/International/BpackWorldBusinessAdditionalInsurance3Test.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ private function getOrder()
4444
$box->setSender($sender = new Sender());
4545
$box->setInternationalBox($internationalBox = new International());
4646
$box->setRemark('bpack World Business - Ins');
47-
$box->setAdditionalCustomerReference('Reference that can be used for cross-referencing');
47+
$box->setAdditionalCustomerReference('Reference used for bpost statistics');
48+
$box->setAdditionalCustomerReferenceSuffix('PHPx.y');
4849

4950
$sender->setName('SENDER NAME');
5051
$sender->setCompany('SENDER COMPANY');
@@ -190,7 +191,7 @@ private function getXml()
190191
</international:international>
191192
</tns:internationalBox>
192193
<tns:remark>bpack World Business - Ins</tns:remark>
193-
<tns:additionalCustomerReference>Reference that can be used for cross-referencing</tns:additionalCustomerReference>
194+
<tns:additionalCustomerReference>Reference used for bpost statistics+PHPx.y</tns:additionalCustomerReference>
194195
</tns:box>
195196
</tns:order>
196197

tests/BpostApiExamples/CreateOrder/International/BpackWorldBusinessBasicInsuranceTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ private function getOrder()
4444
$box->setSender($sender = new Sender());
4545
$box->setInternationalBox($internationalBox = new International());
4646
$box->setRemark('bpack World Business - Ins');
47-
$box->setAdditionalCustomerReference('Reference that can be used for cross-referencing');
47+
$box->setAdditionalCustomerReference('Reference used for bpost statistics');
48+
$box->setAdditionalCustomerReferenceSuffix('PHPx.y');
4849

4950
$sender->setName('SENDER NAME');
5051
$sender->setCompany('SENDER COMPANY');
@@ -188,7 +189,7 @@ private function getXml()
188189
</international:international>
189190
</tns:internationalBox>
190191
<tns:remark>bpack World Business - Ins</tns:remark>
191-
<tns:additionalCustomerReference>Reference that can be used for cross-referencing</tns:additionalCustomerReference>
192+
<tns:additionalCustomerReference>Reference used for bpost statistics+PHPx.y</tns:additionalCustomerReference>
192193
</tns:box>
193194
</tns:order>
194195

tests/BpostApiExamples/CreateOrder/International/BpackWorldBusinessNoOptionsTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ private function getOrder()
4343
$box->setSender($sender = new Sender());
4444
$box->setInternationalBox($internationalBox = new International());
4545
$box->setRemark('bpack World Business - Ins');
46-
$box->setAdditionalCustomerReference('Reference that can be used for cross-referencing');
46+
$box->setAdditionalCustomerReference('Reference used for bpost statistics');
47+
$box->setAdditionalCustomerReferenceSuffix('PHPx.y');
4748

4849
$sender->setName('SENDER NAME');
4950
$sender->setCompany('SENDER COMPANY');
@@ -180,7 +181,7 @@ private function getXml()
180181
</international:international>
181182
</tns:internationalBox>
182183
<tns:remark>bpack World Business - Ins</tns:remark>
183-
<tns:additionalCustomerReference>Reference that can be used for cross-referencing</tns:additionalCustomerReference>
184+
<tns:additionalCustomerReference>Reference used for bpost statistics+PHPx.y</tns:additionalCustomerReference>
184185
</tns:box>
185186
</tns:order>
186187

tests/BpostApiExamples/CreateOrder/International/BpackWorldEasyReturnNoOptionsTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ private function getOrder()
4242
$box->setSender($sender = new Sender());
4343
$box->setInternationalBox($internationalBox = new International());
4444
$box->setRemark('bpack World Easy Return - No options');
45-
$box->setAdditionalCustomerReference('Reference that can be used for cross-referencing');
45+
$box->setAdditionalCustomerReference('Reference used for bpost statistics');
46+
$box->setAdditionalCustomerReferenceSuffix('PHPx.y');
4647

4748
$sender->setName('ORIGINAL RECEIVER NAME');
4849
$sender->setCompany('ORIGINAL RECEIVER COMPANY');
@@ -136,7 +137,7 @@ private function getXml()
136137
</international:international>
137138
</tns:internationalBox>
138139
<tns:remark>bpack World Easy Return - No options</tns:remark>
139-
<tns:additionalCustomerReference>Reference that can be used for cross-referencing</tns:additionalCustomerReference>
140+
<tns:additionalCustomerReference>Reference used for bpost statistics+PHPx.y</tns:additionalCustomerReference>
140141
</tns:box>
141142
</tns:order>
142143

0 commit comments

Comments
 (0)