### Initialize PyProdamus Object Source: https://github.com/dnagikh/python-prodamus/blob/master/README.md Instantiate the PyProdamus class with your API token to begin. ```python prodamus = prodamuspy.PyProdamus(API_TOKEN) ``` -------------------------------- ### Initialize ProdamusPy Client Source: https://context7.com/dnagikh/python-prodamus/llms.txt Instantiate the ProdamusPy client with your shared API secret token. This token is required for all subsequent signing and verification operations. ```python import prodamuspy API_TOKEN = "your_prodamus_secret_token" prodamus = prodamuspy.ProdamusPy(API_TOKEN) ``` -------------------------------- ### Create Prodamus Signature Source: https://github.com/dnagikh/python-prodamus/blob/master/README.md Generate a Prodamus signature from a dictionary representation of the request body. ```python checkSign = prodamus.sign(bodyDict) ``` -------------------------------- ### ProdamusPy(secret) — Initialize the client Source: https://context7.com/dnagikh/python-prodamus/llms.txt Creates a new ProdamusPy instance bound to a shared API secret token. This secret is used for all signing and verification operations. ```APIDOC ## ProdamusPy(secret) — Initialize the client ### Description Creates a new `ProdamusPy` instance bound to a shared API secret token. All signing and verification operations use this secret. The `secret` is the API token provided by Prodamus for your integration. ### Usage ```python import prodamuspy API_TOKEN = "your_prodamus_secret_token" prodamus = prodamuspy.ProdamusPy(API_TOKEN) ``` ``` -------------------------------- ### verify(obj, sign) — Verify an HMAC-SHA256 signature Source: https://context7.com/dnagikh/python-prodamus/llms.txt Compares a provided signature string against the HMAC-SHA256 signature computed from the given dictionary. Returns `True` if the signatures match, indicating an authentic payload, and `False` otherwise. ```APIDOC ## verify(obj, sign) — Verify an HMAC-SHA256 signature ### Description Compares a provided signature string against the HMAC-SHA256 signature computed from the given dictionary. Returns `True` if the signatures match (the payload is authentic), or `False` otherwise. The comparison is case-insensitive on the received signature. ### Usage ```python import prodamuspy from flask import Flask, request, abort app = Flask(__name__) prodamus = prodamuspy.ProdamusPy("your_prodamus_secret_token") @app.route("/webhook/prodamus", methods=["POST"]) def prodamus_webhook(): raw_body = request.get_data(as_text=True) # Parse the incoming URL-encoded payload payload = prodamus.parse(raw_body) # Extract and remove the signature field from the payload received_sign = payload.pop("sign", None) if not received_sign: abort(400, "Missing signature") # Verify the signature against the remaining payload if prodamus.verify(payload, received_sign): order_id = payload.get("order_id") amount = payload.get("sum") print(f"Payment confirmed: order {order_id}, amount {amount}") # TODO: fulfill the order return "OK", 200 else: print("Invalid signature — possible tampering detected") abort(403, "Signature verification failed") if __name__ == "__main__": app.run(port=5000) ``` ``` -------------------------------- ### sign(data) — Generate an HMAC-SHA256 signature Source: https://context7.com/dnagikh/python-prodamus/llms.txt Takes a Python dictionary and produces a lowercase hex-encoded HMAC-SHA256 signature. The dictionary is serialized to compact JSON with sorted keys before hashing for deterministic results. ```APIDOC ## sign(data) — Generate an HMAC-SHA256 signature ### Description Takes a Python dictionary and produces a lowercase hex-encoded HMAC-SHA256 signature. The dictionary is serialized to compact JSON with sorted keys before hashing, ensuring a deterministic and consistent signature regardless of key insertion order. ### Usage ```python import prodamuspy prodamus = prodamuspy.ProdamusPy("your_prodamus_secret_token") data = { "order_id": "12345", "order_num": "ORD-2023-001", "sum": "1500.00", "currency": "rub", "products": [ {"name": "Widget Pro", "price": "1500.00", "quantity": "1"} ] } signature = prodamus.sign(data) # Returns a hex string, e.g.: # "3b4c2a1f9e8d7c6b5a4f3e2d1c0b9a8f7e6d5c4b3a2f1e0d9c8b7a6f5e4d3c2" print(signature) ``` ``` -------------------------------- ### Verify Prodamus Signature Source: https://github.com/dnagikh/python-prodamus/blob/master/README.md Validate a received Prodamus signature against the provided dictionary and the expected signature. Prints a success or failure message. ```python signIsGood = prodamus.verify(bodyDict, receivedSign) if signIsGood: print("Signature is awesome") else: print("Signature is incorrect") ``` -------------------------------- ### Parse Query String to Dictionary Source: https://github.com/dnagikh/python-prodamus/blob/master/README.md Convert the raw query string body into a Python dictionary for further processing. ```python bodyDict = prodamus.parse(body) ``` -------------------------------- ### Verify HMAC-SHA256 Signature in Flask Webhook Source: https://context7.com/dnagikh/python-prodamus/llms.txt Verify an incoming signature against the computed signature of the payload in a Flask webhook endpoint. Aborts with 400 if the signature is missing, or 403 if verification fails. ```python import prodamuspy from flask import Flask, request, abort app = Flask(__name__) prodamus = prodamuspy.ProdamusPy("your_prodamus_secret_token") @app.route("/webhook/prodamus", methods=["POST"]) def prodamus_webhook(): raw_body = request.get_data(as_text=True) # Parse the incoming URL-encoded payload payload = prodamus.parse(raw_body) # Extract and remove the signature field from the payload received_sign = payload.pop("sign", None) if not received_sign: abort(400, "Missing signature") # Verify the signature against the remaining payload if prodamus.verify(payload, received_sign): order_id = payload.get("order_id") amount = payload.get("sum") print(f"Payment confirmed: order {order_id}, amount {amount}") # TODO: fulfill the order return "OK", 200 else: print("Invalid signature — possible tampering detected") abort(403, "Signature verification failed") if __name__ == "__main__": app.run(port=5000) ``` -------------------------------- ### Generate HMAC-SHA256 Signature Source: https://context7.com/dnagikh/python-prodamus/llms.txt Create a lowercase hex-encoded HMAC-SHA256 signature from a Python dictionary. The dictionary is first serialized to compact JSON with sorted keys for deterministic output. ```python import prodamuspy prodamus = prodamuspy.ProdamusPy("your_prodamus_secret_token") data = { "order_id": "12345", "order_num": "ORD-2023-001", "sum": "1500.00", "currency": "rub", "products": [ {"name": "Widget Pro", "price": "1500.00", "quantity": "1"} ] } signature = prodamus.sign(data) # Returns a hex string, e.g.: # "3b4c2a1f9e8d7c6b5a4f3e2d1c0b9a8f7e6d5c4b3a2f1e0d9c8b7a6f5e4d3c2" print(signature) ``` -------------------------------- ### Parse Prodamus Webhook Body Source: https://context7.com/dnagikh/python-prodamus/llms.txt Parse a raw URL-encoded query string from a Prodamus webhook notification into a nested Python dictionary. Handles PHP-style array notation for complex data structures. ```python import prodamuspy prodamus = prodamuspy.ProdamusPy("your_prodamus_secret_token") # Raw body string as received in a Prodamus webhook notification raw_body = ( "order_id=12345" "&order_num=ORD-2023-001" "&domain=example.com" "&sum=1500.00" "¤cy=rub" "&customer_phone=%2B79001234567" "&customer_email=customer%40example.com" "&products%5B0%5D%5Bname%5D=Widget+Pro" "&products%5B0%5D%5Bprice%5D=1500.00" "&products%5B0%5D%5Bquantity%5D=1" "&sign=abc123def456..." ) parsed = prodamus.parse(raw_body) # Result: # { # "order_id": "12345", # "order_num": "ORD-2023-001", # "domain": "example.com", # "sum": "1500.00", # "currency": "rub", # "customer_phone": "+79001234567", # "customer_email": "customer@example.com", # "products": [ # {"name": "Widget Pro", "price": "1500.00", "quantity": "1"} # ], # "sign": "abc123def456..." # } print(parsed) ``` -------------------------------- ### parse(body) — Parse a URL-encoded query string Source: https://context7.com/dnagikh/python-prodamus/llms.txt Parses a raw URL-encoded query string body, typically from a Prodamus webhook, into a nested Python dictionary. It handles PHP-style bracket notation for arrays and nested objects. ```APIDOC ## parse(body) — Parse a URL-encoded query string ### Description Parses a raw URL-encoded query string body (as received in a Prodamus webhook POST request) into a nested Python dictionary. It correctly handles PHP-style bracket notation for arrays and nested objects (e.g., `products[0][name]=Widget`). ### Usage ```python import prodamuspy prodamus = prodamuspy.ProdamusPy("your_prodamus_secret_token") # Raw body string as received in a Prodamus webhook notification raw_body = ( "order_id=12345" "&order_num=ORD-2023-001" "&domain=example.com" "&sum=1500.00" "¤cy=rub" "&customer_phone=%2B79001234567" "&customer_email=customer%40example.com" "&products%5B0%5D%5Bname%5D=Widget+Pro" "&products%5B0%5D%5Bprice%5D=1500.00" "&products%5B0%5D%5Bquantity%5D=1" "&sign=abc123def456..." ) parsed = prodamus.parse(raw_body) # Result: # { # "order_id": "12345", # "order_num": "ORD-2023-001", # "domain": "example.com", # "sum": "1500.00", # "currency": "rub", # "customer_phone": "+79001234567", # "customer_email": "customer@example.com", # "products": [ # {"name": "Widget Pro", "price": "1500.00", "quantity": "1"} # ], # "sign": "abc123def456..." # } print(parsed) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.