Skip to content

Commit 6c971cc

Browse files
authored
Merge pull request #205 from FacturAPI/FAC-1092/feature/pdf-preview
2 parents 5a88cee + 25cb2ef commit 6c971cc

File tree

2 files changed

+304
-0
lines changed

2 files changed

+304
-0
lines changed

website/openapi_v2.en.yaml

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,159 @@ paths:
17331733
$ref: "#/components/responses/NotFound"
17341734
"500":
17351735
$ref: "#/components/responses/UnexpectedError"
1736+
/invoices/preview/pdf:
1737+
post:
1738+
operationId: previewInvoicePdf
1739+
tags:
1740+
- invoice
1741+
summary: Preview invoice PDF
1742+
description: |
1743+
Generates a PDF preview of an invoice **without stamping it**. The PDF will be generated with the default template of your organization.
1744+
x-codeSamples:
1745+
- lang: Bash
1746+
label: cURL
1747+
source: |
1748+
curl https://www.facturapi.io/v2/invoices/preview/pdf \
1749+
-H "Authorization: Bearer sk_test_API_KEY" \
1750+
-H "Content-Type: application/json" \
1751+
-d '{
1752+
"customer": {
1753+
"legal_name": "Dunder Mifflin",
1754+
"email": "email@example.com",
1755+
"tax_id": "ABC101010111",
1756+
"tax_system": "601",
1757+
"address": {
1758+
"zip": "85900"
1759+
}
1760+
},
1761+
"items": [{
1762+
"quantity": 2,
1763+
"product": {
1764+
"description": "Ukelele",
1765+
"product_key": "60131324",
1766+
"price": 345.60
1767+
}
1768+
}],
1769+
"payment_form": "06",
1770+
"folio_number": 914,
1771+
"series": "F"
1772+
}'
1773+
- lang: JavaScript
1774+
label: Node.js
1775+
source: |
1776+
const Facturapi = require('facturapi');
1777+
1778+
const facturapi = new Facturapi('sk_live_API_KEY');
1779+
const pdfStream = await facturapi.invoices.previewPdf({
1780+
customer: {
1781+
legal_name: 'Dunder Mifflin',
1782+
email: 'email@example.com',
1783+
tax_id: 'ABC101010111',
1784+
tax_system: '601',
1785+
address: {
1786+
zip: '85900'
1787+
}
1788+
},
1789+
items: [{
1790+
quantity: 2,
1791+
product: {
1792+
description: 'Ukelele',
1793+
product_key: '60131324',
1794+
price: 345.60
1795+
}
1796+
}],
1797+
payment_form: Facturapi.PaymentForm.DINERO_ELECTRONICO,
1798+
folio_number: 914,
1799+
series: 'F'
1800+
});
1801+
// Save the PDF to a file
1802+
const fs = require('fs');
1803+
const file = fs.createWriteStream('/route/to/save/invoice.pdf');
1804+
pdfStream.pipe(file);
1805+
- lang: csharp
1806+
label: C#
1807+
source: |
1808+
var facturapi = new FacturapiClient("sk_live_API_KEY");
1809+
var pdfStream = await facturapi.Invoice.PreviewPdfAsync(new Dictionary<string, object>
1810+
{
1811+
["customer"] = new Dictionary<string, object>
1812+
{
1813+
["legal_name"] = "Dunder Mifflin",
1814+
["email"] = "email@example.com",
1815+
["tax_id"] = "ABC101010111",
1816+
["tax_system"] = "601",
1817+
["address"] = new Dictionary<string, object>
1818+
{
1819+
["zip"] = "85900"
1820+
}
1821+
},
1822+
["items"] = new Dictionary<string, object>[]
1823+
{
1824+
new Dictionary<string, object>
1825+
{
1826+
["product"] = new Dictionary<string, object>
1827+
{
1828+
["description"] = "Ukelele",
1829+
["product_key"] = "60131324",
1830+
["price"] = 345.60
1831+
}
1832+
}
1833+
},
1834+
["payment_form"] = Facturapi.PaymentForm.DINERO_ELECTRONICO,
1835+
["folio_number"] = 914,
1836+
["series"] = "F"
1837+
});
1838+
// Save the PDF to a file
1839+
var file = new System.IO.FileStream("C:\\route\\to\\save\\invoice.pdf", FileMode.Create);
1840+
pdfStream.CopyTo(file);
1841+
file.Close();
1842+
- lang: PHP
1843+
source: |
1844+
$facturapi = new Facturapi( "sk_live_API_KEY" );
1845+
$pdfContent = $facturapi->Invoices->preview_pdf([
1846+
"customer" => [
1847+
"legal_name" => "Dunder Mifflin",
1848+
"email" => "email@example.com",
1849+
"tax_id" => "ABC101010111",
1850+
"tax_system" => "601",
1851+
"address" => [
1852+
"zip" => "85900"
1853+
]
1854+
],
1855+
"items" => [
1856+
[
1857+
"quantity" => 2,
1858+
"product" => [
1859+
"description" => "Ukelele",
1860+
"product_key" => "60131324",
1861+
"price" => 345.60,
1862+
"sku" => "ABC4567"
1863+
]
1864+
]
1865+
],
1866+
"payment_form" => \Facturapi\PaymentForm::EFECTIVO,
1867+
"folio_number" => 914,
1868+
"series" => "F"
1869+
]);
1870+
requestBody:
1871+
$ref: "#/components/requestBodies/InvoiceCreate"
1872+
security:
1873+
- "SecretLiveKey": []
1874+
- "SecretTestKey": []
1875+
responses:
1876+
"200":
1877+
description: PDF binary content
1878+
content:
1879+
application/pdf:
1880+
schema:
1881+
type: string
1882+
format: binary
1883+
"400":
1884+
$ref: "#/components/responses/BadRequest"
1885+
"401":
1886+
$ref: "#/components/responses/Unauthenticated"
1887+
"500":
1888+
$ref: "#/components/responses/UnexpectedError"
17361889
/invoices/{invoice_id}:
17371890
get:
17381891
operationId: getInvoice

