def __build_mobile(self, payment: Payment, phone: str, method: str): """Build up a mobile payment into the format required by Paynow Args: payment (Payment): The payment object to format phone (str): The phone number to send to Paynow method (str): The mobile money method being employed Note: Currently supported methods are `ecocash` and `onemoney` Returns: dict: A dictionary properly formatted in the format required by Paynow """ body = { "resulturl": self.result_url, "returnurl": self.return_url, "reference": payment.reference, "amount": payment.total(), "id": self.integration_id, "additionalinfo": payment.info(), "authemail": payment.auth_email, "phone": phone, "method": method, "status": "Message" } for key, value in body.items(): body[key] = quote_plus(str(value)) # Url encode the body['hash'] = self.__hash(body, self.integration_key) return body def __hash(self, items: {}, integration_key: str): """Generates a SHA512 hash of the transaction Args: items (dict): The transaction dictionary to hash integration_key (str): Merchant integration key to use during hashing Returns: str: The hashed transaction """ out = "" for key, value in items.items(): out += str(value) out += integration_key return hashlib.sha512(out.encode('utf-8')).hexdigest().upper()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question