django-rest-cryptomus


Namedjango-rest-cryptomus JSON
Version 0.2.7 PyPI version JSON
download
home_pagehttps://github.com/rz-k/django_cryptomus
SummaryA Django app for integrating with Cryptomus payment gateway.
upload_time2024-06-13 13:37:33
maintainerNone
docs_urlNone
authorreza karampour
requires_pythonNone
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django Cryptomus

Django Cryptomus is a Django package designed to enhance web applications with robust payment processing capabilities using Cryptomus services. Cryptomus provides a secure and dynamic platform for managing payment transactions through various cryptocurrencies.

## About Cryptomus

Cryptomus is a platform that facilitates secure and efficient cryptocurrency payment processing solutions for businesses and developers. It allows users to create invoices, handle payment transactions, and customize payment forms and callbacks according to specific business needs.

With Django Cryptomus, developers can integrate Cryptomus functionalities seamlessly into their Django applications. This package offers dynamic configuration settings, enabling developers to tailor security measures and payment processes based on their project requirements.


## Features

- **Advanced Security Capabilities**: This package provides advanced features such as data encryption, access control, and detection of security threats.
- **Dynamic Configuration Settings**: All settings in this package are dynamically configurable via an admin panel.
- **Ease of Use**: Designed to be highly intuitive, making it easy for developers familiar with Django to integrate and customize security features.

## Installation

To install via pip, simply run:

```bash
pip install django-rest-cryptomus
```

Then, add it to the `INSTALLED_APPS` list in your project settings:

```python
# settings.py

INSTALLED_APPS = [
    ...
    'django_cryptomus',
    'rest_framework',
]
```

## Configuration

Add the following required settings to your Django settings file (`settings.py`):

```python
# Cryptomus API configuration
CRYPTOMUS_API_KEY = 'your_api_key'
CRYPTOMUS_MERCHANT = 'your_merchant'
CRYPTOMUS_BASE_URL = 'your_base_url'  # For local testing, see below
```

### Local Testing

If you want to test the integration locally, you need to expose your local server to the internet. You can use tools like ngrok or pinggy to achieve this.

#### Using ngrok

