facturapi / facturapi-php
Facturapi的PHP客户端库
3.0.1
2024-08-30 14:59 UTC
Requires
- php: >=5.5.0
Requires (Dev)
- phpspec/phpspec: ~2.0
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-08-30 16:26:36 UTC
README
这是https://www.facturapi.io的官方PHP包装器
FacturAPI使得开发者轻松在墨西哥生成有效的发票(称为电子发票或CFDI)。
如果你曾经使用过Stripe或Conekta,你将发现FacturAPI非常简单易懂,易于集成到你的服务器应用中。
安装
composer require "facturapi/facturapi-php"
开始之前
请确保你已在FacturAPI上创建了免费账户,并且你有你的API密钥。
入门
导入库
不要忘记在代码顶部引用库
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 include in your invoice ), "payment_form" => \Facturapi\PaymentForm::EFECTIVO, "folio_number" => "581", "series" => "F" ); $facturapi->Invoices->create( $invoice );
下载你的发票
// 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");
文档
你可以用这个库做更多的事情:列出、检索、更新和删除客户、产品和发票。
访问完整文档http://docs.facturapi.io。
帮助
发现了错误?
请在问题追踪器上报告它
想要贡献?
给我们发送你的PR!我们非常感激你的帮助 :)