def contains_payment(self, price, request_headers, **kwargs):
"""Validate the payment information received in the request headers.
Args:
price (int): The price the user must pay for the resource.
request_headers (dict): Headers sent by client with their request.
keyword args: Any other headers needed to verify payment.
Returns:
(bool): True if payment is valid,
False if no payment attached (402 initiation).
Raises:
ParseError: If request is malformed.
"""
for method in self.allowed_methods:
if method.should_redeem(request_headers):
try:
v = method.redeem_payment(price, request_headers, **kwargs)
except Exception as e:
raise ParseError(str(e))
return v
return False
评论列表
文章目录