Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions addons/payment_worldline/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@
'cancel': ('CANCELLED',),
'declined': ('REJECTED', 'REJECTED_CAPTURE'),
}

# Mapping of response codes indicating Worldline handled the request
# See https://apireference.connect.worldline-solutions.com/s2sapi/v1/en_US/json/response-codes.html.
VALID_RESPONSE_CODES = {
200: 'Successful',
201: 'Created',
402: 'Payment Rejected',
}
3 changes: 2 additions & 1 deletion addons/payment_worldline/models/payment_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def _worldline_make_request(self, endpoint, payload=None, method='POST', idempot
try:
response = requests.request(method, url, json=payload, headers=headers, timeout=10)
try:
response.raise_for_status()
if response.status_code not in const.VALID_RESPONSE_CODES:
response.raise_for_status()
except requests.exceptions.HTTPError:
_logger.exception(
"Invalid API request at %s with data:\n%s", url, pprint.pformat(payload)
Expand Down