Skip to content

Commit

Permalink
[FIX] *_online_adyen: make sure downloaded file contains valid base64…
Browse files Browse the repository at this point in the history
… encode bytes
  • Loading branch information
NL66278 committed Dec 16, 2021
1 parent 807d15f commit dc3a629
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,18 @@ def _adyen_get_settlement_details_file(self):
[self.api_base, self.journal_id.adyen_merchant_account, filename]
)
response = requests.get(URL, auth=(self.username, self.password))
if response.status_code == 200:
return response.content, filename
else:
if response.status_code != 200:
raise UserError(_("%s \n\n %s") % (response.status_code, response.text))
# Check base64 decoding and padding of response.content.
# Remember: response.text is unicode, response.content is in bytes.
byte_count = len(response.content)
_logger.debug(
_("Retrieved %d bytes, starting with %s"), byte_count, response.text[:32]
)
# Make sure base64 encoded content contains multiple of 4 bytes.
byte_padding = b"=" * (byte_count % 4)
data_file = response.content + byte_padding
return data_file, filename

def _schedule_next_run(self):
"""Set next run date and autoincrement batch number."""
Expand Down
6 changes: 6 additions & 0 deletions setup/account_bank_statement_import_online_adyen/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit dc3a629

Please sign in to comment.