Skip to content

Billing and betting

BillingAndBetting

Bases: BaseAPIWrapper

Source code in pykuda2/wrappers/sync_wrappers/billing_and_betting.py
class BillingAndBetting(BaseAPIWrapper):
    def get_bill_type_options(
        self, bill_type: BillType, request_reference: Optional[str] = None
    ) -> APIResponse:
        """Retrieves all the options of a bill type that are available from Kuda.

        Args:
            bill_type: The bill type we want to get the options available for e.g.
                BillType.INTERNET_DATA, BillType.CABLE_TV
            request_reference: a unique identifier for this api call.
                it is automatically generated if not provided.

        Returns:
            An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
                of calling this function.

        Raises:
            ConnectionException: when the request times out or in the absence of an internet connection.
        """
        data = {"BillTypeName": bill_type}
        return self._api_call(
            service_type=ServiceType.GET_BILLERS_BY_TYPE,
            data=data,
            request_reference=request_reference,
        )

    def verify_customer_before_purchase(
        self,
        tracking_reference: str,
        kuda_bill_item_identifier: str,
        customer_identification: str,
        request_reference: Optional[str] = None,
    ) -> APIResponse:
        """Verifies the identity of  the beneficiary.

        Just like an account or bank transfer, You need to verify a customer's identity before
        successfully initiating a bill purchase instance. This way you reduce the issue of theft
        or erroneous bill payments which are hard to retrieve.
        You don't need to verify the customer if the bill type is airtime


        Args:
            tracking_reference: Customer's wallet identifier.
            kuda_bill_item_identifier: The Kuda bill unique identifier.
            customer_identification: The customer's unique identifier.
            request_reference: a unique identifier for this api call.
                it is automatically generated if not provided.

        Returns:
            An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
                of calling this function.

        Raises:
            ConnectionException: when the request times out or in the absence of an internet connection.
        """
        data = {
            "TrackingRef": tracking_reference,
            "KudaBillItemIdentifier": kuda_bill_item_identifier,
            "CustomerIdentification": customer_identification,
        }
        return self._api_call(
            service_type=ServiceType.VERIFY_BILL_CUSTOMER,
            data=data,
            request_reference=request_reference,
        )

    def purchase_bill(
        self,
        amount: Union[int, float],
        bill_item_identifier: str,
        customer_identifier: str,
        phone_number: Optional[str] = None,
        request_reference: Optional[str] = None,
    ) -> APIResponse:
        """Purchase a bill from your main account.

        Args:
            amount: Bill amount. Note care should be taken when performing calculations as money is involved.
                a `Decimal` would have been the preferred type compared to `Union[int, float]` that was used.
                it is advisable that static values are passed for this parameter. see
                https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency
            bill_item_identifier: The Kuda bill unique identifier
            customer_identifier: The customer's unique identifier
            phone_number: The customer's phone number It is not required
                if you're purchasing airtime.
            request_reference: a unique identifier for this api call.
                it is automatically generated if not provided.

        Returns:
            An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
                of calling this function.

        Raises:
            ConnectionException: when the request times out or in the absence of an internet connection.
        """
        data = {
            "Amount": amount,
            "BillItemIdentifier": bill_item_identifier,
            "PhoneNumber": phone_number,
            "CustomerIdentifier": customer_identifier,
        }
        return self._api_call(
            service_type=ServiceType.ADMIN_PURCHASE_BILL,
            data=data,
            request_reference=request_reference,
        )

    def purchase_bill_from_virtual_account(
        self,
        tracking_reference: str,
        amount: Union[int, float],
        bill_item_identifier: str,
        phone_number: str,
        customer_identifier: str,
        request_reference: Optional[str] = None,
    ) -> APIResponse:
        """Purchase a bill from your virtual account.

        Args:
            tracking_reference: The customer virtual account Identifier.
            amount: Bill amount. Note care should be taken when performing calculations as money is involved.
                a `Decimal` would have been the preferred type compared to `Union[int, float]` that was used.
                it is advisable that static values are passed for this parameter. see
                https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency
            bill_item_identifier: The Kuda bill unique identifier
            customer_identifier: The customer's unique identifier
            phone_number: The customer's phone number It is not required
                if you're purchasing airtime.
            request_reference: a unique identifier for this api call.
                it is automatically generated if not provided.

        Returns:
            An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
                of calling this function.

        Raises:
            ConnectionException: when the request times out or in the absence of an internet connection.
        """
        data = {
            "Amount": amount,
            "BillItemIdentifier": bill_item_identifier,
            "PhoneNumber": phone_number,
            "CustomerIdentifier": customer_identifier,
            "TrackingReference": tracking_reference,
        }
        return self._api_call(
            service_type=ServiceType.PURCHASE_BILL,
            data=data,
            request_reference=request_reference,
        )

    def get_bill_purchase_status(
        self,
        bill_request_ref: Optional[str],
        bill_response_reference: Optional[str],
        request_reference: Optional[str] = None,
    ) -> APIResponse:
        """Retrieve the status of a bill purchase.

        Args:
            bill_request_ref: The bill request reference.
            bill_response_reference: The bill reference gotten from purchasing the bill.
            request_reference: a unique identifier for this api call.
                it is automatically generated if not provided.

        Returns:
            An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
                of calling this function.

        Raises:
            ConnectionException: when the request times out or in the absence of an internet connection.
        """
        if bill_response_reference and bill_request_ref:
            raise ValueError(
                "Both `bill_response_reference` and `bill_request_ref` should"
                " not be provided. Please provide any but not both"
            )
        data = {
            "BillResponseReference": bill_response_reference,
            "BillRequestRef": bill_request_ref,
        }
        return self._api_call(
            service_type=ServiceType.BILL_TSQ,
            data=data,
            request_reference=request_reference,
        )

    def get_purchased_bills(
        self, request_reference: Optional[str] = None
    ) -> APIResponse:
        """Retrieve bills purchased from the main account.

        Args:
            request_reference: a unique identifier for this api call.
                it is automatically generated if not provided.

        Returns:
            An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
                of calling this function.

        Raises:
            ConnectionException: when the request times out or in the absence of an internet connection.
        """
        return self._api_call(
            service_type=ServiceType.ADMIN_GET_PURCHASED_BILLS,
            request_reference=request_reference,
        )

    def get_purchased_bill_from_virtual_account(
        self, tracking_reference: str, request_reference: Optional[str] = None
    ) -> APIResponse:
        """Retrieve bills purchased from a virtual account.

        Args:
            tracking_reference: The unique identifier of the virtual account.
            request_reference: a unique identifier for this api call.
                it is automatically generated if not provided.

        Returns:
            An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
                of calling this function.

        Raises:
            ConnectionException: when the request times out or in the absence of an internet connection.
        """
        data = {"TrackingReference": tracking_reference}
        return self._api_call(
            service_type=ServiceType.GET_PURCHASED_BILLS,
            data=data,
            request_reference=request_reference,
        )

