Skip to content

Commit

Permalink
Update async DNI call
Browse files Browse the repository at this point in the history
  • Loading branch information
giansalex committed Sep 30, 2021
1 parent 8975734 commit 9ca909b
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions src/Peru/Jne/Async/Dni.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@

class Dni
{
/**
* JNE Request Token
*
* @var string
*/
private $requestToken = 'Dmfiv1Unnsv8I9EoXEzbyQExSD8Q1UY7viyyf_347vRCfO-1xGFvDddaxDAlvm0cZ8XgAKTaWclVFnnsGgoy4aLlBGB5m-E8rGw_ymEcCig1:eq4At-H2zqgXPrPnoiDGFZH0Fdx5a-1UiyVaR4nQlCvYZzAhzmvWxLwkUk6-yORYrBBxEnoG5sm-Hkiyc91so6-nHHxIeLee5p700KE47Cw1';

/**
* @var ClientInterface
*/
Expand All @@ -41,11 +34,11 @@ public function __construct(ClientInterface $client, DniParser $parser)
/**
* Override JNE Request token
*
* @deprecated unused
* @param string $requestToken
*/
public function setRequestToken(string $requestToken): void
{
$this->requestToken = $requestToken;
}

/**
Expand All @@ -57,24 +50,16 @@ public function setRequestToken(string $requestToken): void
*/
public function get(string $dni): PromiseInterface
{
$payload = '{"CODDNI": "'.$dni.'"}';
$url = sprintf(Endpoints::CONSULT, $dni);

return $this->client
->postAsync(
Endpoints::CONSULT,
$payload,
[
'Content-Type' => 'application/json;chartset=utf-8',
'Content-Length' => strlen($payload),
'Requestverificationtoken' => $this->requestToken,
])
->postAsync($url, null)
->then(function ($json) use ($dni) {
$result = json_decode($json);
if (!$result || !isset($result->data)) {
if ($json === false || !($result = json_decode($json)) || !isset($result->nombreSoli)) {
return null;
}

return $this->parser->parse($dni, $result->data);
return $this->parser->parse($dni, $result);
});
}
}

0 comments on commit 9ca909b

Please sign in to comment.