Skip to content

Commit 93718e8

Browse files
authored
Merge pull request #218 from FacturAPI/FAC-858/feat/assign-customer-to-receipt
Add customer assignment to existing receipts in API and docs
2 parents 3617a61 + ce214e0 commit 93718e8

File tree

4 files changed

+375
-2
lines changed

4 files changed

+375
-2
lines changed

website/docs/guides/receipts.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ recibos que no fueron facturados.
2424
Para ver las descripciones de todos los parámetros, consulta la referencia completa del
2525
método [Crear Recibo](/api/#tag/receipt/operation/createReceipt).
2626

27+
Opcionalmente, puedes asociar un cliente al recibo enviando el campo `customer` (ya sea
28+
el ID de un cliente existente o el objeto del cliente para crearlo).
29+
2730
<Tabs groupId="codeExamples">
2831
<TabItem value="js" label="Node.js" default>
2932

@@ -111,6 +114,21 @@ curl https://www.facturapi.io/v2/receipts \
111114
</TabItem>
112115
</Tabs>
113116

117+
## Asignar un cliente a un recibo existente
118+
119+
Puedes asignar un cliente (o crearlo desde payload) a un recibo existente con el método
120+
[Asignar cliente a recibo](/api/#tag/receipt/operation/assignReceiptCustomer).
121+
122+
```bash
123+
curl https://www.facturapi.io/v2/receipts/58e93bd8e86eb318b019743d \
124+
-H "Authorization: Bearer sk_test_API_KEY" \
125+
-H "Content-Type: application/json" \
126+
-X PUT \
127+
-d '{
128+
"customer": "58e93bd8e86eb318b0197456"
129+
}'
130+
```
131+
114132
## Portal de Autofactura
115133

116134
Cuando creas un e-receipt, tienes la opción de enviarlo por correo electrónico a tu cliente.

website/i18n/en/docusaurus-plugin-content-docs/current/guides/receipts.mdx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ receipts that were not invoiced (known as global invoice).
2525
To see the descriptions of all the parameters, consult the complete reference of the
2626
method [Create Receipt](/api/#tag/receipt/operation/createReceipt).
2727

28+
Optionally, you can associate a customer to the receipt by sending the `customer` field
29+
(either the ID of an existing customer or the customer object to create it).
2830

2931
<Tabs groupId="codeExamples">
3032
<TabItem value="js" label="Node.js" default>
@@ -92,7 +94,7 @@ $receipt = $facturapi->Receipts->create([
9294
<TabItem value="curl" label="cURL">
9395

9496
```bash
95-
curl https://www.facturapi.io/v1/receipts \
97+
curl https://www.facturapi.io/v2/receipts \
9698
-H "Authorization: Bearer sk_test_API_KEY" \
9799
-H "Content-Type: application/json" \
98100
-d '{
@@ -113,6 +115,21 @@ curl https://www.facturapi.io/v1/receipts \
113115
</TabItem>
114116
</Tabs>
115117

118+
## Assign a customer to an existing receipt
119+
120+
You can assign a customer (or create it from payload) to an existing receipt with
121+
[Assign customer to receipt](/api/#tag/receipt/operation/assignReceiptCustomer).
122+
123+
```bash
124+
curl https://www.facturapi.io/v2/receipts/58e93bd8e86eb318b019743d \
125+
-H "Authorization: Bearer sk_test_API_KEY" \
126+
-H "Content-Type: application/json" \
127+
-X PUT \
128+
-d '{
129+
"customer": "58e93bd8e86eb318b0197456"
130+
}'
131+
```
132+
116133
## Self-invoice portal
117134

118135
When you create an e-receipt, you have the option to send it via email to your customer.
@@ -178,7 +195,7 @@ $invoice = $facturapi->Receipts->invoice($receipt->id, [
178195
<TabItem value="curl" label="cURL">
179196

180197
```bash
181-
curl https://www.facturapi.io/v1/receipts/5ebd8e56f5687a013ca0df46/invoice \
198+
curl https://www.facturapi.io/v2/receipts/5ebd8e56f5687a013ca0df46/invoice \
182199
-H "Authorization: Bearer sk_test_API_KEY" \
183200
-H "Content-Type: application/json" \
184201
-d '{

website/openapi_v2.en.yaml

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3930,6 +3930,15 @@ paths:
39303930
type: string
39313931
description: |
39323932
Search. Text to search in the description of the receipt's items or the SKU.
3933+
- in: query
3934+
name: customer
3935+
schema:
3936+
type: string
3937+
minLength: 24
3938+
maxLength: 24
3939+
description: |
3940+
ID of the customer associated to the receipt.
3941+
example: "58e93bd8e86eb318b0197456"
39333942
- in: query
39343943
name: payment_form
39353944
schema:
@@ -4035,6 +4044,133 @@ paths:
40354044
$ref: "#/components/responses/Unauthenticated"
40364045
"500":
40374046
$ref: "#/components/responses/UnexpectedError"
4047+
put:
4048+
operationId: assignReceiptCustomer
4049+
tags:
4050+
- receipt
4051+
summary: Assign customer to receipt
4052+
description: |
4053+
Assign an existing customer (by ID) to a receipt, or create a new one by sending the customer object.
4054+
4055+
If the receipt has a registered transaction, the transaction's `counterparty` will also be updated.
4056+
x-codeSamples:
4057+
- lang: Bash
4058+
label: cURL
4059+
source: |
4060+
curl https://www.facturapi.io/v2/receipts/58e93bd8e86eb318b019743d \
4061+
-H "Authorization: Bearer sk_test_API_KEY" \
4062+
-H "Content-Type: application/json" \
4063+
-X PUT \
4064+
-d '{
4065+
"customer": "58e93bd8e86eb318b0197456"
4066+
}'
4067+
- lang: JavaScript
4068+
label: Node.js
4069+
source: |
4070+
import Facturapi from 'facturapi'
4071+
const facturapi = new Facturapi('sk_test_API_KEY');
4072+
4073+
// Assign an existing customer by ID
4074+
const receipt = await facturapi.receipts.assignCustomer(
4075+
'58e93bd8e86eb318b019743d',
4076+
{ customer: '58e93bd8e86eb318b0197456' }
4077+
);
4078+
4079+
// Or create the customer from payload and assign it to the receipt
4080+
const receiptWithNewCustomer = await facturapi.receipts.assignCustomer(
4081+
'58e93bd8e86eb318b019743d',
4082+
{
4083+
customer: {
4084+
legal_name: 'Dunder Mifflin',
4085+
tax_id: 'XAXX010101000',
4086+
tax_system: '616',
4087+
email: 'billing@dundermifflin.com',
4088+
address: { zip: '01234', country: 'MEX' }
4089+
}
4090+
}
4091+
);
4092+
- lang: csharp
4093+
label: C#
4094+
source: |
4095+
var facturapi = new FacturapiClient("sk_test_API_KEY");
4096+
4097+
// Assign an existing customer by ID
4098+
var receipt = await facturapi.Receipt.AssignCustomerAsync(
4099+
"58e93bd8e86eb318b019743d",
4100+
new Dictionary<string, object>
4101+
{
4102+
["customer"] = "58e93bd8e86eb318b0197456"
4103+
}
4104+
);
4105+
4106+
// Or create the customer from payload and assign it to the receipt
4107+
var receiptWithNewCustomer = await facturapi.Receipt.AssignCustomerAsync(
4108+
"58e93bd8e86eb318b019743d",
4109+
new Dictionary<string, object>
4110+
{
4111+
["customer"] = new Dictionary<string, object>
4112+
{
4113+
["legal_name"] = "Dunder Mifflin",
4114+
["tax_id"] = "XAXX010101000",
4115+
["tax_system"] = "616",
4116+
["email"] = "billing@dundermifflin.com",
4117+
["address"] = new Dictionary<string, object>
4118+
{
4119+
["zip"] = "01234",
4120+
["country"] = "MEX"
4121+
}
4122+
}
4123+
}
4124+
);
4125+
- lang: PHP
4126+
source: |
4127+
$facturapi = new Facturapi( "sk_test_API_KEY" );
4128+
4129+
// Assign an existing customer by ID
4130+
$receipt = $facturapi->Receipts->assign_customer("58e93bd8e86eb318b019743d", [
4131+
"customer" => "58e93bd8e86eb318b0197456"
4132+
]);
4133+
4134+
// Or create the customer from payload and assign it to the receipt
4135+
$receiptWithNewCustomer = $facturapi->Receipts->assign_customer("58e93bd8e86eb318b019743d", [
4136+
"customer" => [
4137+
"legal_name" => "Dunder Mifflin",
4138+
"tax_id" => "XAXX010101000",
4139+
"tax_system" => "616",
4140+
"email" => "billing@dundermifflin.com",
4141+
"address" => [
4142+
"zip" => "01234",
4143+
"country" => "MEX"
4144+
]
4145+
]
4146+
]);
4147+
parameters:
4148+
- in: path
4149+
name: receipt_id
4150+
schema:
4151+
type: string
4152+
required: true
4153+
description: ID of the receipt to update
4154+
requestBody:
4155+
$ref: "#/components/requestBodies/ReceiptAssignCustomer"
4156+
security:
4157+
- "SecretLiveKey": []
4158+
- "SecretTestKey": []
4159+
responses:
4160+
"200":
4161+
description: Updated `Receipt` object
4162+
content:
4163+
application/json:
4164+
schema:
4165+
$ref: "#/components/schemas/Receipt"
4166+
"400":
4167+
$ref: "#/components/responses/BadRequest"
4168+
"401":
4169+
$ref: "#/components/responses/Unauthenticated"
4170+
"404":
4171+
$ref: "#/components/responses/NotFound"
4172+
"500":
4173+
$ref: "#/components/responses/UnexpectedError"
40384174
delete:
40394175
operationId: cancelReceipt
40404176
tags:
@@ -7728,6 +7864,12 @@ components:
77287864
application/json:
77297865
schema:
77307866
$ref: "#/components/schemas/ReceiptInput"
7867+
ReceiptAssignCustomer:
7868+
required: true
7869+
content:
7870+
application/json:
7871+
schema:
7872+
$ref: "#/components/schemas/ReceiptAssignCustomerInput"
77317873
ReceiptInvoice:
77327874
required: true
77337875
content:
@@ -11863,6 +12005,10 @@ components:
1186312005
type: string
1186412006
example: 614496b471d422de4b6cfcc4
1186512007
description: ID of the associated invoice, if invoiced.
12008+
customer:
12009+
type: string
12010+
example: 58e93bd8e86eb318b0197456
12011+
description: ID of the customer associated to the receipt, if assigned.
1186612012
key:
1186712013
type: string
1186812014
example: r9YqYarL
@@ -11892,6 +12038,15 @@ components:
1189212038
- items
1189312039
- payment_form
1189412040
properties:
12041+
customer:
12042+
description: |
12043+
Customer associated to the receipt. You can send the ID of an existing customer or a customer object to create it.
12044+
oneOf:
12045+
- type: string
12046+
minLength: 24
12047+
maxLength: 24
12048+
example: 58e93bd8e86eb318b0197456
12049+
- $ref: "#/components/schemas/CustomerCreateInput"
1189512050
items:
1189612051
type: array
1189712052
maxItems: 5000
@@ -11947,6 +12102,20 @@ components:
1194712102
type: string
1194812103
description: |
1194912104
Optional identifier that you can use to relate this receipt to your records and later search by this number. Facturapi does not validate that this field is unique.
12105+
ReceiptAssignCustomerInput:
12106+
type: object
12107+
required:
12108+
- customer
12109+
properties:
12110+
customer:
12111+
description: |
12112+
Customer to assign to the receipt. You can send the ID of an existing customer or a customer object to create it.
12113+
oneOf:
12114+
- type: string
12115+
minLength: 24
12116+
maxLength: 24
12117+
example: 58e93bd8e86eb318b0197456
12118+
- $ref: "#/components/schemas/CustomerCreateInput"
1195012119
ReceiptSearchResult:
1195112120
allOf:
1195212121
- $ref: "#/components/schemas/SearchResult"

0 commit comments

Comments
 (0)