Skip to content

Commit b767e3a

Browse files
committed
fix(verify-otp): content type for otp is not correct
verify otp accepts application/x-www-form-urlencoded craftsys/msg91-laravel#5
1 parent e69fb02 commit b767e3a

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/OTP/VerifyRequest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
class VerifyRequest extends Request
99
{
1010
protected $url = URLs::OTP_VERIFY_URL;
11+
12+
protected $content_type = \GuzzleHttp\RequestOptions::FORM_PARAMS;
1113
}

src/Support/Request.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Craftsys\Msg91\Exceptions\ValidationException;
77
use Craftsys\Msg91\Contracts\Options;
88
use GuzzleHttp\Client as GuzzleHttpClient;
9+
use GuzzleHttp\RequestOptions;
910

1011
abstract class Request
1112
{
@@ -36,13 +37,19 @@ abstract class Request
3637
*/
3738
protected $url = "";
3839

40+
/**
41+
* Content type
42+
*/
43+
protected $content_type = RequestOptions::JSON;
44+
3945
/**
4046
* Validation instance
4147
*
4248
* @var \Craftsys\Msg91\Requests\Validator
4349
*/
4450
protected $validator;
4551

52+
4653
/**
4754
* Create a new request instance
4855
*
@@ -93,10 +100,9 @@ public function handle()
93100
$method = strtolower($this->method);
94101
try {
95102
$resp = $client->{$method}($this->url, [
96-
\GuzzleHttp\RequestOptions::JSON => $payload,
103+
$this->content_type => $payload,
97104
"headers" => [
98105
'authkey' => $payload['authkey'],
99-
'content-type' => 'application/json'
100106
]
101107
]);
102108
return new Response($resp);

tests/OTP/OTPServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function test_verify_otp()
8484
// check the method
8585
$this->assertEquals("POST", $transaction['request']->getMethod());
8686
// check the request data
87-
$data = (array) json_decode($transaction['request']->getBody()->getContents());
87+
parse_str($transaction['request']->getBody()->getContents(), $data);
8888
$this->assertArrayHasKey('mobile', $data);
8989
$this->assertEquals($phone_number, $data['mobile']);
9090
$this->assertArrayHasKey('authkey', $data);

0 commit comments

Comments
 (0)