2424from .environment import Environment
2525from .models .facade import Facade
2626from .models .bill .bill import Bill
27+ from .models .invoice .invoice_event_token import InvoiceEventToken
2728from .models .rate .rate import Rate
2829from .utils .guid_generator import GuidGenerator
2930from .models .rate .rates import Rates
@@ -184,6 +185,25 @@ def get_invoice(
184185 client = self .create_invoice_client ()
185186 return client .get (invoice_id , facade , sign_request )
186187
188+ def get_invoice_by_guid (
189+ self , guid : str , facade : str = Facade .MERCHANT , sign_request : bool = True
190+ ) -> Invoice :
191+ """
192+ Retrieve a BitPay invoice by invoice id using the specified facade.
193+ The client must have been previously authorized for the specified
194+ facade (the public facade requires no authorization)
195+
196+ :param str guid: The id of the invoice to retrieve
197+ :param str facade: The facade used to create it
198+ :param bool sign_request: Signed request
199+ :return: A BitPay Invoice object
200+ :rtype: Invoice
201+ :raises BitPayException
202+ :raises InvoiceQueryException
203+ """
204+ client = self .create_invoice_client ()
205+ return client .get_by_guid (guid , facade , sign_request )
206+
187207 def get_invoices (
188208 self ,
189209 date_start : str ,
@@ -213,6 +233,21 @@ def get_invoices(
213233 date_start , date_end , status , order_id , limit , offset
214234 )
215235
236+ def get_invoice_event_token (self , invoice_id : str ) -> InvoiceEventToken :
237+ """
238+ Retrieves a bus token which can be used to subscribe to invoice events.
239+
240+ :param str invoice_id: The id of the invoice for which you want to fetch an event token.
241+ :return: Invoice Event Token.
242+ :rtype: InvoiceEventToken
243+ :raises BitPayException
244+ :raises InvoiceQueryException
245+ """
246+ client = self .create_invoice_client ()
247+ return client .get_event_token (
248+ invoice_id
249+ )
250+
216251 def update_invoice (
217252 self ,
218253 invoice_id : str ,
@@ -250,6 +285,21 @@ def cancel_invoice(self, invoice_id: str, force_cancel: bool = False) -> Invoice
250285 client = self .create_invoice_client ()
251286 return client .cancel (invoice_id , force_cancel )
252287
288+ def cancel_invoice_by_guid (self , guid : str , force_cancel : bool = False ) -> Invoice :
289+ """
290+ Delete a previously created BitPay invoice.
291+
292+ :param str guid: The GUID of the BitPay invoice to be canceled.
293+ :param bool force_cancel: Query param that will cancel the invoice even if
294+ no contact information is present
295+ :return: A BitPay generated Invoice object.
296+ :rtype: Invoice
297+ :raises BitPayException
298+ :raises InvoiceCancellationException
299+ """
300+ client = self .create_invoice_client ()
301+ return client .cancel_by_guid (guid , force_cancel )
302+
253303 def pay_invoice (self , invoice_id : str , complete : bool = True ) -> Invoice :
254304 """
255305 Pay an invoice with a mock transaction - it works only for test environment.
@@ -285,6 +335,7 @@ def create_refund(
285335 immediate : bool = False ,
286336 buyer_pays_refund_fee : bool = False ,
287337 reference : str = None ,
338+ guid : str = None
288339 ) -> Refund :
289340 """
290341 Create a refund for a BitPay invoice.
@@ -300,14 +351,16 @@ def create_refund(
300351 :param str reference: Present only if specified in the request to create the refund.
301352 This is your reference label for this refund. It will be passed-through on each response for you to identify
302353 the refund in your system. Maximum string length is 100 characters.
354+ :param str guid: Variable provided by the merchant and designed to be used by the merchant
355+ to correlate the refund with a refund ID in their system.
303356 :return: An updated Refund Object
304357 :rtype: Refund
305358 :raises BitPayException
306359 :raises RefundCreationException
307360 """
308361 client = self .create_refund_client ()
309362 return client .create (
310- invoice_id , amount , preview , immediate , buyer_pays_refund_fee , reference
363+ invoice_id , amount , preview , immediate , buyer_pays_refund_fee , reference , guid
311364 )
312365
313366 def get_refund (self , refund_id : str ) -> Refund :
@@ -323,6 +376,19 @@ def get_refund(self, refund_id: str) -> Refund:
323376 client = self .create_refund_client ()
324377 return client .get (refund_id )
325378
379+ def get_refund_by_guid (self , guid : str ) -> Refund :
380+ """
381+ Retrieve a previously made refund request on a BitPay invoice.
382+
383+ :param str guid: The BitPay refund GUID.
384+ :return: BitPay Refund object with the associated Refund object.
385+ :rtype: Refund
386+ :raises BitPayException
387+ :raises RefundQueryException
388+ """
389+ client = self .create_refund_client ()
390+ return client .get_by_guid (guid )
391+
326392 def get_refunds (self , invoice_id : str ) -> List [Refund ]:
327393 """
328394 Retrieve all refund requests on a BitPay invoice.
@@ -350,6 +416,20 @@ def update_refund(self, refund_id: str, status: str) -> Refund:
350416 client = self .create_refund_client ()
351417 return client .update (refund_id , status )
352418
419+ def update_refund_by_guid (self , refund_guid : str , status : str ) -> Refund :
420+ """
421+ Update the status of a BitPay invoice refund.
422+
423+ :param str refund_guid: BitPay refund GUID.
424+ :param str status: The new status for the refund to be updated
425+ :return: A BitPay generated Refund object.
426+ :rtype: Refund
427+ :raises BitPayException
428+ :raises RefundUpdateException
429+ """
430+ client = self .create_refund_client ()
431+ return client .update_by_guid (refund_guid , status )
432+
353433 def cancel_refund (self , refund_id : str ) -> Refund :
354434 """
355435 Cancel a previously submitted refund request on a BitPay invoice.
@@ -363,6 +443,19 @@ def cancel_refund(self, refund_id: str) -> Refund:
363443 client = self .create_refund_client ()
364444 return client .cancel (refund_id )
365445
446+ def cancel_refund_by_guid (self , guid : str ) -> Refund :
447+ """
448+ Cancel a previously submitted refund request on a BitPay invoice.
449+
450+ :param str guid: The refund GUID for the refund to be canceled.
451+ :return: Cancelled refund Object.
452+ :rtype: Refund
453+ :raises BitPayException
454+ :raises RefundCancellationException
455+ """
456+ client = self .create_refund_client ()
457+ return client .cancel_by_guid (guid )
458+
366459 def request_refund_notification (self , refund_id : str ) -> bool :
367460 """
368461 Send a refund notification.
0 commit comments