monzo-api icon indicating copy to clipboard operation
monzo-api copied to clipboard

[BUG] Delete Receipt Fails

Open petermcd opened this issue 3 years ago • 7 comments

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):

  • Package Version = 0.1.1
  • Python version = 3.8

Additional context N/A

petermcd avatar Aug 07 '22 20:08 petermcd

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 avatar Aug 11 '22 23:08 petermcd

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

petermcd avatar Aug 12 '22 19:08 petermcd

If anyone stumbles upon this, it's due to the Tax int key missing in the line item. It's apparently no longer optional if you want to retreive or delete a receipt

GTB3NW avatar Apr 23 '25 22:04 GTB3NW

Spoke too soon, it doesn't fix DELETE, but at least it fixes retreive. 🤷

GTB3NW avatar Apr 23 '25 22:04 GTB3NW

Hi @GTB3NW

Would you be able to create a merge request with the fix at least for retrieve. This is something I had planned to revisit but life took over.

I am planning on completely rewriting the package at some point but this is a while away I think.

petermcd avatar Apr 24 '25 13:04 petermcd

Hi @GTB3NW

Would you be able to create a merge request with the fix at least for retrieve. This is something I had planned to revisit but life took over.

I am planning on completely rewriting the package at some point but this is a while away I think.

Hey sorry I can't commit to that. Hopefully the truth is easier than a false promise.

GTB3NW avatar Apr 24 '25 19:04 GTB3NW

That's cool cheers anyway. I will try to get it myself shortly.

petermcd avatar Apr 24 '25 19:04 petermcd