1. Install ngrok from [ngrok.com](https://ngrok.com/).
2. Run the following command to start ngrok and expose your local server:

    ```sh
    ngrok http 8000
    ```

3. Use the URL provided by ngrok (e.g., `https://your-subdomain.ngrok.io`) as your `CRYPTOMUS_BASE_URL`.

#### Using pinggy

1. Use the following command to start pinggy and expose your local server:

    ```sh
    ssh -p 443 -R0:localhost:8000 -L4300:localhost:4300 qr@a.pinggy.io
    ```

2. Use the URL provided by pinggy as your `CRYPTOMUS_BASE_URL`.

## Usage

Include the `django_cryptomus` URLs in your project's `urls.py`:

```python
from django.urls import path, include

urlpatterns = [
    ...
    path('payment/', include("django_cryptomus.urls", namespace="django_cryptomus")),
]
```


## Custom Form Integration
You have the flexibility to create your own custom HTML form and use it instead of the default form provided by Django Cryptomus. To integrate your custom form, follow these steps:

1. Create your custom HTML form with the desired fields and styling. You can name this file `custom_payment_form.html`.

2. In your Django project, specify the path to your custom form in the settings:

``` python 
#settings.py

CRYPTOMUS_CUSTOM_PAYMENT_FORM = 'templates_path/custom_payment_form.html'
```

## JSON Example for Payment Data
In addition to using an HTML form, you can also provide payment data in JSON format. This can be useful for API integrations or other programmatic uses. Here is an example of the required fields in JSON format:

``` json
{
    "amount": "100.00",
    "currency": "USD",
    "order_id": "123456",
    "additional_data": {
        "network": "BTC",
        "is_payment_multiple": true,
        "lifetime": 3600,
        "to_currency": "BTC",
        "subtract": 0,
        "accuracy_payment_percent": 0,
        "additional_data": "Additional information for merchant",
        "currencies": ["BTC", "ETH", "LTC"],
        "except_currencies": [],
        "course_source": "Binance",
        "from_referral_code": "your_referral_code",
        "discount_percent": 5,
        "is_refresh": false
    }
}
```
To use JSON instead of a form, simply send a POST request to the appropriate endpoint with the JSON data. This approach allows for more flexibility and can easily be integrated into various systems and applications.

## Additional Data

The `additional_data` field in JSON is used to send additional data and advanced settings in the payment transaction request. This field is optional, meaning you can include it or omit it based on your requirements.

To get detailed information about each parameter within `additional_data` and how to use them, please refer to the official Cryptomus documentation:

- [Cryptomus Documentation on Creating Invoice](https://doc.cryptomus.com/payments/creating-invoice)

You can find comprehensive details about each parameter in the `additional_data` field, enabling you to utilize them effectively for your needs.

## Customizing Cryptomus Callback View and Using CryptoMusPayment Model

If you want to customize the behavior of the callback view provided by Django Cryptomus and use the `CryptoMusPayment` model to manage payment records, follow these steps:

1. Subclass the `CryptomusCallbackView` class and import the `CryptoMusPayment` model into your Django project:

```python
# views.py

from rest_framework import status
from rest_framework.response import Response
from django_cryptomus.views import CryptomusCallbackView
from django_cryptomus.models import CryptoMusPayment

class CustomCryptomusCallbackView(CryptomusCallbackView):
    def post(self, request, *args, **kwargs):
        data = request.data
        if data['status'] == 'paid':
            cryptomus_payment = CryptoMusPayment.objects.filter(order_id=data['order_id'])
            
            cryptomus_payment.update(
                payment_amount_usd=data['payment_amount_usd'],
                payer_currency=data['payer_currency'],
                from_address=data['from'],
                status=data['status'],
                txid=data['txid'],
                payment_data=data
            )
            
            return Response({'message': 'Payment status updated successfully.'}, status=status.HTTP_200_OK)
        else:
            return Response({'error': 'Invalid payment status.'}, status=status.HTTP_400_BAD_REQUEST)
```

Specify the path to your custom callback view class in the settings:
```
# settings.py

CRYPTOMUS_CALLBACK_VIEW_CLASS = 'yourapp.views.CustomCryptomusCallbackView'
```

## Customizing Success View

To customize the success page of Cryptomus payment, you can create a custom view class and specify its path using the `CRYPTOMUS_SUCCESS_VIEW_CLASS` variable in your Django project settings.

### Example Custom Success View

```python
# views.py

from django_cryptomus.views import SuccessCryptomusView
from django.http import HttpResponse
from django.shortcuts import render

class CustomSuccessCryptomusView(SuccessCryptomusView):

    def get(self, request):
        """
        Handle GET requests to render the success page.

        Renders a success page template specified in
```


Setting Custom Success View
To set the custom success view, you need to specify the path to your custom view class in the settings.py file of your Django project:

```
# settings.py

CRYPTOMUS_SUCCESS_VIEW_CLASS = 'yourapp.views.CustomCryptomusSuccessView'
```

## Customizing Success Template

To customize the success page template for Cryptomus payment, you can create a custom HTML template and specify its path using the `CRYPTOMUS_PAYMENT_SUCCESS_HTML` variable in your Django project settings.

### Example Custom Success Template

```html
<!-- success_page.html -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Payment Success</title>
    <!-- Add your custom CSS stylesheets or scripts here -->
</head>
<body>
    <div class="container">
        <h1>Payment Successful!</h1>
        <p>Thank you for your payment.</p>
        <!-- Add additional content or dynamic data here -->
    </div>
</body>
</html>
```
Setting Custom Success Template
To set the custom success template, you need to specify the path to your custom HTML template in the settings.py file of your Django proje

```
# settings.py

CRYPTOMUS_PAYMENT_SUCCESS_HTML = 'cryptopay/success_page.html'
```


Then, you can utilize the dynamic configuration settings provided by this package to tailor all aspects of your site's security.
## Contributing

We welcome contributions and feedback from the community. To report issues, make suggestions, or submit pull requests, please visit our [GitHub repository](https://github.com/rz-k/django_cryptomus).

## License

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rz-k/django_cryptomus",
    "name": "django-rest-cryptomus",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "reza karampour",
    "author_email": "adamak.tng@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2a/cd/b337811e1ff12327e6fb18593f63fef341698103aa1de4ad81db8faecd45/django-rest-cryptomus-0.2.7.tar.gz",
    "platform": null,
    "description": "# Django Cryptomus\n\nDjango Cryptomus is a Django package designed to enhance web applications with robust payment processing capabilities using Cryptomus services. Cryptomus provides a secure and dynamic platform for managing payment transactions through various cryptocurrencies.\n\n## About Cryptomus\n\nCryptomus is a platform that facilitates secure and efficient cryptocurrency payment processing solutions for businesses and developers. It allows users to create invoices, handle payment transactions, and customize payment forms and callbacks according to specific business needs.\n\nWith Django Cryptomus, developers can integrate Cryptomus functionalities seamlessly into their Django applications. This package offers dynamic configuration settings, enabling developers to tailor security measures and payment processes based on their project requirements.\n\n\n## Features\n\n- **Advanced Security Capabilities**: This package provides advanced features such as data encryption, access control, and detection of security threats.\n- **Dynamic Configuration Settings**: All settings in this package are dynamically configurable via an admin panel.\n- **Ease of Use**: Designed to be highly intuitive, making it easy for developers familiar with Django to integrate and customize security features.\n\n## Installation\n\nTo install via pip, simply run:\n\n```bash\npip install django-rest-cryptomus\n```\n\nThen, add it to the `INSTALLED_APPS` list in your project settings:\n\n```python\n# settings.py\n\nINSTALLED_APPS = [\n    ...\n    'django_cryptomus',\n    'rest_framework',\n]\n```\n\n## Configuration\n\nAdd the following required settings to your Django settings file (`settings.py`):\n\n```python\n# Cryptomus API configuration\nCRYPTOMUS_API_KEY = 'your_api_key'\nCRYPTOMUS_MERCHANT = 'your_merchant'\nCRYPTOMUS_BASE_URL = 'your_base_url'  # For local testing, see below\n```\n\n### Local Testing\n\nIf you want to test the integration locally, you need to expose your local server to the internet. You can use tools like ngrok or pinggy to achieve this.\n\n#### Using ngrok\n\n1. Install ngrok from [ngrok.com](https://ngrok.com/).\n2. Run the following command to start ngrok and expose your local server:\n\n    ```sh\n    ngrok http 8000\n    ```\n\n3. Use the URL provided by ngrok (e.g., `https://your-subdomain.ngrok.io`) as your `CRYPTOMUS_BASE_URL`.\n\n#### Using pinggy\n\n1. Use the following command to start pinggy and expose your local server:\n\n    ```sh\n    ssh -p 443 -R0:localhost:8000 -L4300:localhost:4300 qr@a.pinggy.io\n    ```\n\n2. Use the URL provided by pinggy as your `CRYPTOMUS_BASE_URL`.\n\n## Usage\n\nInclude the `django_cryptomus` URLs in your project's `urls.py`:\n\n```python\nfrom django.urls import path, include\n\nurlpatterns = [\n    ...\n    path('payment/', include(\"django_cryptomus.urls\", namespace=\"django_cryptomus\")),\n]\n```\n\n\n## Custom Form Integration\nYou have the flexibility to create your own custom HTML form and use it instead of the default form provided by Django Cryptomus. To integrate your custom form, follow these steps:\n\n1. Create your custom HTML form with the desired fields and styling. You can name this file `custom_payment_form.html`.\n\n2. In your Django project, specify the path to your custom form in the settings:\n\n``` python \n#settings.py\n\nCRYPTOMUS_CUSTOM_PAYMENT_FORM = 'templates_path/custom_payment_form.html'\n```\n\n## JSON Example for Payment Data\nIn addition to using an HTML form, you can also provide payment data in JSON format. This can be useful for API integrations or other programmatic uses. Here is an example of the required fields in JSON format:\n\n``` json\n{\n    \"amount\": \"100.00\",\n    \"currency\": \"USD\",\n    \"order_id\": \"123456\",\n    \"additional_data\": {\n        \"network\": \"BTC\",\n        \"is_payment_multiple\": true,\n        \"lifetime\": 3600,\n        \"to_currency\": \"BTC\",\n        \"subtract\": 0,\n        \"accuracy_payment_percent\": 0,\n        \"additional_data\": \"Additional information for merchant\",\n        \"currencies\": [\"BTC\", \"ETH\", \"LTC\"],\n        \"except_currencies\": [],\n        \"course_source\": \"Binance\",\n        \"from_referral_code\": \"your_referral_code\",\n        \"discount_percent\": 5,\n        \"is_refresh\": false\n    }\n}\n```\nTo use JSON instead of a form, simply send a POST request to the appropriate endpoint with the JSON data. This approach allows for more flexibility and can easily be integrated into various systems and applications.\n\n## Additional Data\n\nThe `additional_data` field in JSON is used to send additional data and advanced settings in the payment transaction request. This field is optional, meaning you can include it or omit it based on your requirements.\n\nTo get detailed information about each parameter within `additional_data` and how to use them, please refer to the official Cryptomus documentation:\n\n- [Cryptomus Documentation on Creating Invoice](https://doc.cryptomus.com/payments/creating-invoice)\n\nYou can find comprehensive details about each parameter in the `additional_data` field, enabling you to utilize them effectively for your needs.\n\n## Customizing Cryptomus Callback View and Using CryptoMusPayment Model\n\nIf you want to customize the behavior of the callback view provided by Django Cryptomus and use the `CryptoMusPayment` model to manage payment records, follow these steps:\n\n1. Subclass the `CryptomusCallbackView` class and import the `CryptoMusPayment` model into your Django project:\n\n```python\n# views.py\n\nfrom rest_framework import status\nfrom rest_framework.response import Response\nfrom django_cryptomus.views import CryptomusCallbackView\nfrom django_cryptomus.models import CryptoMusPayment\n\nclass CustomCryptomusCallbackView(CryptomusCallbackView):\n    def post(self, request, *args, **kwargs):\n        data = request.data\n        if data['status'] == 'paid':\n            cryptomus_payment = CryptoMusPayment.objects.filter(order_id=data['order_id'])\n            \n            cryptomus_payment.update(\n                payment_amount_usd=data['payment_amount_usd'],\n                payer_currency=data['payer_currency'],\n                from_address=data['from'],\n                status=data['status'],\n                txid=data['txid'],\n                payment_data=data\n            )\n            \n            return Response({'message': 'Payment status updated successfully.'}, status=status.HTTP_200_OK)\n        else:\n            return Response({'error': 'Invalid payment status.'}, status=status.HTTP_400_BAD_REQUEST)\n```\n\nSpecify the path to your custom callback view class in the settings:\n```\n# settings.py\n\nCRYPTOMUS_CALLBACK_VIEW_CLASS = 'yourapp.views.CustomCryptomusCallbackView'\n```\n\n## Customizing Success View\n\nTo customize the success page of Cryptomus payment, you can create a custom view class and specify its path using the `CRYPTOMUS_SUCCESS_VIEW_CLASS` variable in your Django project settings.\n\n### Example Custom Success View\n\n```python\n# views.py\n\nfrom django_cryptomus.views import SuccessCryptomusView\nfrom django.http import HttpResponse\nfrom django.shortcuts import render\n\nclass CustomSuccessCryptomusView(SuccessCryptomusView):\n\n    def get(self, request):\n        \"\"\"\n        Handle GET requests to render the success page.\n\n        Renders a success page template specified in\n```\n\n\nSetting Custom Success View\nTo set the custom success view, you need to specify the path to your custom view class in the settings.py file of your Django project:\n\n```\n# settings.py\n\nCRYPTOMUS_SUCCESS_VIEW_CLASS = 'yourapp.views.CustomCryptomusSuccessView'\n```\n\n## Customizing Success Template\n\nTo customize the success page template for Cryptomus payment, you can create a custom HTML template and specify its path using the `CRYPTOMUS_PAYMENT_SUCCESS_HTML` variable in your Django project settings.\n\n### Example Custom Success Template\n\n```html\n<!-- success_page.html -->\n\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Payment Success</title>\n    <!-- Add your custom CSS stylesheets or scripts here -->\n</head>\n<body>\n    <div class=\"container\">\n        <h1>Payment Successful!</h1>\n        <p>Thank you for your payment.</p>\n        <!-- Add additional content or dynamic data here -->\n    </div>\n</body>\n</html>\n```\nSetting Custom Success Template\nTo set the custom success template, you need to specify the path to your custom HTML template in the settings.py file of your Django proje\n\n```\n# settings.py\n\nCRYPTOMUS_PAYMENT_SUCCESS_HTML = 'cryptopay/success_page.html'\n```\n\n\nThen, you can utilize the dynamic configuration settings provided by this package to tailor all aspects of your site's security.\n## Contributing\n\nWe welcome contributions and feedback from the community. To report issues, make suggestions, or submit pull requests, please visit our [GitHub repository](https://github.com/rz-k/django_cryptomus).\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A Django app for integrating with Cryptomus payment gateway.",
    "version": "0.2.7",
    "project_urls": {
        "Homepage": "https://github.com/rz-k/django_cryptomus"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a5d12a89f7acf970a116a13da84212ab84c096c5362d94c11359554b17a60771",
                "md5": "5a010331fa772ccc4059e946851c34da",
                "sha256": "f895c21f56ffa7146b71201c61b9b076aebdf41cede5743cb913f92d3e6ad740"
            },
            "downloads": -1,
            "filename": "django_rest_cryptomus-0.2.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5a010331fa772ccc4059e946851c34da",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11740,
            "upload_time": "2024-06-13T13:37:18",
            "upload_time_iso_8601": "2024-06-13T13:37:18.239119Z",
            "url": "https://files.pythonhosted.org/packages/a5/d1/2a89f7acf970a116a13da84212ab84c096c5362d94c11359554b17a60771/django_rest_cryptomus-0.2.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2acdb337811e1ff12327e6fb18593f63fef341698103aa1de4ad81db8faecd45",
                "md5": "9c9b60e6d370870060a9bdd41d110362",
                "sha256": "bb14d0f555676910524d37f6be836a4cbce6e2c68c0ee571d95d51b840539307"
            },
            "downloads": -1,
            "filename": "django-rest-cryptomus-0.2.7.tar.gz",
            "has_sig": false,
            "md5_digest": "9c9b60e6d370870060a9bdd41d110362",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12524,
            "upload_time": "2024-06-13T13:37:33",
            "upload_time_iso_8601": "2024-06-13T13:37:33.217090Z",
            "url": "https://files.pythonhosted.org/packages/2a/cd/b337811e1ff12327e6fb18593f63fef341698103aa1de4ad81db8faecd45/django-rest-cryptomus-0.2.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-13 13:37:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rz-k",
    "github_project": "django_cryptomus",
    "github_not_found": true,
    "lcname": "django-rest-cryptomus"
}
        
Elapsed time: 0.70624s