22import json
33
44from .config import Config
5+ from .exceptions .invoice_creation_exception import InvoiceCreationException
56from .tokens import Tokens
67from .models .facade import Facade
78from .models .bill .bill import Bill
3031
3132
3233class Client :
34+ """
35+ * Class Client
36+ * @package Bitpay
37+ * @author Antonio Buedo
38+ * @version 1.0.0
39+ * See bitpay.com/api for more information.
40+ """
3341 __configuration = None
3442 __env = None
3543 __ec_key = None
@@ -150,23 +158,46 @@ def get_access_token(self, key: str):
150158 # ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
151159
152160 def create_invoice (self , invoice : Invoice , facade : str = Facade .Merchant , sign_request : bool = True ) -> Invoice :
161+ """
162+ Create a BitPay invoice
163+
164+ :param Invoice invoice: An Invoice object with request parameters defined
165+ :param str facade: The facade used to create it
166+ :param str sign_request: Signed request
167+ :return: A BitPay generated Invoice object
168+ :rtype: Invoice
169+ :raises BitPayException
170+ :raises InvoiceCreationException
171+ """
153172 try :
154173 invoice .set_token (self .get_access_token (facade ))
155174 invoice_json = invoice .to_json ()
156175 response_json = self .__restcli .post ("invoices" , invoice_json , sign_request )
157176 except BitPayException as e :
158- raise InvoiceQueryException ("failed to serialize Invoice object : %s" % str (e ), e .get_api_code ())
177+ raise InvoiceCreationException ("failed to serialize Invoice object : %s" % str (e ), e .get_api_code ())
159178 except Exception as e :
160- raise InvoiceQueryException ("failed to serialize Invoice object : %s" % str (e ))
179+ raise InvoiceCreationException ("failed to serialize Invoice object : %s" % str (e ))
161180
162181 try :
163182 invoice = Invoice (** response_json )
164183 except Exception as e :
165- raise InvoiceQueryException ("failed to deserialize BitPay server response (Invoice) : %s" % str (e ))
184+ raise InvoiceCreationException ("failed to deserialize BitPay server response (Invoice) : %s" % str (e ))
166185
167186 return invoice
168187
169188 def get_invoice (self , invoice_id : str , facade : str = Facade .Merchant , sign_request : bool = True ) -> Invoice :
189+ """
190+ Retrieve a BitPay invoice by invoice id using the specified facade. The client must have been previously
191+ authorized for the specified facade (the public facade requires no authorization)
192+
193+ :param str invoice_id: The id of the invoice to retrieve
194+ :param str facade: The facade used to create it
195+ :param bool sign_request: Signed request
196+ :return: A BitPay Invoice object
197+ :rtype: Invoice
198+ :raises BitPayException
199+ :raises InvoiceQueryException
200+ """
170201 try :
171202 params = {"token" : self .get_access_token (facade )}
172203 response_json = self .__restcli .get ("invoices/%s" % invoice_id , params , sign_request )
@@ -184,6 +215,20 @@ def get_invoice(self, invoice_id: str, facade: str = Facade.Merchant, sign_reque
184215
185216 def get_invoices (self , date_start : str , date_end : str , status : str = None , order_id : str = None , limit : int = None ,
186217 offset : int = None ) -> [Invoice ]:
218+ """
219+ Retrieve a collection of BitPay invoices.
220+
221+ :param str date_start: The first date for the query filter.
222+ :param str date_end: The last date for the query filter.
223+ :param str status: The invoice status you want to query on.
224+ :param str order_id: The optional order id specified at time of invoice creation.
225+ :param int limit: Maximum results that the query will return (useful for paging results).
226+ :param int offset: Number of results to offset (ex. skip 10 will give you results starting with the 11th
227+ :return: A list of BitPay Invoice objects.
228+ :rtype: [Invoice]
229+ :raises BitPayException
230+ :raises InvoiceQueryException
231+ """
187232 try :
188233 params = {"token" : self .get_access_token (Facade .Merchant ), "dateStart" : date_start , "date_end" : date_end }
189234 if status :
@@ -211,6 +256,16 @@ def get_invoices(self, date_start: str, date_end: str, status: str = None, order
211256 return invoices
212257
213258 def update_invoice (self , invoice_id : str , buyer_email : str ) -> Invoice :
259+ """
260+ Update a BitPay invoice with communication method.
261+
262+ :param str invoice_id: The id of the invoice to updated.
263+ :param str buyer_email: The buyer's email address.
264+ :return: A BitPay generated Invoice object.
265+ :rtype: Invoice
266+ :raises BitPayException
267+ :raises InvoiceUpdateException
268+ """
214269 try :
215270 params = {'token' : self .get_access_token (Facade .Merchant ), 'buyer_email' : buyer_email }
216271 response_json = self .__restcli .update ("invoices/%s" % invoice_id , params )
@@ -227,6 +282,15 @@ def update_invoice(self, invoice_id: str, buyer_email: str) -> Invoice:
227282 return invoice
228283
229284 def cancel_invoice (self , invoice_id : str ) -> Invoice :
285+ """
286+ Delete a previously created BitPay invoice.
287+
288+ :param str invoice_id: The Id of the BitPay invoice to be canceled.
289+ :return: A BitPay generated Invoice object.
290+ :rtype: Invoice
291+ :raises BitPayException
292+ :raises InvoiceCancellationException
293+ """
230294 try :
231295 params = {'token' : self .get_access_token (Facade .Merchant )}
232296 response_json = self .__restcli .delete ("invoices/%s" % invoice_id , params )
@@ -243,6 +307,15 @@ def cancel_invoice(self, invoice_id: str) -> Invoice:
243307 return invoice
244308
245309 def request_invoice_notifications (self , invoice_id : str ) -> bool :
310+ """
311+ Request a BitPay Invoice Webhook.
312+
313+ :param str invoice_id: A BitPay invoice ID.
314+ :return: True if the webhook was successfully requested, false otherwise.
315+ :rtype: bool
316+ :raises BitPayException
317+ :raises InvoiceNotificationException
318+ """
246319 try :
247320 invoice = self .get_invoice (invoice_id )
248321 except Exception as e :
0 commit comments