Skip to content

Commit

Permalink
Add support for specifying a delivery status url for Telenor Gateway (#7
Browse files Browse the repository at this point in the history
)
  • Loading branch information
viirre authored Sep 10, 2024
1 parent 7f303d3 commit a4de14f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Gateway/TelenorGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(
?ClientInterface $httpClient = null,
?RequestFactoryInterface $requestFactory = null,
?StreamFactoryInterface $streamFactory = null,
protected ?string $statusDeliveryUrl = null,
) {
parent::__construct($httpClient, $requestFactory, $streamFactory);

Expand Down Expand Up @@ -97,6 +98,9 @@ protected function buildSendBody(MessageInterface $message): string
if ($this->supplementaryInformation !== null) {
$header->appendChild($xml->createElement('sub_id_1', $this->supplementaryInformation));
}
if ($this->statusDeliveryUrl !== null) {
$header->appendChild($xml->createElement('status_delivery_url', $this->statusDeliveryUrl));
}
$mobileCtrlSms->appendChild($header);

$payload = $xml->createElement('payload');
Expand Down
44 changes: 44 additions & 0 deletions tests/Gateway/TelenorGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected function setUp(): void
$this->httpClientMock,
$this->requestFactoryMock,
$this->streamFactoryMock,
null,
);
}

Expand Down Expand Up @@ -137,6 +138,49 @@ public function testReceiveTelenorDeliveryReport(): void
$this->assertSame($status, $deliveryReport->getStatus());
}

public function testSendTelenorMessageWithStatusDeliveryUrl(): void
{
$this->gateway = new TelenorGateway(
'some-username',
'some-password',
'some-customer-id',
'some-customer-password',
null,
$this->httpClientMock,
$this->requestFactoryMock,
$this->streamFactoryMock,
'https://example.com/api/sms/delivery',
);

$message = Message::create('46700123001', 'Hello world!', 'Testing');

$url = 'https://sms-pro.net:44343/services/some-customer-id/sendsms';

$this->streamFactoryMock->method('createStream')
->with($this->callback(function ($body) {
$this->assertStringContainsString(
'<status_delivery_url>https://example.com/api/sms/delivery</status_delivery_url>',
$body
);

return true;
}))
->willReturn($this->createMock(Stream::class));

$requestMock = $this->createMock(RequestInterface::class);
$requestMock->method('withHeader')->willReturnSelf();
$requestMock->method('withBody')->willReturnSelf();
$this->requestFactoryMock->expects($this->once())
->method('createRequest')->with('POST', $url)->willReturn($requestMock);

$responseMock = $this->createMock(ResponseInterface::class);
$this->httpClientMock->expects($this->once())->method('sendRequest')->willReturn($responseMock);

$responseMock->method('getBody')->willReturn(Utils::streamFor($this->getSuccessfulResponseXml()));

$this->gateway->sendMessage($message);
}

public function testReceiveTelenorInvalidDeliveryReport(): void
{
$this->expectException(ReceiveException::class);
Expand Down

0 comments on commit a4de14f

Please sign in to comment.