Skip to content

Commit

Permalink
Added option to store REDIRECT_URL and CANCEL_URL in the environment …
Browse files Browse the repository at this point in the history
…variables
  • Loading branch information
kdpisda committed Jan 16, 2022
1 parent d0888c6 commit d110ef6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <pisdak79@gmail.com>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/pay_ccavenue/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .ccavenue import CCAvenue # noqa

__version__ = "0.1.4"
__version__ = "0.1.5"
42 changes: 42 additions & 0 deletions src/pay_ccavenue/ccavenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down Expand Up @@ -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.
Expand All @@ -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:
"""
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_python_pay_ccavenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == "0.1.4"
assert __version__ == "0.1.5"

0 comments on commit d110ef6

Please sign in to comment.