Skip to content

Instantly share code, notes, and snippets.

@muendelezaji
Last active May 19, 2023 18:22
Show Gist options
  • Save muendelezaji/924591f2388a4d2c293b95609a56e6c2 to your computer and use it in GitHub Desktop.
Save muendelezaji/924591f2388a4d2c293b95609a56e6c2 to your computer and use it in GitHub Desktop.

Revisions

  1. muendelezaji revised this gist May 19, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions payment-reference.py
    Original 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:])
  2. muendelezaji revised this gist May 19, 2023. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion payment-reference.py
    Original 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]
    - [email protected]
    :param email: Customer's email
  3. muendelezaji revised this gist May 19, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions payment-reference.py
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    from datetime import datetime

    def create_payment_ref(email, method, country):
    def generate_payment_ref(email, method, country):
    """
    Creates a unique payment reference that will be sent to the payment provider.
    Generates a unique payment reference that will be sent to the payment provider.
    Examples of returned references:
    - [email protected]
  4. muendelezaji revised this gist May 19, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion payment-reference.py
    Original 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, MOBILE, etc.
    :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
    """
  5. muendelezaji created this gist May 19, 2023.
    37 changes: 37 additions & 0 deletions payment-reference.py
    Original 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