Skip to content

Commit

Permalink
Merge pull request #2 from kdpisda/major-1.0.0
Browse files Browse the repository at this point in the history
Major 1.0.0
  • Loading branch information
kdpisda authored Sep 25, 2024
2 parents 2378adb + e9b5647 commit 183c516
Show file tree
Hide file tree
Showing 16 changed files with 874 additions and 579 deletions.
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Bug report
about: Create a report to help us improve
title: '[BUG] '
labels: 'bug'
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environment (please complete the following information):**
- OS: [e.g. iOS]
- Python version: [e.g. 3.8]
- pay_ccavenue version: [e.g. 1.0.0]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: '[FEATURE] '
labels: 'enhancement'
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
28 changes: 28 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.

Fixes # (issue)

## Type of change
Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

## How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

- [ ] Test A
- [ ] Test B

## Checklist:
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.29.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: ["--py36-plus"]
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.6.0
rev: v3.12.0
hooks:
- id: reorder-python-imports
- repo: https://github.com/psf/black
rev: 21.10b0
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-implicit-str-concat
args: [--max-line-length=90]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.4.0
hooks:
- id: fix-byte-order-marker
- id: trailing-whitespace
Expand Down
132 changes: 98 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,136 @@
# pay_ccavenue

A simple package to integrate CCAvenue. It can be used for both `iframe` and `seemless` methods.
A Python package for seamless integration with CCAvenue payment gateway.

## How to install
## Features

- Easy-to-use API for CCAvenue integration
- Secure encryption and decryption of payment data
- Flexible configuration via environment variables or direct instantiation
- Type hints for better code reliability

## Current Limitations

- This package does not yet support iframe integration with CCAvenue. It currently provides basic encryption and decryption functionality for standard integration.

## Installation

Install the package using pip:

```bash
pip install pay_ccavenue
```

## Import
## Quick Start

1. Import the CCAvenue class:

```python
from pay_ccavenue import CCAvenue
```

## Initialize the Package

We can either setup via the environment or by passing the credentials directly to the plugin.
2. Initialize the CCAvenue object:

### Via the environment variables

Set the credentials in the environment variables
```python
# Using environment variables
ccavenue = CCAvenue()

- 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`
# Or, passing credentials directly
ccavenue = CCAvenue(
working_key="YOUR_WORKING_KEY",
access_code="YOUR_ACCESS_CODE",
merchant_code="YOUR_MERCHANT_CODE",
redirect_url="YOUR_REDIRECT_URL",
cancel_url="YOUR_CANCEL_URL"
)
```

And then instantiate the `CCAvenue` object as shown below
3. Encrypt payment data:

```python
ccavenue = CCAvenue()
form_data = {
"order_id": "123456",
"amount": "1000.00",
"currency": "INR",
# Add other required fields
}

encrypted_data = ccavenue.encrypt(form_data)
```

### Pasing the credentials directly
4. Decrypt response data:

```python
ccavenue = CCAvenue(WORKING_KEY, ACCESS_CODE, MERCHANT_CODE, REDIRECT_URL, CANCEL_URL)
response_data = {
"encResp": "ENCRYPTED_RESPONSE_FROM_CCAVENUE"
}

decrypted_data = ccavenue.decrypt(response_data)
```

---
## Configuration

**NOTE**
### Environment Variables

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`.
Set the following environment variables to configure the package:

---
- `CCAVENUE_WORKING_KEY`: Your CCAvenue working key
- `CCAVENUE_ACCESS_CODE`: Your CCAvenue access code
- `CCAVENUE_MERCHANT_CODE`: Your CCAvenue merchant code
- `CCAVENUE_REDIRECT_URL`: URL to redirect after successful payment
- `CCAVENUE_CANCEL_URL`: URL to redirect after cancelled payment

## To encrypt the data
### Direct Instantiation

`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.
Pass the configuration parameters directly when creating the CCAvenue object:

```python
encrypt_data = ccavenue.encrypt(form_data)
ccavenue = CCAvenue(
working_key="YOUR_WORKING_KEY",
access_code="YOUR_ACCESS_CODE",
merchant_code="YOUR_MERCHANT_CODE",
redirect_url="YOUR_REDIRECT_URL",
cancel_url="YOUR_CANCEL_URL"
)
```

Pass the `encrypt_data` from the above to the view to render the IFrame.
## API Reference

## Decrypt the data received from the CCAvenue
### `CCAvenue` Class

`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.
#### Methods

```python
decrypted_data = ccavenue.decrypt(form_data)
```
- `encrypt(data: Dict[str, Any]) -> str`: Encrypts the payment data
- `decrypt(data: Dict[str, str]) -> Dict[str, str]`: Decrypts the response data

### `CCavenueFormData` Class

Represents the form data required for CCAvenue payment processing. It includes mandatory and optional fields, and provides methods for data manipulation and validation.

#### Important Fields

- `merchant_id`: CCAvenue merchant ID
- `order_id`: Unique order identifier
- `currency`: Payment currency (default: "INR")
- `amount`: Payment amount
- `redirect_url`: URL for successful payment redirection
- `cancel_url`: URL for cancelled payment redirection

For a complete list of fields, refer to the `CCavenueFormData` class documentation.

## Security Considerations

- The package uses AES encryption with CBC mode for secure communication with CCAvenue.
- Ensure that your working key and other sensitive information are kept secure and not exposed in your codebase.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

# Limitations
## Disclaimer

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.
2. More detailed documentation.
This package is not officially associated with CCAvenue. Use it at your own risk and ensure compliance with CCAvenue's terms of service.
Loading

0 comments on commit 183c516

Please sign in to comment.