petermcd / monzo-api

Python package to interact with the API provided by Monzo bank
MIT License
27 stars 5 forks source link

[BUG] Delete Receipt Fails #38

Open petermcd opened 2 years ago

petermcd commented 2 years ago

Describe the bug When trying to delete a receipt the response received is a 400 bad requerst.

To Reproduce

from monzo.handlers.filesystem import FileSystem
from monzo.endpoints.receipt import Receipt, ReceiptItem
from monzo.authentication import Authentication

EXTERNAL_ID = 'ABC123'
TRANSACTION_ID = 'REPLACE WITH TRANSACTION ID'

handler = FileSystem(file='monzo.json')
creds = handler.fetch()
redirect_url = ''
auth = Authentication(
    access_token=creds['access_token'],
    access_token_expiry=creds['expiry'],
    client_id=creds['client_id'],
    client_secret=creds['client_secret'],
    redirect_url=redirect_url,
    refresh_token=creds['refresh_token'],
)
auth.register_callback_handler(handler=handler)

item = ReceiptItem(
    description = 'Test 123',
    amount= 1234,
    currency = 'GBP',
    tax=123
)

receipt = Receipt(
    auth = auth,
    transaction_id = TRANSACTION_ID,
    external_id = EXTERNAL_ID,
    transaction_total = 1234,
    transaction_currency = 'GBP',
    items=[item]
)

Receipt.create(auth=auth, receipt=receipt)
Receipt.delete(auth=auth, receipt=receipt)

Expected behavior Receipt to be deleted

Environment (please complete the following information):

Additional context N/A

petermcd commented 2 years ago

As with #42 the reason this is failing Monzo allows you to create a receipt that is inadvertantly invalid. The actual output is:

{"code":"bad_response.marshaling","message":"Failed to marshal proto receipt to DTO","params":{"amount_currency":"GBP","client_id":"xxx","external_id":"ABC123","tax_currency":"","user_id":"xxx"},"retryable":{}}

It appears the created receipt is good enough to show in the Monzo app but not return using the get API or the delete using the Delete API.

petermcd commented 2 years ago

The issue seems to be related to creating invalid receipt items, however even after fixing a receipt and being able to fetch it delete does not work, further invetigation ongoing