braintree / braintree_python

Braintree Python library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
242 stars 116 forks source link

Test disbursement objects throw AttributeError for is_credit() and is_debit() #126

Open bcdickinson opened 3 years ago

bcdickinson commented 3 years ago

General information

Issue description

Test disbursement webhook notifications are missing the disbursement_type attribute, causing the is_credit() and is_debit() methods to throw AttributeErrors:

>>> webhook_notification = self.gateway.webhook_testing.sample_notification(
>>>   braintree.WebhookNotification.Kind.Disbursement,
>>>   "test_disbursement_id",
>>> )
>>> webhook_notification.disbursement.is_credit()                                                                     
Traceback (most recent call last):                                                               
  File "<pudb command line>", line 1, in <module>                                                
  File "/usr/local/lib/python3.8/site-packages/braintree/disbursement.py", line 27, in is_credit 
    return self.disbursement_type == Disbursement.Type.Credit                                    
AttributeError: 'Disbursement' object has no attribute 'disbursement_type'                       
crookedneighbor commented 3 years ago

Would you like to open a PR to fix this? If not, we'll add it to our backlog to fix. Thanks for bringing this to our attention!

bcdickinson commented 3 years ago

Thanks for getting back to me.

I held off submitting a PR for this while I waited for some real webhook data to come through from our sandbox environment. It seems like the disbursement type field is coming through as None, whereas the tests and documentation imply that it should always be "credit" or "debit".

I'm not sure which bit is incorrect, the documentation and the tests or the API response! I think I'll have to leave this one to you.

Here's an example of a parsed notification we received:

<WebhookNotification {kind: 'disbursement', timestamp: datetime.datetime(2021, 2, 23, 6, 20, 56), subject: {'disbursement': {'id': 'abcdef', 'merchant_account': {'status': 'active', 'id': '<snip>', 'currency_iso_code': 'GBP', 'default': True, 'sub_merchant_account': False}, 'exception_message': None, 'amount': '10.00', 'disbursement_date': datetime.date(2021, 2, 23), 'disbursement_type': None, 'follow_up_action': None, 'success': True, 'retry': False, 'transaction_ids': ['<snip>']}}} at 140366520028080>
hollabaq86 commented 2 years ago

for internal tracking, ticket 842