def validate_payment()

in orders/src/create_order/main.py [0:0]


def validate_payment(order: dict) -> Tuple[bool, str]:
    """
    Validate the payment token
    """

    # Gather the domain name and AWS region
    url = urlparse(PAYMENT_API_URL)
    region = boto3.session.Session().region_name
    # Create the signature helper
    iam_auth = BotoAWSRequestsAuth(aws_host=url.netloc,
                                   aws_region=region,
                                   aws_service='execute-api')

    # Send a POST request
    response = requests.post(
        PAYMENT_API_URL+"/backend/validate",
        json={"paymentToken": order["paymentToken"], "total": order["total"]},
        auth=iam_auth
    )

    logger.debug({
        "message": "Response received from payment",
        "body": response.json()
    })

    body = response.json()
    if response.status_code != 200 or "ok" not in body:
        logger.warning({
            "message": "Failure to contact the payment service",
            "statusCode": response.status_code,
            "body": body
        })
        return (False, "Failure to contact the payment service")

    if not body["ok"]:
        logger.info({
            "message": "Wrong payment token",
            "paymentToken": order["paymentToken"],
            "total": order["total"]
        })
        return (False, "Wrong payment token")

    return (True, "The payment token is valid")