@@ -11,6 +11,7 @@ class to create the resource and a class to represent an
1111from pydantic import BaseModel
1212from pydantic .dataclasses import dataclass
1313
14+ from ..http import client
1415from ..types import InvoiceRelation , InvoiceUse , PaymentForm , PaymentMethod
1516from ..types .general import (
1617 CustomerBasicInfo ,
@@ -191,6 +192,38 @@ def cancel(cls, invoice_id: str, motive: str) -> 'Invoice':
191192 """
192193 return cast ('Invoice' , cls ._delete (invoice_id , ** dict (motive = motive )))
193194
195+ @classmethod
196+ def send_by_email (
197+ cls ,
198+ invoice_id : str ,
199+ recipients : Optional [Union [str , List [str ]]] = None ,
200+ ) -> bool :
201+ """Send an invoice by email.
202+
203+ Sends an email to the customer's email address with the XML and PDF
204+ files attached.
205+
206+ Args:
207+ invoice_id: The ID of the invoice to send.
208+ recipients: The email addresses to send the invoice to.
209+ If not provided, the invoice will be sent to the customer's
210+ registered email.
211+
212+ Returns:
213+ bool: True if the email was sent successfully, False otherwise.
214+
215+ Raises:
216+ FacturapiResponseException: If the invoice_id is not found.
217+ requests.RequestException: If the API request fails.
218+ """
219+
220+ endpoint = f"{ cls ._resource } /{ invoice_id } /email"
221+ payload = {}
222+ if recipients :
223+ payload ["email" ] = recipients
224+ response = client .post (endpoint , payload )
225+ return response .get ("ok" , False )
226+
194227 @property
195228 def customer (self ) -> Customer :
196229 """Fetch and access Customer resource.
0 commit comments