changes
This commit is contained in:
@@ -208,7 +208,7 @@ class PaymentProvider(models.Model):
|
||||
json=payload,
|
||||
params=params,
|
||||
headers=headers,
|
||||
timeout=60,
|
||||
timeout=15,
|
||||
)
|
||||
except requests.exceptions.RequestException as e:
|
||||
_logger.error("Poynt API request failed: %s", e)
|
||||
@@ -521,6 +521,11 @@ class PaymentProvider(models.Model):
|
||||
which returns a TransactionReceipt with a ``data`` field containing
|
||||
the rendered receipt content (HTML or text).
|
||||
|
||||
If Poynt has reported a missing receipt template for this business,
|
||||
we fail fast (no network call) until the admin clears the flag.
|
||||
This protects Odoo workers from a thundering-herd of 400s when the
|
||||
merchant's Poynt account is missing its receipt template config.
|
||||
|
||||
:param str transaction_id: The Poynt transaction UUID.
|
||||
:return: The receipt content string, or None on failure.
|
||||
:rtype: str | None
|
||||
@@ -528,14 +533,46 @@ class PaymentProvider(models.Model):
|
||||
self.ensure_one()
|
||||
if not transaction_id:
|
||||
return None
|
||||
|
||||
ICP = self.env['ir.config_parameter'].sudo()
|
||||
cooldown_key = f'fusion_poynt.receipt_endpoint_cooldown_until.{self.id}'
|
||||
try:
|
||||
cooldown_until = int(ICP.get_param(cooldown_key, '0'))
|
||||
except (TypeError, ValueError):
|
||||
cooldown_until = 0
|
||||
now_ts = int(fields.Datetime.now().timestamp())
|
||||
if cooldown_until > now_ts:
|
||||
_logger.debug(
|
||||
"Skipping Poynt receipt fetch for %s — endpoint in cooldown "
|
||||
"for %ss (template missing or endpoint unhealthy)",
|
||||
transaction_id, cooldown_until - now_ts,
|
||||
)
|
||||
return None
|
||||
|
||||
try:
|
||||
result = self._poynt_make_request(
|
||||
'GET', f'transactions/{transaction_id}/receipt',
|
||||
)
|
||||
return result.get('data') or None
|
||||
except (ValidationError, Exception):
|
||||
except ValidationError as e:
|
||||
err = str(e).lower()
|
||||
if 'template' in err or '400' in err:
|
||||
# Poynt is consistently rejecting the receipt call for this
|
||||
# business. Put the endpoint in a 1-hour cooldown so subsequent
|
||||
# webhooks do not hammer Poynt with known-bad requests.
|
||||
ICP.set_param(cooldown_key, str(now_ts + 3600))
|
||||
_logger.warning(
|
||||
"Poynt receipt endpoint returned %s — suspending receipt "
|
||||
"fetches for provider %s for 1 hour. "
|
||||
"Admin: check that the Poynt business has a receipt "
|
||||
"template configured in the Poynt dashboard.",
|
||||
e, self.id,
|
||||
)
|
||||
return None
|
||||
except Exception:
|
||||
_logger.debug(
|
||||
"Could not fetch Poynt receipt for transaction %s", transaction_id,
|
||||
exc_info=True,
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user