Skip to content

Commit

Permalink
fix(verify-otp): content type for otp is not correct
Browse files Browse the repository at this point in the history
verify otp accepts application/x-www-form-urlencoded
craftsys/msg91-laravel#5
  • Loading branch information
sudkumar committed Oct 20, 2020
1 parent e69fb02 commit b767e3a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/OTP/VerifyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
class VerifyRequest extends Request
{
protected $url = URLs::OTP_VERIFY_URL;

protected $content_type = \GuzzleHttp\RequestOptions::FORM_PARAMS;
}
10 changes: 8 additions & 2 deletions src/Support/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Craftsys\Msg91\Exceptions\ValidationException;
use Craftsys\Msg91\Contracts\Options;
use GuzzleHttp\Client as GuzzleHttpClient;
use GuzzleHttp\RequestOptions;

abstract class Request
{
Expand Down Expand Up @@ -36,13 +37,19 @@ abstract class Request
*/
protected $url = "";

/**
* Content type
*/
protected $content_type = RequestOptions::JSON;

/**
* Validation instance
*
* @var \Craftsys\Msg91\Requests\Validator
*/
protected $validator;


/**
* Create a new request instance
*
Expand Down Expand Up @@ -93,10 +100,9 @@ public function handle()
$method = strtolower($this->method);
try {
$resp = $client->{$method}($this->url, [
\GuzzleHttp\RequestOptions::JSON => $payload,
$this->content_type => $payload,
"headers" => [
'authkey' => $payload['authkey'],
'content-type' => 'application/json'
]
]);
return new Response($resp);
Expand Down
2 changes: 1 addition & 1 deletion tests/OTP/OTPServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function test_verify_otp()
// check the method
$this->assertEquals("POST", $transaction['request']->getMethod());
// check the request data
$data = (array) json_decode($transaction['request']->getBody()->getContents());
parse_str($transaction['request']->getBody()->getContents(), $data);
$this->assertArrayHasKey('mobile', $data);
$this->assertEquals($phone_number, $data['mobile']);
$this->assertArrayHasKey('authkey', $data);
Expand Down

0 comments on commit b767e3a

Please sign in to comment.