get_bill_purchase_status(bill_request_ref, bill_response_reference, request_reference=None)

Retrieve the status of a bill purchase.

Parameters:

Name Type Description Default
bill_request_ref Optional[str]

The bill request reference.

required
bill_response_reference Optional[str]

The bill reference gotten from purchasing the bill.

required
request_reference Optional[str]

a unique identifier for this api call. it is automatically generated if not provided.

None

Returns:

Type Description
APIResponse

An APIResponse which is basically just a dataclass containing the data returned by the server as result of calling this function.

Raises:

Type Description
ConnectionException

when the request times out or in the absence of an internet connection.

Source code in pykuda2/wrappers/sync_wrappers/billing_and_betting.py
def get_bill_purchase_status(
    self,
    bill_request_ref: Optional[str],
    bill_response_reference: Optional[str],
    request_reference: Optional[str] = None,
) -> APIResponse:
    """Retrieve the status of a bill purchase.

    Args:
        bill_request_ref: The bill request reference.
        bill_response_reference: The bill reference gotten from purchasing the bill.
        request_reference: a unique identifier for this api call.
            it is automatically generated if not provided.

    Returns:
        An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
            of calling this function.

    Raises:
        ConnectionException: when the request times out or in the absence of an internet connection.
    """
    if bill_response_reference and bill_request_ref:
        raise ValueError(
            "Both `bill_response_reference` and `bill_request_ref` should"
            " not be provided. Please provide any but not both"
        )
    data = {
        "BillResponseReference": bill_response_reference,
        "BillRequestRef": bill_request_ref,
    }
    return self._api_call(
        service_type=ServiceType.BILL_TSQ,
        data=data,
        request_reference=request_reference,
    )

get_bill_type_options(bill_type, request_reference=None)

Retrieves all the options of a bill type that are available from Kuda.

Parameters:

Name Type Description Default
bill_type BillType

The bill type we want to get the options available for e.g. BillType.INTERNET_DATA, BillType.CABLE_TV

required
request_reference Optional[str]

a unique identifier for this api call. it is automatically generated if not provided.

None

Returns:

Type Description
APIResponse

An APIResponse which is basically just a dataclass containing the data returned by the server as result of calling this function.

Raises:

Type Description
ConnectionException

when the request times out or in the absence of an internet connection.

