in recaptcha_enterprise/demosite/app/urls.py [0:0]
def on_store_checkout() -> Response:
try:
recaptcha_action = config["recaptcha_actions"]["store"]
json_data = json.loads(request.data)
# <!-- ATTENTION: reCAPTCHA Example (Server Part 1/2) Starts -->
assessment_response = create_assessment(
context.get("project_id"),
context.get("site_key"),
json_data["token"],
recaptcha_action,
)
# Check if the token is valid, score is above threshold score and the action equals expected.
# Take action based on the result (BAD/ NOT_BAD).
#
# If 'label' is NOT_BAD:
# Check if the cart contains items and proceed to checkout and payment.
# items = json_data["items"]
# Business logic.
#
# If 'label' is BAD:
# Trigger email/phone verification flow.
label, reason = check_for_bad_action(assessment_response, recaptcha_action)
# <!-- ATTENTION: reCAPTCHA Example (Server Part 1/2) Ends -->
# Below code is only used to send response to the client for demo purposes.
# DO NOT send scores or other assessment response to the client.
# Return the response.
return jsonify(
{
"data": {
"score": f"{assessment_response.risk_analysis.score:.1f}",
"label": label,
"reason": reason,
}
}
)
except ValueError or Exception as e:
return jsonify({"data": {"error_msg": str(e.__dict__)}})