Skip to content

Commit 601e7e3

Browse files
authored
Merge pull request #167 from FacturAPI/FAC-1224/async-invoices
Add tutorial for async invoices
2 parents 3004a3e + 5118b93 commit 601e7e3

File tree

4 files changed

+450
-2
lines changed

4 files changed

+450
-2
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"label": "Guías",
3-
"position": 4
3+
"position": 4,
4+
"collapsed": false
45
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"position": 3
2+
"position": 3,
3+
"collapsed": false
34
}
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
---
2+
sidebar_position: 9
3+
---
4+
5+
import Tabs from '@theme/Tabs';
6+
import TabItem from '@theme/TabItem';
7+
8+
# Facturación asíncrona
9+
10+
Cuando el tamaño de tus facturas es muy grande, o necesitas facturar muchas facturas al mismo tiempo, es recomendable (y en algunos casos requerido) utilizar la facturación asíncrona. Esto te permite registrar una factura en Facturapi
11+
y recibir una respuesta inmediata con el objeto Invoice y su ID, pero sin timbrar todavía. El timbrado de la factura se realiza en segundo plano, y puedes consultar el estado de la factura en cualquier momento
12+
por medio del método de obtener factura.
13+
14+
## Crear una factura asíncrona
15+
16+
Una factura se creará de manera asíncrona en cualquiera de estos 2 casos:
17+
18+
- Si se envía el parámetro `async` con el valor `true` al crear la factura.
19+
- Si el tamaño de la información enviada excede los 2MB (CFDIs con alrededor de 5,000 elementos o con un complemento de carta porte muy extenso).
20+
21+
En cualquiera de los 2 casos recibirás el objeto invoice como respuesta, con el campo `status` en `pending`. Esto significa que la factura se está procesando en segundo plano. Mientras esto ocurre, es importante
22+
señalar que los campos `stamp` y `uuid` serán null. Una vez timbrada la factura, el campo `status` cambiará a `valid` y se llenarán los campos `stamp` y `uuid` con la información del timbrado.
23+
24+
### Petición
25+
26+
<Tabs groupId="codeExamples">
27+
<TabItem value="js" label="Node.js" default>
28+
29+
```javascript
30+
const invoice = await facturapi.invoices.create({
31+
customer: {
32+
legal_name: 'Dunder Mifflin',
33+
email: 'email@example.com',
34+
tax_id: 'ABC101010111',
35+
tax_system: '601',
36+
address: {
37+
zip: '85900'
38+
}
39+
},
40+
items: [{
41+
quantity: 2,
42+
product: {
43+
description: 'Ukelele',
44+
product_key: '60131324', // ClaveProdServ del SAT
45+
price: 345.60,
46+
taxes: [
47+
{
48+
type: 'IVA',
49+
rate: 0.16
50+
}
51+
]
52+
}
53+
}],
54+
use: 'G01',
55+
payment_form: "28" // "Tarjeta de débito"
56+
}, { async: true });
57+
```
58+
59+
</TabItem>
60+
<TabItem value="cs" label="C#">
61+
62+
```csharp
63+
var invoice = await facturapi.Invoice.CreateAsync(new Dictionary<string, object>
64+
{
65+
["customer"] = new Dictionary<string, object>
66+
{
67+
["legal_name"] = "Dunder Mifflin",
68+
["email"] = "email@example.com",
69+
["tax_id"] = "ABC101010111",
70+
["tax_system"] = "601",
71+
["address"] = new Dictionary<string, object>
72+
{
73+
["zip"] = "85900"
74+
},
75+
},
76+
["items"] = new List<Dictionary<string, object>>
77+
{
78+
new Dictionary<string, object>
79+
{
80+
["quantity"] = 2,
81+
["product"] = new Dictionary<string, object>
82+
{
83+
["description"] = "Ukelele",
84+
["product_key"] = "60131324",
85+
["price"] = 345.60,
86+
["taxes"] = new List<Dictionary<string, object>>
87+
{
88+
new Dictionary<string, object>
89+
{
90+
["type"] = "IVA",
91+
["rate"] = 0.16
92+
}
93+
}
94+
}
95+
}
96+
},
97+
["use"] = "G01",
98+
["payment_form"] = "28" // "Tarjeta de débito"
99+
}, new Dictionary<string, object>
100+
{
101+
["async"] = true
102+
});
103+
```
104+
105+
</TabItem>
106+
<TabItem value="php" label="PHP">
107+
108+
```php
109+
$invoice = $facturapi->Invoices->create([
110+
"customer" => [
111+
"legal_name" => "Dunder Mifflin",
112+
"email" => "email@example.com",
113+
"tax_id" => "ABC101010111",
114+
"tax_system" => "601",
115+
"address" => [
116+
"zip" => "85900"
117+
]
118+
],
119+
"items" => [
120+
[
121+
"quantity" => 2,
122+
"product" => [
123+
"description" => "Ukelele",
124+
"product_key" => "60131324",
125+
"price" => 345.60,
126+
"taxes" => [
127+
[
128+
"type" => "IVA",
129+
"rate" => 0.16
130+
]
131+
]
132+
]
133+
]
134+
],
135+
"use" => "G01",
136+
"payment_form" => "28" // "Tarjeta de débito"
137+
], [
138+
"async" => true
139+
]);
140+
```
141+
142+
</TabItem>
143+
<TabItem value="curl" label="cURL">
144+
145+
```bash
146+
curl https://www.facturapi.io/v2/invoices \
147+
-H "
148+
Authorization Bearer sk_test_API_KEY" \
149+
-H "Content-Type: application/json" \
150+
-d '{
151+
"customer": {
152+
"legal_name": "Dunder Mifflin",
153+
"email": "email@example.com",
154+
"tax_id": "ABC101010111",
155+
"tax_system": "601",
156+
"address": {
157+
"zip": "85900"
158+
}
159+
},
160+
"items": [
161+
{
162+
"quantity": 2,
163+
"product": {
164+
"description": "Ukelele",
165+
"product_key": "60131324",
166+
"price": 345.60,
167+
"taxes": [
168+
{
169+
"type": "IVA",
170+
"rate": 0.16
171+
}
172+
]
173+
}
174+
}
175+
],
176+
"use": "G01",
177+
"payment_form": "28" // "Tarjeta de débito"
178+
}'
179+
```
180+
181+
</TabItem>
182+
</Tabs>
183+
184+
### Response
185+
186+
```json
187+
{
188+
"id": "5f4b1b4b4b4b4b4b4b4b4b4a",
189+
"created_at": "2020-08-29T00:00:00.000Z",
190+
"status": "pending",
191+
"customer": {
192+
"id": "5f4b1b4b4b4b4b4b4b4b4b4b",
193+
"legal_name": "Dunder Mifflin",
194+
"email": "email@example.com",
195+
"tax_id": "ABC101010111",
196+
"tax_system": "601",
197+
"address": {
198+
"country": "MEX",
199+
"zip": "85900"
200+
}
201+
},
202+
"items": [
203+
{
204+
"quantity": 2,
205+
"product": {
206+
"description": "Ukelele",
207+
"product_key": "60131324",
208+
"price": 345.60,
209+
"taxes": [
210+
{
211+
"type": "IVA",
212+
"rate": 0.16
213+
}
214+
]
215+
}
216+
}
217+
],
218+
"use": "G01",
219+
"payment_form": "28",
220+
"stamp": null,
221+
"uuid": null
222+
}
223+
```

0 commit comments

Comments
 (0)