Source code in pykuda2/wrappers/sync_wrappers/billing_and_betting.py
def get_bill_type_options(
    self, bill_type: BillType, request_reference: Optional[str] = None
) -> APIResponse:
    """Retrieves all the options of a bill type that are available from Kuda.

    Args:
        bill_type: The bill type we want to get the options available for e.g.
            BillType.INTERNET_DATA, BillType.CABLE_TV
        request_reference: a unique identifier for this api call.
            it is automatically generated if not provided.

    Returns:
        An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
            of calling this function.

    Raises:
        ConnectionException: when the request times out or in the absence of an internet connection.
    """
    data = {"BillTypeName": bill_type}
    return self._api_call(
        service_type=ServiceType.GET_BILLERS_BY_TYPE,
        data=data,
        request_reference=request_reference,
    )

get_purchased_bill_from_virtual_account(tracking_reference, request_reference=None)

Retrieve bills purchased from a virtual account.

Parameters:

Name Type Description Default
tracking_reference str

The unique identifier of the virtual account.

required
request_reference Optional[str]

a unique identifier for this api call. it is automatically generated if not provided.

None

Returns:

Type Description
APIResponse

An APIResponse which is basically just a dataclass containing the data returned by the server as result of calling this function.

Raises:

Type Description
ConnectionException

when the request times out or in the absence of an internet connection.

Source code in pykuda2/wrappers/sync_wrappers/billing_and_betting.py
def get_purchased_bill_from_virtual_account(
    self, tracking_reference: str, request_reference: Optional[str] = None
) -> APIResponse:
    """Retrieve bills purchased from a virtual account.

    Args:
        tracking_reference: The unique identifier of the virtual account.
        request_reference: a unique identifier for this api call.
            it is automatically generated if not provided.

    Returns:
        An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
            of calling this function.

    Raises:
        ConnectionException: when the request times out or in the absence of an internet connection.
    """
    data = {"TrackingReference": tracking_reference}
    return self._api_call(
        service_type=ServiceType.GET_PURCHASED_BILLS,
        data=data,
        request_reference=request_reference,
    )

get_purchased_bills(request_reference=None)

Retrieve bills purchased from the main account.

Parameters:

Name Type Description Default
request_reference Optional[str]

a unique identifier for this api call. it is automatically generated if not provided.

None

Returns:

Type Description
APIResponse

An APIResponse which is basically just a dataclass containing the data returned by the server as result of calling this function.

Raises:

Type Description
ConnectionException

when the request times out or in the absence of an internet connection.

Source code in pykuda2/wrappers/sync_wrappers/billing_and_betting.py
def get_purchased_bills(
    self, request_reference: Optional[str] = None
) -> APIResponse:
    """Retrieve bills purchased from the main account.

    Args:
        request_reference: a unique identifier for this api call.
            it is automatically generated if not provided.

    Returns:
        An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
            of calling this function.

    Raises:
        ConnectionException: when the request times out or in the absence of an internet connection.
    """
    return self._api_call(
        service_type=ServiceType.ADMIN_GET_PURCHASED_BILLS,
        request_reference=request_reference,
    )

purchase_bill(amount, bill_item_identifier, customer_identifier, phone_number=None, request_reference=None)

Purchase a bill from your main account.

Parameters:

Name Type Description Default
amount Union[int, float]

Bill amount. Note care should be taken when performing calculations as money is involved. a Decimal would have been the preferred type compared to Union[int, float] that was used. it is advisable that static values are passed for this parameter. see https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency

required
bill_item_identifier str

The Kuda bill unique identifier

required
customer_identifier str

The customer's unique identifier

required
phone_number Optional[str]

The customer's phone number It is not required if you're purchasing airtime.

None
request_reference Optional[str]

a unique identifier for this api call. it is automatically generated if not provided.

None

Returns:

Type Description
APIResponse

An APIResponse which is basically just a dataclass containing the data returned by the server as result of calling this function.

Raises:

Type Description
ConnectionException

when the request times out or in the absence of an internet connection.

Source code in pykuda2/wrappers/sync_wrappers/billing_and_betting.py
def purchase_bill(
    self,
    amount: Union[int, float],
    bill_item_identifier: str,
    customer_identifier: str,
    phone_number: Optional[str] = None,
    request_reference: Optional[str] = None,
) -> APIResponse:
    """Purchase a bill from your main account.

    Args:
        amount: Bill amount. Note care should be taken when performing calculations as money is involved.
            a `Decimal` would have been the preferred type compared to `Union[int, float]` that was used.
            it is advisable that static values are passed for this parameter. see
            https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency
        bill_item_identifier: The Kuda bill unique identifier
        customer_identifier: The customer's unique identifier
        phone_number: The customer's phone number It is not required
            if you're purchasing airtime.
        request_reference: a unique identifier for this api call.
            it is automatically generated if not provided.

    Returns:
        An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
            of calling this function.

    Raises:
        ConnectionException: when the request times out or in the absence of an internet connection.
    """
    data = {
        "Amount": amount,
        "BillItemIdentifier": bill_item_identifier,
        "PhoneNumber": phone_number,
        "CustomerIdentifier": customer_identifier,
    }
    return self._api_call(
        service_type=ServiceType.ADMIN_PURCHASE_BILL,
        data=data,
        request_reference=request_reference,
    )

