Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #55 from giansalex/fix-jne-service-down
Browse files Browse the repository at this point in the history
Cambiar fuente para DNI
  • Loading branch information
giansalex authored Nov 9, 2021
2 parents 8907b07 + 43a2d7c commit 1e95abb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 48 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);
});
}
}
22 changes: 5 additions & 17 deletions src/Peru/Jne/Dni.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
*/
class Dni implements DniInterface
{
/**
* JNE Request Token
*
* @var string
*/
private $requestToken = 'Dmfiv1Unnsv8I9EoXEzbyQExSD8Q1UY7viyyf_347vRCfO-1xGFvDddaxDAlvm0cZ8XgAKTaWclVFnnsGgoy4aLlBGB5m-E8rGw_ymEcCig1:eq4At-H2zqgXPrPnoiDGFZH0Fdx5a-1UiyVaR4nQlCvYZzAhzmvWxLwkUk6-yORYrBBxEnoG5sm-Hkiyc91so6-nHHxIeLee5p700KE47Cw1';

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

/**
Expand All @@ -63,18 +56,13 @@ public function setRequestToken(string $requestToken): void
*/
public function get(string $dni): ?Person
{
$json = $this->client->post(
Endpoints::CONSULT,
'{"CODDNI": "'.$dni.'"}',
[
'Content-Type' => 'application/json;chartset=utf-8',
'Requestverificationtoken' => $this->requestToken,
]);
$url = sprintf(Endpoints::CONSULT, $dni);
$json = $this->client->post($url, []);

if ($json === false || !($result = json_decode($json)) || !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);
}
}
13 changes: 4 additions & 9 deletions src/Peru/Jne/DniParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@

class DniParser
{
public function parse(string $dni, string $raw): ?Person
public function parse(string $dni, $data): ?Person
{
$parts = explode('|', $raw);
if (count($parts) !== 3 || empty($parts[0])) {
return null;
}

$person = new Person();
$person->dni = $dni;
$person->apellidoPaterno = $parts[0];
$person->apellidoMaterno = $parts[1];
$person->nombres = $parts[2];
$person->apellidoPaterno = $data->apePatSoli;
$person->apellidoMaterno = $data->apeMatSoli;
$person->nombres = $data->nombreSoli;
$person->codVerifica = strval($this->getVerifyCode($dni));

return $person;
Expand Down
2 changes: 1 addition & 1 deletion src/Peru/Jne/Endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

final class Endpoints
{
public const CONSULT = 'https://aplicaciones007.jne.gob.pe/srop_publico/Consulta/api/AfiliadoApi/GetNombresCiudadano';
public const CONSULT = 'https://ww1.sunat.gob.pe/ol-ti-itatencionf5030/registro/solicitante?tipDocu=1&numDocu=%s';
}
3 changes: 2 additions & 1 deletion tests/Peru/Jne/DniParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ protected function setUp()
*/
public function testParseDni($dni)
{
$person = $this->parser->parse($dni, 'A|B|C');
$obj = json_decode('{"apeMatSoli": "PATERNO","apePatSoli": "MATERNO","nombreSoli": "NOMBRES"}');
$person = $this->parser->parse($dni, $obj);

$this->assertNotNull($person);
$this->assertNotNull($person->codVerifica);
Expand Down

0 comments on commit 1e95abb

Please sign in to comment.