basic_shopify_api/utils.py
def create_hmac(
    data: Union[dict, str],
    raw: bool = False,
    build_query: bool = False,
    build_query_with_join: bool = False,
    encode: bool = False,
    secret: str = None
) -> str:
    """
    Create an HMAC string based on inputted values.
    """

    if build_query:
        # Query building is required, sort the keys alphabetically
        sorted_keys = sorted(data.keys())
        query_string = []
        for key in sorted_keys:
            value = data[key]
            # Join arrays together by ","
            query_value = ",".join(value) if isinstance(value, (tuple, list)) else value
            query_string.append(f"{key}={query_value}")
        # Optionally join result by "&"
        join_key = "&" if build_query_with_join else ""
        data = join_key.join(query_string).encode(e)

    # Generate the HMAC value
    hmac_local = hmac.new(secret.encode(e), data, hashlib.sha256)
    if encode:
        # For webhooks
        return base64.b64encode(hmac_local.digest())
    # For 0Auth and proxy
    return hmac_local.hexdigest().encode(e)

    Create an HMAC string based on inputted values.
    
Create an HMAC string based on inputted values.
Create an HMAC string based on inputted values .
def create_hmac(
    data: Union[dict, str],
    raw: bool = False,
    build_query: bool = False,
    build_query_with_join: bool = False,
    encode: bool = False,
    secret: str = None
) -> str:
    if build_query:
        sorted_keys = sorted(data.keys())
        query_string = []
        for key in sorted_keys:
            value = data[key]
            query_value = ",".join(value) if isinstance(value, (tuple, list)) else value
            query_string.append(f"{key}={query_value}")
        join_key = "&" if build_query_with_join else ""
        data = join_key.join(query_string).encode(e)
    hmac_local = hmac.new(secret.encode(e), data, hashlib.sha256)
    if encode:
        return base64.b64encode(hmac_local.digest())
    return hmac_local.hexdigest().encode(e)
def create_hmac ( data : Union [ dict , str ] , raw : bool = False , build_query : bool = False , build_query_with_join : bool = False , encode : bool = False , secret : str = None ) -> str : if build_query : sorted_keys = sorted ( data . keys ( ) ) query_string = [ ] for key in sorted_keys : value = data [ key ] query_value = "," . join ( value ) if isinstance ( value , ( tuple , list ) ) else value query_string . append ( f"{key}={query_value}" ) join_key = "&" if build_query_with_join else "" data = join_key . join ( query_string ) . encode ( e ) hmac_local = hmac . new ( secret . encode ( e ) , data , hashlib . sha256 ) if encode : return base64 . b64encode ( hmac_local . digest ( ) ) return hmac_local . hexdigest ( ) . encode ( e )
Create an HMAC string based on inputted values.
Create an HMAC string based on inputted values .
"""
    Create an HMAC string based on inputted values.
    """ # Query building is required, sort the keys alphabetically # Join arrays together by "," # Optionally join result by "&" # Generate the HMAC value # For webhooks # For 0Auth and proxy
data
Union[dict, str]
raw
bool
build_query
bool
build_query_with_join
bool
encode
bool
secret
str