Skip to content

Commit b413b7b

Browse files
committed
Add tariff method
1 parent 78c0330 commit b413b7b

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public function routeNotificationForCmsms()
104104
- `body('')`: Accepts a string value for the message body.
105105
- `originator('')`: Accepts a string value between 1 and 11 characters, used as the message sender name.
106106
- `reference('')`: Accepts a string value for your message reference. This information will be returned in a status report so you can match the message and it's status. Restrictions: 1 - 32 alphanumeric characters and reference will not work for demo accounts.
107+
- `tariff()`: Accepts a integer value for your message tariff. The unit is eurocent. Requires the `originator` to be set to a specific value. Contact CM for this value and to enable this feature for your contract.
107108

108109
## Changelog
109110

src/CmsmsMessage.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class CmsmsMessage
1515
/** @var string */
1616
protected $reference;
1717

18+
/** @var int */
19+
protected $tariff;
20+
1821
/**
1922
* @param string $body
2023
*/
@@ -66,6 +69,22 @@ public function reference($reference)
6669
return $this;
6770
}
6871

72+
/**
73+
* @param int $tariff Tariff in eurocent
74+
* @return $this
75+
* @throws InvalidMessage
76+
*/
77+
public function tariff($tariff)
78+
{
79+
if (empty($tariff) || ! is_int($tariff)) {
80+
throw InvalidMessage::invalidTariff($tariff);
81+
}
82+
83+
$this->tariff = $tariff;
84+
85+
return $this;
86+
}
87+
6988
/**
7089
* @return array
7190
*/
@@ -75,6 +94,7 @@ public function toXmlArray()
7594
'BODY' => $this->body,
7695
'FROM' => $this->originator,
7796
'REFERENCE' => $this->reference,
97+
'TARIFF' => $this->tariff,
7898
]);
7999
}
80100

src/Exceptions/InvalidMessage.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ public static function invalidOriginator($originator)
2323
{
2424
return new static("The originator on the CMSMS message may only contain 1 - 11 characters. Was given '{$originator}'");
2525
}
26+
27+
/**
28+
* @param int $tariff
29+
* @return static
30+
*/
31+
public static function invalidTariff($tariff)
32+
{
33+
return new static("The tarrif on the CMSMS message may only contain a nonzero integer. Was given '{$tariff}'");
34+
}
2635
}

tests/CmsmsMessageTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,30 @@ public function it_cannot_set_a_reference_that_contains_non_alpha_numeric_values
9797
(new CmsmsMessage)->reference('@#$*A*Sjks87');
9898
}
9999

100+
/** @test */
101+
public function is_can_set_tariff()
102+
{
103+
$message = (new CmsmsMessage)->tariff(12);
104+
105+
$this->assertEquals(12, Arr::get($message->toXmlArray(), 'TARIFF'));
106+
}
107+
108+
/** @test */
109+
public function it_cannot_set_an_empty_tariff()
110+
{
111+
$this->setExpectedException(InvalidMessage::class);
112+
113+
(new CmsmsMessage)->tariff(0);
114+
}
115+
116+
/** @test */
117+
public function it_cannot_set_a_float_to_tariff()
118+
{
119+
$this->setExpectedException(InvalidMessage::class);
120+
121+
(new CmsmsMessage)->tariff(2.5);
122+
}
123+
100124
/** @test */
101125
public function it_xml_contains_only_filled_parameters()
102126
{

0 commit comments

Comments
 (0)