website/openapi_v2.yaml

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,157 @@ paths:
17831783
$ref: "#/components/responses/NotFound"
17841784
"500":
17851785
$ref: "#/components/responses/UnexpectedError"
1786+
/invoices/preview/pdf:
1787+
post:
1788+
operationId: previewInvoicePdf
1789+
tags:
1790+
- invoice
1791+
summary: Vista previa de factura en PDF
1792+
description: Genera una vista previa en PDF de una factura sin timbrar ni guardar en la organización.
1793+
x-codeSamples:
1794+
- lang: Bash
1795+
label: cURL
1796+
source: |
1797+
curl https://www.facturapi.io/v2/invoices/preview/pdf \
1798+
-H "Authorization: Bearer sk_test_API_KEY" \
1799+
-H "Content-Type: application/json" \
1800+
-d '{
1801+
"customer": {
1802+
"legal_name": "Dunder Mifflin",
1803+
"email": "email@example.com",
1804+
"tax_id": "ABC101010111",
1805+
"tax_system": "601",
1806+
"address": {
1807+
"zip": "85900"
1808+
}
1809+
},
1810+
"items": [{
1811+
"quantity": 2,
1812+
"product": {
1813+
"description": "Ukelele",
1814+
"product_key": "60131324",
1815+
"price": 345.60
1816+
}
1817+
}],
1818+
"payment_form": "06",
1819+
"folio_number": 914,
1820+
"series": "F"
1821+
}'
1822+
- lang: JavaScript
1823+
label: Node.js
1824+
source: |
1825+
const Facturapi = require('facturapi');
1826+
const facturapi = new Facturapi('sk_test_API_KEY');
1827+
const pdfStream = await facturapi.invoices.previewPdf({
1828+
customer: {
1829+
legal_name: 'Dunder Mifflin',
1830+
email: 'email@example.com',
1831+
tax_id: 'ABC101010111',
1832+
tax_system: '601',
1833+
address: {
1834+
zip: '85900'
1835+
}
1836+
},
1837+
items: [{
1838+
quantity: 2,
1839+
product: {
1840+
description: 'Ukelele',
1841+
product_key: '60131324',
1842+
price: 345.60
1843+
}
1844+
}],
1845+
payment_form: Facturapi.PaymentForm.DINERO_ELECTRONICO,
1846+
folio_number: 914,
1847+
series: 'F'
1848+
});
1849+
// Save PDF stream to a file
1850+
const fs = require('fs');
1851+
const file = fs.createWriteStream('invoice_preview.pdf');
1852+
pdfStream.pipe(file);
1853+
- lang: csharp
1854+
label: C#
1855+
source: |
1856+
var facturapi = new FacturapiClient("sk_test_API_KEY");
1857+
var pdfStream = await facturapi.Invoice.PreviewPdfAsync(new Dictionary<string, object>
1858+
{
1859+
["customer"] = new Dictionary<string, object>
1860+
{
1861+
["legal_name"] = "Dunder Mifflin",
1862+
["email"] = "email@example.com",
1863+
["tax_id"] = "ABC101010111",
1864+
["tax_system"] = "601",
1865+
["address"] = new Dictionary<string, object>
1866+
{
1867+
["zip"] = "85900"
1868+
}
1869+
},
1870+
["items"] = new Dictionary<string, object>[]
1871+
{
1872+
new Dictionary<string, object>
1873+
{
1874+
["product"] = new Dictionary<string, object>
1875+
{
1876+
["description"] = "Ukelele",
1877+
["product_key"] = "60131324",
1878+
["price"] = 345.60
1879+
}
1880+
}
1881+
},
1882+
["payment_form"] = Facturapi.PaymentForm.DINERO_ELECTRONICO,
1883+
["folio_number"] = 914,
1884+
["series"] = "F"
1885+
});
1886+
// Save PDF stream to a file
1887+
var file = new System.IO.FileStream("invoice_preview.pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write);
1888+
pdfStream.CopyTo(file);
1889+
file.Close();
1890+
- lang: PHP
1891+
source: |
1892+
$facturapi = new Facturapi( "sk_test_API_KEY" );
1893+
$pdfBytes = $facturapi->Invoices->preview_pdf([
1894+
"customer" => [
1895+
"legal_name" => "Dunder Mifflin",
1896+
"email" => "email@example.com",
1897+
"tax_id" => "ABC101010111",
1898+
"tax_system" => "601",
1899+
"address" => [
1900+
"zip" => "85900"
1901+
]
1902+
],
1903+
"items" => [
1904+
[
1905+
"quantity" => 2,
1906+
"product" => [
1907+
"description" => "Ukelele",
1908+
"product_key" => "60131324",
1909+
"price" => 345.60,
1910+
"sku" => "ABC4567"
1911+
]
1912+
]
1913+
],
1914+
"payment_form" => \Facturapi\PaymentForm::EFECTIVO,
1915+
"folio_number" => 914,
1916+
"series" => "F"
1917+
]);
1918+
requestBody:
1919+
$ref: "#/components/requestBodies/InvoiceCreate"
1920+
security:
1921+
- "SecretLiveKey": []
1922+
- "SecretTestKey": []
1923+
responses:
1924+
"200":
1925+
description: El archivo PDF de la factura
1926+
content:
1927+
application/pdf:
1928+
schema:
1929+
type: string
1930+
format: binary
1931+
"400":
1932+
$ref: "#/components/responses/BadRequest"
1933+
"401":
1934+
$ref: "#/components/responses/Unauthenticated"
1935+
"500":
1936+
$ref: "#/components/responses/UnexpectedError"
17861937
/invoices/{invoice_id}:
17871938
get:
17881939
operationId: getInvoice

0 commit comments

Comments
 (0)