Exemplo n.º 1
0
def validate_post_fields_needed(response_fields: Dict, asset: Asset):
    expected_fields = registered_sep31_receiver_integration.info(asset).get(
        "fields", {})
    if "transaction" not in response_fields:
        raise ValueError("unrecognized category of fields in response")
    if not isinstance(response_fields["transaction"], dict):
        raise ValueError("'transaction' value must be a dict")
    for field, value in response_fields["transaction"].items():
        if field not in expected_fields["transaction"]:
            raise ValueError(f"unrecognized field in 'transaction' object")
        elif not (isinstance(response_fields["transaction"][field], dict) and
                  response_fields["transaction"][field].get("description")):
            raise ValueError(f"field value must be a dict with a description")
Exemplo n.º 2
0
def validate_post_fields(passed_fields: Dict, asset: Asset,
                         lang: Optional[str]) -> Dict:
    missing_fields = defaultdict(dict)
    expected_fields = registered_sep31_receiver_integration.info(
        asset, lang).get("fields", {})
    if "transaction" not in expected_fields:
        return {}
    elif "transaction" not in passed_fields:
        missing_fields["transaction"] = expected_fields["transaction"]
        return missing_fields
    for field, info in expected_fields["transaction"].items():
        if info.get("optional"):
            continue
        elif field not in passed_fields["transaction"]:
            missing_fields["transaction"][field] = info
    return dict(missing_fields)
Exemplo n.º 3
0
def info(request: Request) -> Response:
    info_data = {
        "receive": {},
    }
    for asset in Asset.objects.filter(sep31_enabled=True):
        try:
            fields_and_types = registered_sep31_receiver_integration.info(
                asset, request.GET.get("lang"))
        except ValueError:
            return render_error_response("unsupported 'lang'")
        try:
            validate_info_response(fields_and_types)
        except ValueError as e:
            logger.error(f"info integration error: {str(e)}")
            return render_error_response(
                _("unable to process the request"),
                status_code=500,
            )
        info_data["receive"][asset.code] = get_asset_info(
            asset, fields_and_types)

    return Response(info_data)