purchase_bill_from_virtual_account(tracking_reference, amount, bill_item_identifier, phone_number, customer_identifier, request_reference=None)

Purchase a bill from your virtual account.

Parameters:

Name Type Description Default
tracking_reference str

The customer virtual account Identifier.

required
amount Union[int, float]

Bill amount. Note care should be taken when performing calculations as money is involved. a Decimal would have been the preferred type compared to Union[int, float] that was used. it is advisable that static values are passed for this parameter. see https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency

required
bill_item_identifier str

The Kuda bill unique identifier

required
customer_identifier str

The customer's unique identifier

required
phone_number str

The customer's phone number It is not required if you're purchasing airtime.

required
request_reference Optional[str]

a unique identifier for this api call. it is automatically generated if not provided.

None

Returns:

Type Description
APIResponse

An APIResponse which is basically just a dataclass containing the data returned by the server as result of calling this function.

Raises:

Type Description
ConnectionException

when the request times out or in the absence of an internet connection.

Source code in pykuda2/wrappers/sync_wrappers/billing_and_betting.py
def purchase_bill_from_virtual_account(
    self,
    tracking_reference: str,
    amount: Union[int, float],
    bill_item_identifier: str,
    phone_number: str,
    customer_identifier: str,
    request_reference: Optional[str] = None,
) -> APIResponse:
    """Purchase a bill from your virtual account.

    Args:
        tracking_reference: The customer virtual account Identifier.
        amount: Bill amount. Note care should be taken when performing calculations as money is involved.
            a `Decimal` would have been the preferred type compared to `Union[int, float]` that was used.
            it is advisable that static values are passed for this parameter. see
            https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency
        bill_item_identifier: The Kuda bill unique identifier
        customer_identifier: The customer's unique identifier
        phone_number: The customer's phone number It is not required
            if you're purchasing airtime.
        request_reference: a unique identifier for this api call.
            it is automatically generated if not provided.

    Returns:
        An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
            of calling this function.

    Raises:
        ConnectionException: when the request times out or in the absence of an internet connection.
    """
    data = {
        "Amount": amount,
        "BillItemIdentifier": bill_item_identifier,
        "PhoneNumber": phone_number,
        "CustomerIdentifier": customer_identifier,
        "TrackingReference": tracking_reference,
    }
    return self._api_call(
        service_type=ServiceType.PURCHASE_BILL,
        data=data,
        request_reference=request_reference,
    )

verify_customer_before_purchase(tracking_reference, kuda_bill_item_identifier, customer_identification, request_reference=None)

Verifies the identity of the beneficiary.

Just like an account or bank transfer, You need to verify a customer's identity before successfully initiating a bill purchase instance. This way you reduce the issue of theft or erroneous bill payments which are hard to retrieve. You don't need to verify the customer if the bill type is airtime

Parameters:

Name Type Description Default
tracking_reference str

Customer's wallet identifier.

required
kuda_bill_item_identifier str

The Kuda bill unique identifier.

required
customer_identification str

The customer's unique identifier.

required
request_reference Optional[str]

a unique identifier for this api call. it is automatically generated if not provided.

None

Returns:

Type Description
APIResponse

An APIResponse which is basically just a dataclass containing the data returned by the server as result of calling this function.

Raises:

Type Description
ConnectionException

when the request times out or in the absence of an internet connection.

Source code in pykuda2/wrappers/sync_wrappers/billing_and_betting.py
def verify_customer_before_purchase(
    self,
    tracking_reference: str,
    kuda_bill_item_identifier: str,
    customer_identification: str,
    request_reference: Optional[str] = None,
) -> APIResponse:
    """Verifies the identity of  the beneficiary.

    Just like an account or bank transfer, You need to verify a customer's identity before
    successfully initiating a bill purchase instance. This way you reduce the issue of theft
    or erroneous bill payments which are hard to retrieve.
    You don't need to verify the customer if the bill type is airtime


    Args:
        tracking_reference: Customer's wallet identifier.
        kuda_bill_item_identifier: The Kuda bill unique identifier.
        customer_identification: The customer's unique identifier.
        request_reference: a unique identifier for this api call.
            it is automatically generated if not provided.

    Returns:
        An `APIResponse` which is basically just a dataclass containing the data returned by the server as result
            of calling this function.

    Raises:
        ConnectionException: when the request times out or in the absence of an internet connection.
    """
    data = {
        "TrackingRef": tracking_reference,
        "KudaBillItemIdentifier": kuda_bill_item_identifier,
        "CustomerIdentification": customer_identification,
    }
    return self._api_call(
        service_type=ServiceType.VERIFY_BILL_CUSTOMER,
        data=data,
        request_reference=request_reference,
    )