|
1 | 1 | # pay_ccavenue |
2 | 2 |
|
3 | | -A simple package to integrate CCAvenue. It can be used for both `iframe` and `seemless` methods. |
| 3 | +A Python package for seamless integration with CCAvenue payment gateway. |
4 | 4 |
|
5 | | -## How to install |
| 5 | +## Features |
| 6 | + |
| 7 | +- Easy-to-use API for CCAvenue integration |
| 8 | +- Secure encryption and decryption of payment data |
| 9 | +- Flexible configuration via environment variables or direct instantiation |
| 10 | +- Type hints for better code reliability |
| 11 | + |
| 12 | +## Current Limitations |
| 13 | + |
| 14 | +- This package does not yet support iframe integration with CCAvenue. It currently provides basic encryption and decryption functionality for standard integration. |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +Install the package using pip: |
6 | 19 |
|
7 | 20 | ```bash |
8 | 21 | pip install pay_ccavenue |
9 | 22 | ``` |
10 | 23 |
|
11 | | -## Import |
| 24 | +## Quick Start |
| 25 | + |
| 26 | +1. Import the CCAvenue class: |
12 | 27 |
|
13 | 28 | ```python |
14 | 29 | from pay_ccavenue import CCAvenue |
15 | 30 | ``` |
16 | 31 |
|
17 | | -## Initialize the Package |
18 | | - |
19 | | -We can either setup via the environment or by passing the credentials directly to the plugin. |
| 32 | +2. Initialize the CCAvenue object: |
20 | 33 |
|
21 | | -### Via the environment variables |
22 | | - |
23 | | -Set the credentials in the environment variables |
| 34 | +```python |
| 35 | +# Using environment variables |
| 36 | +ccavenue = CCAvenue() |
24 | 37 |
|
25 | | -- Set `CCAVENUE_WORKING_KEY` for the `WORKING_KEY` |
26 | | -- Set `CCAVENUE_ACCESS_CODE` for the `ACCESS_CODE` |
27 | | -- Set `CCAVENUE_MERCHANT_CODE` for the `MERCHANT_CODE` |
28 | | -- Set `CCAVENUE_REDIRECT_URL` for the `REDIRECT_URL` |
29 | | -- Set `CCAVENUE_CANCEL_URL` for the `CANCEL_URL` |
| 38 | +# Or, passing credentials directly |
| 39 | +ccavenue = CCAvenue( |
| 40 | + working_key="YOUR_WORKING_KEY", |
| 41 | + access_code="YOUR_ACCESS_CODE", |
| 42 | + merchant_code="YOUR_MERCHANT_CODE", |
| 43 | + redirect_url="YOUR_REDIRECT_URL", |
| 44 | + cancel_url="YOUR_CANCEL_URL" |
| 45 | +) |
| 46 | +``` |
30 | 47 |
|
31 | | -And then instantiate the `CCAvenue` object as shown below |
| 48 | +3. Encrypt payment data: |
32 | 49 |
|
33 | 50 | ```python |
34 | | -ccavenue = CCAvenue() |
| 51 | +form_data = { |
| 52 | + "order_id": "123456", |
| 53 | + "amount": "1000.00", |
| 54 | + "currency": "INR", |
| 55 | + # Add other required fields |
| 56 | +} |
| 57 | + |
| 58 | +encrypted_data = ccavenue.encrypt(form_data) |
35 | 59 | ``` |
36 | 60 |
|
37 | | -### Pasing the credentials directly |
| 61 | +4. Decrypt response data: |
38 | 62 |
|
39 | 63 | ```python |
40 | | -ccavenue = CCAvenue(WORKING_KEY, ACCESS_CODE, MERCHANT_CODE, REDIRECT_URL, CANCEL_URL) |
| 64 | +response_data = { |
| 65 | + "encResp": "ENCRYPTED_RESPONSE_FROM_CCAVENUE" |
| 66 | +} |
| 67 | + |
| 68 | +decrypted_data = ccavenue.decrypt(response_data) |
41 | 69 | ``` |
42 | 70 |
|
43 | | ---- |
| 71 | +## Configuration |
44 | 72 |
|
45 | | -**NOTE** |
| 73 | +### Environment Variables |
46 | 74 |
|
47 | | -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`. |
| 75 | +Set the following environment variables to configure the package: |
48 | 76 |
|
49 | | ---- |
| 77 | +- `CCAVENUE_WORKING_KEY`: Your CCAvenue working key |
| 78 | +- `CCAVENUE_ACCESS_CODE`: Your CCAvenue access code |
| 79 | +- `CCAVENUE_MERCHANT_CODE`: Your CCAvenue merchant code |
| 80 | +- `CCAVENUE_REDIRECT_URL`: URL to redirect after successful payment |
| 81 | +- `CCAVENUE_CANCEL_URL`: URL to redirect after cancelled payment |
50 | 82 |
|
51 | | -## To encrypt the data |
| 83 | +### Direct Instantiation |
52 | 84 |
|
53 | | -`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. |
| 85 | +Pass the configuration parameters directly when creating the CCAvenue object: |
54 | 86 |
|
55 | 87 | ```python |
56 | | -encrypt_data = ccavenue.encrypt(form_data) |
| 88 | +ccavenue = CCAvenue( |
| 89 | + working_key="YOUR_WORKING_KEY", |
| 90 | + access_code="YOUR_ACCESS_CODE", |
| 91 | + merchant_code="YOUR_MERCHANT_CODE", |
| 92 | + redirect_url="YOUR_REDIRECT_URL", |
| 93 | + cancel_url="YOUR_CANCEL_URL" |
| 94 | +) |
57 | 95 | ``` |
58 | 96 |
|
59 | | -Pass the `encrypt_data` from the above to the view to render the IFrame. |
| 97 | +## API Reference |
60 | 98 |
|
61 | | -## Decrypt the data received from the CCAvenue |
| 99 | +### `CCAvenue` Class |
62 | 100 |
|
63 | | -`form_data` is the post request body which is a dictionary of the related data received from the CCAvenue. The `decrypt()` method returns the dictionary of the data received from the CCAvenue. |
| 101 | +#### Methods |
64 | 102 |
|
65 | | -```python |
66 | | -decrypted_data = ccavenue.decrypt(form_data) |
67 | | -``` |
| 103 | +- `encrypt(data: Dict[str, Any]) -> str`: Encrypts the payment data |
| 104 | +- `decrypt(data: Dict[str, str]) -> Dict[str, str]`: Decrypts the response data |
| 105 | + |
| 106 | +### `CCavenueFormData` Class |
| 107 | + |
| 108 | +Represents the form data required for CCAvenue payment processing. It includes mandatory and optional fields, and provides methods for data manipulation and validation. |
| 109 | + |
| 110 | +#### Important Fields |
| 111 | + |
| 112 | +- `merchant_id`: CCAvenue merchant ID |
| 113 | +- `order_id`: Unique order identifier |
| 114 | +- `currency`: Payment currency (default: "INR") |
| 115 | +- `amount`: Payment amount |
| 116 | +- `redirect_url`: URL for successful payment redirection |
| 117 | +- `cancel_url`: URL for cancelled payment redirection |
| 118 | + |
| 119 | +For a complete list of fields, refer to the `CCavenueFormData` class documentation. |
| 120 | + |
| 121 | +## Security Considerations |
| 122 | + |
| 123 | +- The package uses AES encryption with CBC mode for secure communication with CCAvenue. |
| 124 | +- Ensure that your working key and other sensitive information are kept secure and not exposed in your codebase. |
| 125 | + |
| 126 | +## Contributing |
| 127 | + |
| 128 | +Contributions are welcome! Please feel free to submit a Pull Request. |
| 129 | + |
| 130 | +## License |
| 131 | + |
| 132 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
68 | 133 |
|
69 | | -# Limitations |
| 134 | +## Disclaimer |
70 | 135 |
|
71 | | -1. I have not added any tests as of now in the package, but I have tested this out for my project after debugging their given examples and Stackoverflow to simplify it. |
72 | | -2. More detailed documentation. |
| 136 | +This package is not officially associated with CCAvenue. Use it at your own risk and ensure compliance with CCAvenue's terms of service. |
0 commit comments