Invalid Hash Hash should start with %3a+5F297B


#1

How do i fix this error im stuck

status=Error&error=Invalid+Hash.++Hash+should+start+with%3a+5F297B

This is my python Code

import requests
import hashlib

# Define the URL to which you want to post the data
url = "https://www.paynow.co.zw/interface/initiatetransaction"

# Define the parameters to be sent in the POST request
id                  =xxxx
reference          = 'business_ID'
amount             = 99.99

returnurl          =  'http://localhost:8000'
resulturl          =  'http://localhost:8000'
status             =  "Message"
integration_key    =  "xxxx"



id            = str(id)
reference     = str(reference)
amount        = str(amount)
hash_value    = id + reference + amount  + returnurl +  resulturl+ status + integration_key 
print(hash_value)
# Encode the text to bytes, as required by hashlib
text_bytes = hash_value.encode('utf-8')

# Create a SHA-512 hash object
sha512_hash = hashlib.sha512()

# Update the hash object with the bytes to be hashed
sha512_hash.update(text_bytes)

# Get the hexadecimal representation of the digest and convert it to uppercase
hex_digest_upper = sha512_hash.hexdigest().upper()
hex_digest_upper = str(hex_digest_upper)
print("--------------------------------------")
print(type(hex_digest_upper))
print("--------------------------------------")
data = {
    
    
    'id': my_ID,        # Replace with your actual ID
    'reference': business_ID, # Replace with your actual reference
    'amount': 10.0,       # Replace with the amount to be paid
    'returnurl':'http://localhost:8000',
     'resulturl':'http://localhost:8000',
     
     'status':"Message",
     'hash':hex_digest_upper
}

try:
    # Send a POST request to the URL with the specified parameters
    response = requests.post(url, data=data)

    # Check if the request was successful
    if response.status_code == 200:
        # Process the response data as needed
        print("Transaction initiated successfully!")
        print("Response:", response.text)
    else:
        # If there was an error, print the status code and response text
        print(f"Failed to initiate transaction. Status code: {response.status_code}")
        print("Response:", response.text)
except requests.exceptions.RequestException as e:
    # Handle any errors that occur during the request
    print("An error occurred:", e)

#2

Kindly use our Python SDK for easier integration

pip install paynow