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:
BadRequest: If request is malformed.
"""
for method in self.allowed_methods:
if method.should_redeem(request_headers):
try:
return method.redeem_payment(price, request_headers, **kwargs)
except PaymentError as e:
raise BadRequest(str(e))
except Exception as e:
raise BadRequest(repr(e))
return False
评论列表
文章目录