import hmacimport hashlibimport jsondef calculate_hmac(vibess_secret_key: str, external_user_id: str, churncut_app_id: int | str, churncut_expiration_timestamp: str): message = (external_user_id + churncut_app_id + churncut_expiration_timestamp).encode('utf-8') return hmac.new( vibess_secret_key.encode('utf-8'), message, digestmod=hashlib.sha256 ).hexdigest()vibess_secret_key = "your-secret-key" # We will provide you thisexternal_user_id = "cus_XXXXXXXXXXXXXX" # from stripetoken_expiration_timestamp = "1767139200" # replace this for any expiration date as a timestampvibess_app_id = 1 # we will provide you this number although in the future you may be abble to access it in our management appprint(calculate_hmac(vibess_secret_key, external_user_id, vibess_app_id, token_expiration_timestamp))
Use the generated HMAC token to initialize the cancellation flow:
Copy
startCancellationFlow( "cus_XXXXXXXXXXXXXX", // stripe customer id "sub_xxxxxxxxxxxxxxxxxxxxxxxxx", // stripe current subscription "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // Here goes your hmac token "1767139200", // Expiration timestamp "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" // vibess app id)// the info has to be the same as the one used to generate the hmac token
Important: Ensure all parameters match those used to generate the HMAC token
If you don’t have access to the Stripe Customer ID, you can integrate using the user’s email. This method allows session-based identification and supports actions like subscription management or cancellation by matching the user’s email address.
ATTENTION: This is not recommended unless you are sure that:
Your user accounts have unique emails in Stripe
Your users only have a single active subscription at a time
If these conditions are not met, you could get unexpected behavior.
Example:
Copy
startCancellationFlow( null, null, "3423613948ef3bef5a62d33ba58da022bebd72c21c30bca0dfae50606667647e", // Here goes your hmac token "1767139200", // Expiration timestamp "cbbb778e-afda-5ae5-82f4-c58dcafc7f1a", // vibess app id "[email protected]", );