PHP code example of jossmp / sunatphp

1. Go to this page and download the library: Download jossmp/sunatphp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jossmp / sunatphp example snippets

sh

	 = [
		'representantes_legales' 	=> true,
		'cantidad_trabajadores' 	=> true,
		'establecimientos' 			=> true,
		'deuda' 					=> true,
	];

	$sunat = new \jossmp\sunat\ruc($config);

	$ruc = "20169004359";
	$dni = "44274795";

	$search1 = $sunat->consulta($ruc);
	$search2 = $sunat->consulta($dni);

	if ($search1->success == true) {
		echo "\n";
		echo "Empresa: " . $search1->result->razon_social . "\n";
		echo $search1->json(NULL, true);
		echo "\n\n";
	}

	if ($search2->success == true) {
		echo "\n";
		echo "Persona: " . $search1->result->razon_social . "\n";
		echo $search2->json(NULL, true);
		echo "\n\n";
	}
sh

	if( $search->success==false )
	{
		echo "ERROR : " . $search->message;
	}
sh

	 \jossmp\sunat\tipo_cambio();

	$search = $tc->ultimo_tc();

	// $search = $tc->consulta('02','2019'); // No disponible
sh

	...
	if( $search->success == true )
	{
		echo $search->json( );
		echo $search->json( 'callback' ); // para llamadas desde js
	}
	
	if( $search->success == true )
	{
		echo $search->xml( ); 
		echo $search->xml( 'persona' ); // define nodo raiz
	}
sh

    
sh
- cURL
- PHP 5.4.0 o superior
- jossmp/navigate
- jossmp/response