diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..16d875f Binary files /dev/null and b/.DS_Store differ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d0c3cbf --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/make.bat b/make.bat new file mode 100644 index 0000000..747ffb7 --- /dev/null +++ b/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=source +set BUILDDIR=build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/python_flutterwave/charge/bank.py b/python_flutterwave/charge/bank.py index d9a3adc..9b70206 100644 --- a/python_flutterwave/charge/bank.py +++ b/python_flutterwave/charge/bank.py @@ -5,7 +5,7 @@ from python_flutterwave.decorators import handle_api_exceptions -token = os.environ.get("SECRET_KEY") +token = os.environ.get("FW_SECRET_KEY") base_url = "https://api.flutterwave.com/v3/charges" @@ -17,10 +17,14 @@ def initiate_bank_charge( ) -> dict: """ Collect payments from your customers via bank transfers - :param tx_ref: str - :param amount: int - :param email: str - :return: dict + + Args: + tx_ref (int): This is a unique reference peculiar to the transaction being carried out. + amount (int): This is the amount to be charged for the transaction. + email (str): The customer's email address. + + Returns: + dict: Response Details """ params = {"type": "bank_transfer"} @@ -46,10 +50,14 @@ def initiate_nigeria_bank_charge( ) -> dict: """ Charge Nigerian bank accounts using Flutterwave - :param tx_ref: str - :param amount: int - :param email: str - :return: dict + + Args: + tx_ref (int): This is a unique reference peculiar to the transaction being carried out. + amount (int): This is the amount to be charged for the transaction. + email (str): The customer's email address. + + Returns: + dict: Response Details """ params = {"type": "mono"} @@ -73,12 +81,16 @@ def initiate_uk_eu_bank_charge( ) -> dict: """ Charge Customers UK and EU bank accounts - :param tx_ref: str - :param amount: int - :param email: str - :param phone_number: str - :param is_token_io: int - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + phone_number (str): Phone number linked to the customer's bank account or mobile money account + is_token_io (int): + + Returns: + dict: Response Details """ params = {"type": "account-ach-uk"} @@ -108,12 +120,16 @@ def initiate_ach_bank_charge( ) -> dict: """ Collect ACH payments for USD and ZAR transactions - :param tx_ref: str - :param amount: int - :param email: str - :param phone_number: str - :param currency: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + phone_number (str): Phone number linked to the customer's bank account or mobile money account + currency (str): Currency to charge in. Expected values are ZAR for ZA ACH and USD for US ACH. + + Returns: + dict: Response Details """ params = {"type": "account-ach-uk"} diff --git a/python_flutterwave/charge/card.py b/python_flutterwave/charge/card.py index e4c5d49..e60bf56 100644 --- a/python_flutterwave/charge/card.py +++ b/python_flutterwave/charge/card.py @@ -5,7 +5,7 @@ from python_flutterwave.decorators import handle_api_exceptions -token = os.environ.get("SECRET_KEY") +token = os.environ.get("FW_SECRET_KEY") base_url = "https://api.flutterwave.com/v3/charges" @@ -21,14 +21,18 @@ def initiate_card_charge( ) -> dict: """ This is used to initiate card payments. - :param tx_ref: str - :param amount: int - :param card_number: int - :param cvv: int - :param expiry_month: int - :param expiry_year: int - :param email: str - :return: dict + + Args: + tx_ref (int): This is a unique reference peculiar to the transaction being carried out. + amount (int): This is the amount to be charged for the transaction. + email (str): The customer's email address. + card_number (int): The customer's card. + cvv (int): Card CVV. + expiry_month (int): Card expiry month + expiry_year (int): Card expiry year + + Returns: + dict: Response Details """ params = {"type": "card"} diff --git a/python_flutterwave/charge/mobile.py b/python_flutterwave/charge/mobile.py index 8ae7767..0f0e12d 100644 --- a/python_flutterwave/charge/mobile.py +++ b/python_flutterwave/charge/mobile.py @@ -5,7 +5,7 @@ from python_flutterwave.decorators import handle_api_exceptions -token = os.environ.get("SECRET_KEY") +token = os.environ.get("FW_SECRET_KEY") base_url = "https://api.flutterwave.com/v3/charges" @@ -15,11 +15,15 @@ def initiate_mpesa_charge( ) -> dict: """ Collect Mpesa payments from customers in Kenya - :param tx_ref: str - :param amount: int - :param email: str - :param phone_number: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + phone_number (str): Phone number linked to the customer's bank account or mobile money account + + Returns: + dict: Response Details """ params = {"type": "mpesa"} @@ -45,12 +49,16 @@ def initiate_ghana_mobile_charge( ) -> dict: """ Collect mobile money payments from customers in Ghana - :param tx_ref: str - :param amount: int - :param email: str - :param phone_number: str - :param network: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + phone_number (str): Phone number linked to the customer's bank account or mobile money account + network (str): Mobile money network provider (MTN, VODAFONE, TIGO) + + Returns: + dict: Response Details """ params = {"type": "mobile_money_ghana"} @@ -80,11 +88,15 @@ def initiate_uganda_mobile_charge( ) -> dict: """ Collect mobile money payments from customers in Uganda - :param tx_ref: str - :param amount: int - :param email: str - :param phone_number: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + phone_number (str): Phone number linked to the customer's bank account or mobile money account + + Returns: + dict: Response Details """ params = {"type": "mobile_money_uganda"} @@ -115,13 +127,17 @@ def initiate_franco_mobile_charge( ) -> dict: """ Collect mobile money payments from customers in Francophone countries - :param tx_ref: str - :param amount: int - :param email: str - :param phone_number: str - :param currency: str, - :param franco_country_code: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + phone_number (str): Phone number linked to the customer's bank account or mobile money account + currency (str): Currency to charge in. + franco_country_code (str): Country code (BF, CI, CM, SN) + + Returns: + dict: Response Details """ params = {"type": "mobile_money_franco"} @@ -151,11 +167,15 @@ def initiate_tanzania_mobile_charge( ) -> dict: """ Collect mobile money payments from customers in Tanzania - :param tx_ref: str - :param amount: int - :param email: str - :param phone_number: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + phone_number (str): Phone number linked to the customer's bank account or mobile money account + + Returns: + dict: Response Details """ params = {"type": "mobile_money_tanzania"} @@ -181,12 +201,16 @@ def initiate_rwanda_mobile_charge( ) -> dict: """ Collect mobile money payments from customers in Rwanda - :param tx_ref: str - :param amount: int - :param email: str - :param phone_number: str - :param order_id: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + phone_number (str): Phone number linked to the customer's bank account or mobile money account + order_id (str): Unique ref for the mobilemoney transaction to be provided by the merchant + + Returns: + dict: Response Details """ params = {"type": "mobile_money_rwanda"} @@ -216,11 +240,15 @@ def initiate_zambia_mobile_charge( ) -> dict: """ Collect mobile money payments from customers in Zambia - :param tx_ref: str - :param amount: int - :param email: str - :param phone_number: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + phone_number (str): Phone number linked to the customer's bank account or mobile money account + + Returns: + dict: Response Details """ params = {"type": "mobile_money_zambia"} @@ -250,12 +278,16 @@ def initiate_ussd_charge( ) -> dict: """ Collect USSD payments from customers in Nigeria - :param tx_ref: str - :param account_bank: str - :param amount: int - :param email: str - :param phone_number: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + account_bank (str): Bank numeric code. It can be gotten from the banks endpoint. + phone_number (str): Phone number linked to the customer's bank account or mobile money account + + Returns: + dict: Response Details """ params = {"type": "ussd"} @@ -285,11 +317,15 @@ def initiate_apple_pay_charge( ) -> dict: """ Accept payments from your customers with Apple Pay - :param tx_ref: str - :param amount: int - :param email: str - :param currency: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + currency (str): Currency to charge in. + + Returns: + dict: Response Details """ params = {"type": "applepay"} @@ -317,11 +353,15 @@ def initiate_google_pay_charge( ) -> dict: """ Accept payments from your customers with Google Pay - :param tx_ref: str - :param amount: int - :param email: str - :param currency: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + currency (str): Currency to charge in. + + Returns: + dict: Response Details """ params = {"type": "googlepay"} @@ -348,10 +388,14 @@ def initiate_enaira_charge( ) -> dict: """ Accept payment from eNaira wallets - :param tx_ref: str - :param amount: int - :param email: str - :return: dict + + Args: + tx_ref (int): This is a unique reference peculiar to the transaction being carried out. + amount (int): This is the amount to be charged for the transaction. + email (str): The customer's email address. + + Returns: + dict: Response Details """ params = {"type": "enaira"} @@ -377,10 +421,14 @@ def initiate_fawry_pay_charge( ) -> dict: """ Receive Fawry payments from customers in Egypt - :param tx_ref: str - :param amount: int - :param email: str - :return: dict + + Args: + tx_ref (int): This is a unique reference peculiar to the transaction being carried out. + amount (int): This is the amount to be charged for the transaction. + email (str): The customer's email address. + + Returns: + dict: Response Details """ params = {"type": "fawry_pay"} @@ -408,11 +456,14 @@ def initiate_paypal_charge( ) -> dict: """ Collect payments from customers with PayPal - :param tx_ref: str - :param amount: int - :param email: str - :param currency: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + currency (str): Currency to charge in. + Returns: + dict: Response Details """ params = {"type": "paypal"} diff --git a/python_flutterwave/charge/validation.py b/python_flutterwave/charge/validation.py index ebb30b0..742a177 100644 --- a/python_flutterwave/charge/validation.py +++ b/python_flutterwave/charge/validation.py @@ -3,16 +3,20 @@ import json from python_flutterwave.decorators import handle_api_exceptions -token = os.environ.get("SECRET_KEY") +token = os.environ.get("FW_SECRET_KEY") @handle_api_exceptions def validate_charge(otp: str, flw_ref: str) -> dict: """ - Collect Mpesa payments from customers in Kenya - :param flw_ref: str - :param otp: str - :return: dict + Validate a charge + + Args: + flw_ref (str): Reference returned in the initiate charge call as `data.flw_ref` + otp (str): Random number of at least 6 characters sent to customers phone number. + + Returns: + dict: Response Details """ params = {"type": "mpesa"} diff --git a/python_flutterwave/objects.py b/python_flutterwave/objects.py index fd1bef9..4aa4269 100644 --- a/python_flutterwave/objects.py +++ b/python_flutterwave/objects.py @@ -5,10 +5,12 @@ class RetryStrategy: """ This object defines retries for failed tokenization attempts. - :param retry_interval: int - :param retry_amount_variable: int - :param retry_attempt_variable: int - :param last_retry_attempt: int = 10 + + Args: + retry_interval (int): Number in minutes for the next retry attempt. + retry_amount_variable (int): Amount to be retried after the specified number of attempts in percentage. + retry_attempt_variable (int): Number of retries to make after the initial tokenization attempt. + last_retry_attempt (int): Maximum number of retries to attempt. If unspecified, It is set to 10 by default. """ retry_interval: int @@ -21,12 +23,14 @@ class RetryStrategy: class ChargeData: """ Object containing your charge data - :param currency: str - :param token: str - :param country: str - :param amount: int - :param email: str - :param tx_ref: str + + Args: + currency (str): Currency to charge in + token (str): Token id obtained + country (str): Country Code + amount (int): Charge Amount + email (str): Customer Email + tx_ref (str): Unique ref """ currency: str diff --git a/python_flutterwave/tokenization/tokenized_charge.py b/python_flutterwave/tokenization/tokenized_charge.py index 4321e15..8fe8c63 100644 --- a/python_flutterwave/tokenization/tokenized_charge.py +++ b/python_flutterwave/tokenization/tokenized_charge.py @@ -14,12 +14,16 @@ def initiate_tokenized_charge( ) -> dict: """ This endpoint helps you tokenize a customer's card - :param token: str - :param tx_ref: str - :param amount: int - :param email: str - :param currency: str - :return: dict + + Args: + tx_ref (int): Unique reference peculiar to the transaction. + amount (int): Amount to be charged for the transaction. + email (str): The customer's email address. + currency (str): Currency to be used + token (str): Card token returned from the transaction verification endpoint as data.card.token + + Returns: + dict: Response Details """ payload = json.dumps( @@ -51,9 +55,13 @@ def initiate_bulk_tokenized_charges( ) -> dict: """ Tokenize multiple cards at once - :param retry_strategy: RetryStrategy - :param bulk_data: list[ChargeData] - :return: dict + + Args: + retry_strategy: RetryStrategy + bulk_data: list[ChargeData] + + Returns: + dict: Response Details """ payload = json.dumps( @@ -80,7 +88,12 @@ def initiate_bulk_tokenized_charges( def fetch_bulk_tokenized_charges(bulk_id: int): """ This endpoint allows you to get bulk tokenized charges transactions - :param bulk_id: int + + Args: + bulk_id (int): id returned in the bulk charge response + + Returns: + dict: Response Details """ headers = { @@ -100,7 +113,12 @@ def fetch_bulk_tokenized_charges(bulk_id: int): def fetch_bulk_tokenized_charges_status(bulk_id: int): """ This endpoint allows you to query the status of a bulk tokenized charge - :param bulk_id: int + + Args: + bulk_id (int): id returned in the bulk charge response + + Returns: + dict: Response Details """ headers = { @@ -120,10 +138,15 @@ def fetch_bulk_tokenized_charges_status(bulk_id: int): def update_card_token(email: str, full_name: str, phone_number: str, token: str): """ This endpoints allow developers update the details tied to a customer's card token. - :param email: str - :param phone_number: str - :param full_name: str - :param token: str + + Args: + email (str): The customer's email address. + full_name (str): The customer's email address. + phone_number (str): Customer's phone number. + token (str): Card token returned from the transaction verification endpoint as data.card.token + + Returns: + dict: Response Details """ payload = json.dumps( diff --git a/requirements.txt b/requirements.txt index f182b94..74cf51f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,5 @@ charset-normalizer idna requests urllib3 +sphinx +autodoc diff --git a/setup.cfg b/setup.cfg index 80d486a..d1c6e0b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = python-flutterwave -version = 1.0.1 +version = 1.1.1 author = William Otieno author_email = jimmywilliamotieno@gmail.com description = Python Wrapper for interacting with the Flutterwave Payments API diff --git a/source/conf.py b/source/conf.py new file mode 100644 index 0000000..3705899 --- /dev/null +++ b/source/conf.py @@ -0,0 +1,27 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = 'python-flutterwave' +copyright = '2023, William Otieno' +author = 'William Otieno' + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = [] + +templates_path = ['_templates'] +exclude_patterns = [] + + + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = 'alabaster' +html_static_path = ['_static'] diff --git a/source/index.rst b/source/index.rst new file mode 100644 index 0000000..86e1b24 --- /dev/null +++ b/source/index.rst @@ -0,0 +1,20 @@ +.. python-flutterwave documentation master file, created by + sphinx-quickstart on Sun Dec 31 19:28:43 2023. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to python-flutterwave's documentation! +============================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search`