1. Go to this page and download the library: Download facturapi/facturapi-php 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/ */
facturapi / facturapi-php example snippets
use Facturapi\Facturapi;
// Create an instance of the client.
// You can use different instances for uusing different API Keys
$facturapi = new Facturapi( FACTURAPI_KEY );
$customer = array(
"email" => "[email protected]", //Optional but useful to send invoice by email
"legal_name" => "Walter White", // Razón social
"tax_id" => "WIWA761018", //RFC
"address" => array(
"zip"=> "06800",
"street" => "Av. de los Rosales",
"exterior" => "123",
"neighborhood" => "Tepito"
// city, municipality and state are filled automatically from the zip code
// but if you want to, you can override their values
// city: 'México',
// municipality: 'Cuauhtémoc',
// state: 'Ciudad de México'
)
);
// Remember to store the customer.id in your records.
// You will need it to create an invoice for this customer.
$new_customer = $facturapi->Customers->create($customer);
$facturapi = new Facturapi( FACTURAPI_KEY );
$product = array(
"product_key" => "4319150114", // Clave Producto/Servicio from SAT's catalog. Log in to FacturAPI and use our tool to look it up.
"description" => "Apple iPhone 8",
"price" => 345.60 // price in MXN.
// By default, taxes are calculated from the price with IVA 16%
// But again, you can override that by explicitly providing a taxes array
// "taxes" => array(
// array ( "type" => \Facturapi\TaxType::IVA, "rate" => 0.16 ),
// array ( "type" => \Facturapi\TaxType::ISR, "rate" => 0.03666, "withholding" => true )
// )
);
$facturapi->Products->create( $product );
$facturapi = new Facturapi( FACTURAPI_KEY );
$invoice = array(
"customer" => "YOUR_CUSTOMER_ID",
"items" => array(
array(
"quantity" => 1, // Optional. Defaults to 1.
"product" => "YOUR_PRODUCT_ID" // You can also pass a product object instead
),
array(
"quantity" => 2,
"product" => array(
"description" => "Guitarra",
"product_key" => "01234567",
"price" => 420.69,
"sku" => "ABC4567"
)
) // Add as many products as you want to
// Once you have successfully created your invoice, you can...
$facturapi = new Facturapi( FACTURAPI_KEY );
$facturapi->Invoices->download_zip("INVOICE_ID") // stream containing the PDF and XML as a ZIP file or
$facturapi->Invoices->download_pdf("INVOICE_ID") // stream containing the PDF file or
$facturapi->Invoices->download_xml("INVOICE_ID") // stream containing the XML file or
// Send the invoice to your customer's email (if any)
$facturapi = new Facturapi( FACTURAPI_KEY );
$facturapi->Invoices->send_by_email("INVOICE_ID");
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.