Utilities¶
Signature Utilities¶
Signature calculation and verification for RoboKassa.
- aiorobokassa.utils.signature.calculate_payment_signature(merchant_login: str, out_sum: str, inv_id: str | None, password: str, algorithm: str | SignatureAlgorithm = SignatureAlgorithm.MD5, receipt: str | None = None, shp_params: Dict[str, str] | None = None) str[source]¶
Calculate signature for payment URL.
Signature format: MD5(merchant_login:out_sum:inv_id:receipt:Shp_param1:Shp_param2:…:password1) Order is FIXED: MerchantLogin:OutSum:InvId:Receipt:Shp_param1:Shp_param2:…:password1 If InvId is not provided, it must be empty but present (two colons: ::) If receipt is provided, it must be included in signature calculation. Shp_ parameters must be sorted alphabetically by key (without Shp_ prefix).
- Parameters:
- Returns:
Signature string
- aiorobokassa.utils.signature.calculate_signature(values: Dict[str, str], password: str, algorithm: str | SignatureAlgorithm = SignatureAlgorithm.MD5) str[source]¶
Calculate signature for RoboKassa.
- Parameters:
values – Dictionary of values to include in signature (sorted by key)
password – Password for signature calculation
algorithm – Hash algorithm (MD5, SHA256, SHA512) or SignatureAlgorithm enum
- Returns:
Hexadecimal signature string
- Raises:
InvalidSignatureAlgorithmError – If algorithm is not supported
- aiorobokassa.utils.signature.calculate_split_signature(invoice_json: str, password: str, algorithm: str | SignatureAlgorithm = SignatureAlgorithm.MD5) str[source]¶
Calculate signature for split payment.
Signature format: MD5(invoice_json + password1) Where invoice_json is the JSON string in “pure” form (not URL-encoded).
- Parameters:
invoice_json – Invoice JSON string (not URL-encoded)
password – Password (password1 of master merchant)
algorithm – Hash algorithm
- Returns:
Hexadecimal signature string
- Raises:
InvalidSignatureAlgorithmError – If algorithm is not supported
- aiorobokassa.utils.signature.verify_result_url_signature(out_sum: str, inv_id: str, password: str, received_signature: str, algorithm: str | SignatureAlgorithm = SignatureAlgorithm.MD5, shp_params: Dict[str, str] | None = None) bool[source]¶
Verify signature from ResultURL notification.
Signature format: MD5(OutSum:InvId:Shp_param1:Shp_param2:…:password2) Where Shp_ parameters are sorted alphabetically. Order is FIXED: OutSum:InvId (not sorted alphabetically)
- aiorobokassa.utils.signature.verify_signature(values: Dict[str, str], password: str, received_signature: str, algorithm: str | SignatureAlgorithm = SignatureAlgorithm.MD5) bool[source]¶
Verify signature from RoboKassa.
- Parameters:
values – Dictionary of values used in signature
password – Password for signature verification
received_signature – Signature received from RoboKassa
algorithm – Hash algorithm (MD5, SHA256, SHA512)
- Returns:
True if signature is valid, False otherwise
- aiorobokassa.utils.signature.verify_success_url_signature(out_sum: str, inv_id: str, password: str, received_signature: str, algorithm: str | SignatureAlgorithm = SignatureAlgorithm.MD5, shp_params: Dict[str, str] | None = None) bool[source]¶
Verify signature from SuccessURL redirect.
Signature format: MD5(OutSum:InvId:Shp_param1:Shp_param2:…:password1) Where Shp_ parameters are sorted alphabetically. Order is FIXED: OutSum:InvId (not sorted alphabetically)
Helper Functions¶
Utility functions for aiorobokassa.
- aiorobokassa.utils.helpers.build_url(base_url: str, params: Dict[str, str | None]) str[source]¶
Build URL with query parameters.
Parameters are properly URL-encoded. SignatureValue should be last.
- Parameters:
base_url – Base URL
params – Dictionary of query parameters (None values are skipped)
- Returns:
URL with query string
XML Utilities¶
XML helpers for RoboKassa API.