Skip to content

Commit bbffa00

Browse files
authored
fix(otp-resend): otp resend requires content type to be form data (#7)
1 parent bdfb048 commit bbffa00

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/OTP/ResendRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
use Craftsys\Msg91\Support\Request;
66
use Craftsys\Msg91\URLs;
7+
use GuzzleHttp\RequestOptions;
78

89
class ResendRequest extends Request
910
{
1011
protected $url = URLs::OTP_RESEND_URL;
12+
13+
protected $content_type = RequestOptions::FORM_PARAMS;
1114
}

tests/OTP/OTPServiceTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class OTPServiceTest extends TestCase
1818
"key" => "12345678901234567890"
1919
];
2020

21+
protected $phone_number = 919999999999;
22+
2123
protected $container = [];
2224

2325
protected function setUp(): void
@@ -46,7 +48,7 @@ protected function createMockHttpClient(
4648

4749
public function test_otp_send()
4850
{
49-
$phone_number = 919999999999;
51+
$phone_number = $this->phone_number;
5052
$response = (new Client($this->config, $this->createMockHttpClient()))
5153
->otp()
5254
->from("SMSIND")
@@ -70,7 +72,7 @@ public function test_otp_send()
7072

7173
public function test_verify_otp()
7274
{
73-
$phone_number = 919999999999;
75+
$phone_number = $this->phone_number;
7476
$otp = 1234;
7577
$response = (new Client($this->config, $this->createMockHttpClient()))
7678
->otp($otp)
@@ -95,7 +97,7 @@ public function test_verify_otp()
9597

9698
public function test_otp_resend()
9799
{
98-
$phone_number = 919999999999;
100+
$phone_number = $this->phone_number;
99101
$response = (new Client($this->config, $this->createMockHttpClient()))
100102
->otp()
101103
->to($phone_number)
@@ -109,7 +111,7 @@ public function test_otp_resend()
109111
// check the method
110112
$this->assertEquals("POST", $transaction['request']->getMethod());
111113
// check the request data
112-
$data = (array) json_decode($transaction['request']->getBody()->getContents());
114+
parse_str($transaction['request']->getBody()->getContents(), $data);
113115
$this->assertArrayHasKey('mobile', $data);
114116
$this->assertEquals($phone_number, $data['mobile']);
115117
$this->assertArrayHasKey('authkey', $data);
@@ -120,7 +122,7 @@ public function test_otp_resend()
120122

121123
public function test_api_key_required()
122124
{
123-
$phone_number = 919999999999;
125+
$phone_number = $this->phone_number;
124126
$this->expectException(ValidationException::class);
125127
(new Client([], $this->createMockHttpClient()))
126128
->otp()

0 commit comments

Comments
 (0)