Skip to content

Commit 7727c9c

Browse files
committed
Move 'tariff' in XML to messages child
1 parent 78eee19 commit 7727c9c

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/CmsmsClient.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,17 @@ public function send(CmsmsMessage $message, $recipient)
5858
* @param string $recipient
5959
* @return string
6060
*/
61-
protected function buildMessageXml(CmsmsMessage $message, $recipient)
61+
public function buildMessageXml(CmsmsMessage $message, $recipient)
6262
{
6363
$xml = new SimpleXMLElement('<MESSAGES/>');
6464

6565
$xml->addChild('AUTHENTICATION')
6666
->addChild('PRODUCTTOKEN', $this->productToken);
6767

68+
if ($tariff = $message->getTariff()) {
69+
$xml->addChild('TARIFF', $tariff);
70+
}
71+
6872
$msg = $xml->addChild('MSG');
6973
foreach ($message->toXmlArray() as $name => $value) {
7074
$msg->addChild($name, $value);

src/CmsmsMessage.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CmsmsMessage
1616
protected $reference;
1717

1818
/** @var int */
19-
protected $tariff;
19+
protected $tariff = 0;
2020

2121
/** @var int */
2222
protected $minimumNumberOfMessageParts;
@@ -91,6 +91,14 @@ public function tariff($tariff)
9191
return $this;
9292
}
9393

94+
/**
95+
* @return int
96+
*/
97+
public function getTariff()
98+
{
99+
return $this->tariff;
100+
}
101+
94102
/**
95103
* @param int $minimum
96104
* @param int $maximum
@@ -118,7 +126,6 @@ public function toXmlArray()
118126
'BODY' => $this->body,
119127
'FROM' => $this->originator,
120128
'REFERENCE' => $this->reference,
121-
'TARIFF' => $this->tariff,
122129
'MINIMUMNUMBEROFMESSAGEPARTS' => $this->minimumNumberOfMessageParts,
123130
'MAXIMUMNUMBEROFMESSAGEPARTS' => $this->maximumNumberOfMessageParts,
124131
]);

tests/CmsmsClientTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,17 @@ public function it_throws_exception_on_error_response()
7373

7474
$this->client->send($this->message, '00301234');
7575
}
76+
77+
/** @test */
78+
public function it_includes_tariff_in_xml()
79+
{
80+
$message = clone $this->message;
81+
$message->tariff(20);
82+
83+
$messageXml = $this->client->buildMessageXml($message, '00301234');
84+
$parsedXml = simplexml_load_string($messageXml);
85+
86+
$this->assertFalse(empty($parsedXml->TARIFF));
87+
$this->assertEquals(20, (int) $parsedXml->TARIFF);
88+
}
7689
}

tests/CmsmsMessageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function it_can_set_tariff()
102102
{
103103
$message = (new CmsmsMessage)->tariff(12);
104104

105-
$this->assertEquals(12, Arr::get($message->toXmlArray(), 'TARIFF'));
105+
$this->assertEquals(12, $message->getTariff());
106106
}
107107

108108
/** @test */

0 commit comments

Comments
 (0)