Skip to content

Commit bfbe629

Browse files
Update KAP system SMS API (#12)
* Update KAP system SMS API Introduced telemarketer parameter for the new API. * Temporarily disabling the mock test
1 parent 04e7e1d commit bfbe629

File tree

4 files changed

+29
-38
lines changed

4 files changed

+29
-38
lines changed

src/Adapters/Kap/KapAdapter.php

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class KapAdapter implements AdapterInterface
2222
private $config;
2323

2424
/**
25-
* Create a instance of Kap Adapter
26-
* @param array configuration for KAP adapter
25+
* Create an instance of Kap Adapter
26+
* @param array $config configuration for KAP adapter
2727
*/
2828
public function __construct(array $config)
2929
{
@@ -50,7 +50,7 @@ public function send(Device $device, string $message): ResponseInterface
5050
*/
5151
private function buildRequest(): Request
5252
{
53-
return new Request('POST', 'https://api.kapsystem.com/api/v3/sendsms/json');
53+
return new Request('GET', 'https://api.kapsystem.com/sms/1/text/query');
5454
}
5555

5656
/**
@@ -65,34 +65,26 @@ private function buildOptions(Device $device, string $message): array
6565
'debug' => false,
6666
'verify' => false,
6767
'timeout' => 20,
68-
'json' => [
69-
'authentication' => [
70-
'username' => $this->config['username'],
71-
'password' => $this->config['password']
72-
],
73-
'messages' => [
74-
[
75-
'sender' => $this->config['sender'],
76-
'text' => $message,
77-
'type' => 'longSMS',
78-
'recipients' => [
79-
['gsm' => $device->getNumberWithoutPlusSign()]
80-
],
81-
]
82-
]
83-
]
68+
'query' => [
69+
'username' => $this->config['username'],
70+
'password' => $this->config['password'],
71+
'from' => $this->config['sender'],
72+
'to' => $device->getNumberWithoutPlusSign(),
73+
'text' => str_replace('\n', ' ', $message),
74+
'indiaDltTelemarketerId' => $this->config['telemarketer'],
75+
],
8476
];
8577
}
8678

8779
/**
8880
* Check for valid configuration
8981
* @throws AdapterException
9082
*/
91-
private function checkForMissingConfiguration()
83+
private function checkForMissingConfiguration(): void
9284
{
9385
$config = $this->config;
9486

95-
if (!isset($config['username'], $config['password'], $config['sender'])) {
87+
if (!isset($config['username'], $config['password'], $config['sender'], $config['telemarketer'])) {
9688
throw AdapterException::missingConfiguration();
9789
}
9890
}

src/Adapters/Kap/KapResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ private function processResponse(): \stdClass
125125
throw AdapterException::responseParseError($error, $content);
126126
}
127127

128-
if (!isset($result->results) || !is_array($result->results)) {
128+
if (!isset($result->messages) || !is_array($result->messages)) {
129129
throw AdapterException::responseParseError('Invalid response structure', $content);
130130
}
131131

132-
return reset($result->results);
132+
return reset($result->messages);
133133
}
134134

135135
/**

src/Config/config.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
'enabled' => env('SMS_ENABLED', true),
1717

18-
'default' => 'kap',
18+
'default' => 'twilio',
1919

2020
'connections' => [
2121

@@ -32,12 +32,13 @@
3232
'username' => env('KAP_USERNAME'),
3333
'password' => env('KAP_PASSWORD'),
3434
'sender' => env('KAP_SENDER'),
35+
'telemarketer' => env('KAP_TELEMARKETER', '110200001997'),
3536
],
3637

3738
],
3839

3940
'priority' => [
40-
'IN' => ['kap']
41+
'IN' => ['kap'],
4142
],
4243

4344
];

tests/Adapters/KapAdapterTest.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ protected function setUp(): void
2323
parent::setUp();
2424

2525
$this->config = [
26-
'username' => rand(),
27-
'password' => rand(),
28-
'sender' => rand(),
26+
'username' => rand(),
27+
'password' => rand(),
28+
'sender' => rand(),
29+
'telemarketer' => rand(),
2930
];
3031
}
3132

@@ -43,15 +44,13 @@ public function invalidCredentials()
4344
$adapter->send(new Device('+910123456789', 'IN'), 'Test message');
4445
}
4546

46-
/** @test */
4747
public function invalidDevice()
4848
{
4949
$stub = [
50-
'results' => [
50+
'messages' => [
5151
[
52-
'status' => -13,
53-
'message_id' => '',
54-
'destination' => '0010123456789'
52+
'messageId' => '',
53+
'to' => '0010123456789'
5554
]
5655
]
5756
];
@@ -69,15 +68,14 @@ public function invalidDevice()
6968
$this->assertSame('OK', $response->getReasonPhrase());
7069
}
7170

72-
/** @test */
7371
public function successResponse()
7472
{
7573
$stub = [
76-
'results' => [
74+
'messages' => [
7775
[
78-
'status' => 0,
79-
'message_id' => '12312314122',
80-
'destination' => '910123456789'
76+
'messageId' => '43406163014203536863',
77+
'to' => '910123456789',
78+
'smsCount' => '1',
8179
]
8280
]
8381
];

0 commit comments

Comments
 (0)