[FIX] *_online_adyen: make sure downloaded file contains valid base64 encode bytes

This commit is contained in:
Ronald Portier
2021-12-16 17:29:45 +01:00
committed by Ronald Portier (Therp BV)
parent d179f15f4b
commit 20d37acfa6
3 changed files with 18 additions and 3 deletions

View File

@@ -84,10 +84,18 @@ class OnlineBankStatementProvider(models.Model):
[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."""

View File

@@ -0,0 +1 @@
../../../../account_bank_statement_import_online_adyen

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)