diff --git a/README.md b/README.md index 0c1a332..5b2879d 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ Set the credentials in the environment variables - Set `CCAVENUE_WORKING_KEY` for the `WORKING_KEY` - Set `CCAVENUE_ACCESS_CODE` for the `ACCESS_CODE` - Set `CCAVENUE_MERCHANT_CODE` for the `MERCHANT_CODE` +- Set `CCAVENUE_REDIRECT_URL` for the `REDIRECT_URL` +- Set `CCAVENUE_CANCEL_URL` for the `CANCEL_URL` And then instantiate the `CCAvenue` object as shown below @@ -35,9 +37,17 @@ ccavenue = CCAvenue() ### Pasing the credentials directly ```python -ccavenue = CCAvenue(WORKING_KEY, ACCESS_CODE, MERCHANT_CODE) +ccavenue = CCAvenue(WORKING_KEY, ACCESS_CODE, MERCHANT_CODE, REDIRECT_URL, CANCEL_URL) ``` +--- + +**NOTE** + +You don't need to explicitely pass `WORKING_KEY`, `ACCESS_CODE`, `MERCHANT_CODE`, `REDIRECT_URL`, `CANCEL_URL` in the form data for any of the method i.e. `Iframe` or `seemless`. + +--- + ## To encrypt the data `form_data` is the post request body which is a dictionary of the related data for the payment. You don't need to pass the Merchant ID though. Since we have already intiated the package with the correct `MERCHANT_CODE`. `encrypt()` method return the encrypted string that can be ussed directly in the Iframe rendering. diff --git a/pyproject.toml b/pyproject.toml index 89617aa..3601dba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pay_ccavenue" -version = "0.1.4" +version = "0.1.5" description = "A simple library to setup payment integration with CCAvenue" authors = ["Kuldeep Pisda "] license = "MIT" diff --git a/src/pay_ccavenue/__init__.py b/src/pay_ccavenue/__init__.py index 7098921..acf0680 100644 --- a/src/pay_ccavenue/__init__.py +++ b/src/pay_ccavenue/__init__.py @@ -1,3 +1,3 @@ from .ccavenue import CCAvenue # noqa -__version__ = "0.1.4" +__version__ = "0.1.5" diff --git a/src/pay_ccavenue/ccavenue.py b/src/pay_ccavenue/ccavenue.py index c4974fd..7ff1ade 100644 --- a/src/pay_ccavenue/ccavenue.py +++ b/src/pay_ccavenue/ccavenue.py @@ -10,6 +10,8 @@ class CCAvenue: __WORKING_KEY: str = None __ACCESS_CODE: str = None __MERCHANT_CODE: str = None + __REDIRECT_URL: str = None + __CANCEL_URL: str = None __iv = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" __form_data = { "order_id": "", @@ -51,6 +53,8 @@ def __init__( working_key: str = None, access_code: str = None, merchant_code: str = None, + redirect_url: str = None, + cancel_url: str = None, ) -> None: """ Initialize the CCAvenue class. @@ -62,6 +66,8 @@ def __init__( self.load_working_key(working_key) self.load_access_code(access_code) self.load_merchant_code(merchant_code) + self.load_redirect_url(redirect_url) + self.load_cancel_url(cancel_url) def load_working_key(self, working_key: str = None) -> None: """ @@ -117,6 +123,42 @@ def load_merchant_code(self, merchant_code: str = None) -> None: "code as an environment variable by setting it as CCAVENUE_MERCHANT_CODE." ) + def load_redirect_url(self, redirect_url: str) -> None: + """ + Load a redirect url into the CCAvenue class. + + :param redirect_url: The redirect url for the CCAvenue gateway. + """ + if redirect_url: + self.__REDIRECT_URL = redirect_url + else: + self.__REDIRECT_URL = os.environ.get("CCAVENUE_REDIRECT_URL") + + if self.__REDIRECT_URL is None or isinstance(self.__REDIRECT_URL, str) is False: + raise ValueError( + "You must provide a redirect url for CCAvenue or set redirect url " + "as an environment variable by setting it as CCAVENUE_REDIRECT_URL." + ) + self.__form_data["redirect_url"] = self.__REDIRECT_URL + + def load_cancel_url(self, cancel_url: str) -> None: + """ + Load a cancel url into the CCAvenue class. + + :param cancel_url: The cancel url for the CCAvenue gateway. + """ + if cancel_url: + self.__CANCEL_URL = cancel_url + else: + self.__CANCEL_URL = os.environ.get("CCAVENUE_CANCEL_URL") + + if self.__CANCEL_URL is None or isinstance(self.__CANCEL_URL, str) is False: + raise ValueError( + "You must provide a cancel url for CCAvenue or set cancel url " + "as an environment variable by setting it as CCAVENUE_CANCEL_URL." + ) + self.__form_data["cancel_url"] = self.__CANCEL_URL + def pad(self, data: str): """ Pad the data to be encrypted. diff --git a/tests/test_python_pay_ccavenue.py b/tests/test_python_pay_ccavenue.py index ec409c3..191f401 100644 --- a/tests/test_python_pay_ccavenue.py +++ b/tests/test_python_pay_ccavenue.py @@ -2,4 +2,4 @@ def test_version(): - assert __version__ == "0.1.4" + assert __version__ == "0.1.5"