Last active
May 19, 2023 18:22
-
-
Save muendelezaji/924591f2388a4d2c293b95609a56e6c2 to your computer and use it in GitHub Desktop.
Revisions
-
muendelezaji revised this gist
May 19, 2023 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,6 +32,7 @@ def get_email_from_payment_ref(pay_ref): """ # Split the payment reference string into groups by "-" groups = pay_ref.split("-") # Rejoin all groups after the 5th "-" (i.e. where email starts) # This ensures any emails with "-" will be extracted correctly email = "-".join(groups[5:]) -
muendelezaji revised this gist
May 19, 2023 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,8 @@ def generate_payment_ref(email, method, country): Examples of returned references: - [email protected] - [email protected] - [email protected] - [email protected] :param email: Customer's email -
muendelezaji revised this gist
May 19, 2023 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ from datetime import datetime def generate_payment_ref(email, method, country): """ Generates a unique payment reference that will be sent to the payment provider. Examples of returned references: - [email protected] -
muendelezaji revised this gist
May 19, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ def create_payment_ref(email, method, country): - [email protected] :param email: Customer's email :param method: Payment method - CARD, PUSH, BANK, USSD etc. :param country: Country of service - TZ, KE etc. :return: Unique payment reference to be sent to the provider """ -
muendelezaji created this gist
May 19, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ from datetime import datetime def create_payment_ref(email, method, country): """ Creates a unique payment reference that will be sent to the payment provider. Examples of returned references: - [email protected] - [email protected] - [email protected] :param email: Customer's email :param method: Payment method - CARD, MOBILE, etc. :param country: Country of service - TZ, KE etc. :return: Unique payment reference to be sent to the provider """ # Generate date and time strings in the right format date = datetime.now().strftime("%Y%m%d") time = datetime.now().strftime("%H%M%S") # Combine it with the customer's email, payment method and country ref = f"TENDA-{country}-{method}-{date}-{time}-{email}" return ref def get_email_from_payment_ref(pay_ref): """ Extracts the customer's email from payment reference sent to the provider. :param pay_ref: Payment reference :return: Email of the customer that attempted payment """ # Split the payment reference string into groups by "-" groups = pay_ref.split("-") # Rejoin all groups after the 5th "-" (i.e. where email starts) # This ensures any emails with "-" will be extracted correctly email = "-".join(groups[5:]) return email