Instamojo | Django REST Framework
A package for Instamojo integration in Django REST Framework
Instamojo | Django REST Framework is a Django packaged app that provides necessary views based in Django REST
Framework. It enables easy integration of Instamojo Payment Gateway with Web/Mobile Application with a RESTful API
based server.
Contributors: WE'RE LOOKING FOR SOMEONE WHO CAN CONTRIBUTE IN DOCS
- Civil Machines Technologies Private Limited: For providing me platform and
funds for research work. This project is hosted currently with
CMTonly. - Himanshu Shankar: Himanshu Shankar has initiated this project and worked on this project to collect useful functions and classes that are being used in various projects.
Installation
- Download and Install via
pip
pip install drf_instamojo
or
Download and Install via easy_install
easy_install drf_instamojo
- Add, if wanted,
drfaddonsinINSTALLED_APPS(This is although not required!)
INSTALLED_APPS = [
...
'drf_instamojo',
...
]
- Also add other dependencies in
INSTALLED_APPS
INSTALLED_APPS = [
...
'drfaddons',
...
]
- Include urls of
drf_instamojoinurls.py
urlpatterns = [
...
path('api/instamojo/', include('drf_instamojo.urls')),
...
]
# or
urlpatterns = [
...
url(r'^api/instamojo/', include('drf_instamojo.urls')),
...
]
- Run migrate command:
python manage.py migrate
MODELS
The application has three models:
InstamojoConfiguration: You need to define your Instamojo configurations in this model. Only one object can haveis_activeset toTruewhich will be used with Instamojo API.PaymentRequest: This will contain all the Instamojo Payment Request that one will create with Instamojo.Payment: This will contain all the responses received from Instamojo API against payment.
VIEWS
The application has following views:
ListAddPaymentRequestView: All payment request should be made on this view. Requires a logged in user. It'll provide user with required data, includinglongurlthat will be used to make payment.ListAddPaymentView: All response data should be posted on this view. Doesn't requires a logged in user.
URLS
request/: All payment request to be made via this URL.payment/: All payment reponses to be posted on this URL.
Quickstart Guide
- Complete
Installation Steps(mentioned above) - Create a configuration via
Django AdmininInstamojo Configuration - Set
is_activetoTrue - Note: Use sandbox mode credential at first
How to integrate with apps
- Use
serializersto integrate with custom apps.
Creating Payment Request
Example
- Create a view:
PaymentView - Use
PaymentRequestSerializerto create a payment request. - Check example code in
serializers.py:
# Initialize serializer with proper data
prs = PaymentRequestSerializer(data={'amount': 120.00, 'purpose': 'Test', 'send_sms': False,
'redirect_url': 'http://127.0.0.1/api/test/'})
# Check if data is valid
prs.is_valid(raise_exception=True)
instance = prs.save(created_by=user)
- Save
instanceas foreign key in app pointing to bill for which the payment request is made. - Return
longurlto client for making payment
Problem with created_by requirement in .save() of serializer
- If app doesn't require user to login, use following logic:
- Inside payment view, take following data from user:
- Name of the customer
- Mobile Number of the customer
mobile: 9987987345 - Email of the customer
email: test@abc.com
- Use following code to create a logic around getting an existing or creating a new user:
- Inside payment view, take following data from user:
from django.contrib.auth import get_user_model
user_model = get_user_model()
try:
user = user_model.objects.get(email=email)
except user_model.DoesNotExist:
try:
user = user_model.objects.get(mobile=mobile)
except user_model.DoesNotExist:
# Now you're dead sure that user does not exists.
user = user_model.objects.create(name=name, mobile=mobile, email=email, password="RANDOM_PASSWORD")
- Otherwise, simply use
user = request.useras user while calling.save()on serializer. - Bonus Pointer: Check out Django REST Framework - User
Payment Completion
- Use
payment_donesignal - Create
signalspython directory with__init__.py, handlers.pyin app - In
handlers.py, create a function for handlingpayment_donesignal
from django.dispatch import receiver
from drf_instamojo.models import PaymentRequest
from drf_instamojo.signals import payment_done
@receiver(signal=payment_done, sender=PaymentRequest)
def payment_done_handler(instance: PaymentRequest, sender, *args, **kwargs):
...
# Payment completed
# bill.paid()
# item.dispatch()
...
Metadata
Release files for drf-instamojo 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| drf_instamojo-0.0.1.tar.gz | 13.5 kB | Without provenance | Details for drf_instamojo-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drf_instamojo-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for drf_instamojo-0.0.1-py3-none-any.whl |
Total release size: 41.0 kB
Release files / drf_instamojo-0.0.1.tar.gz
| Download URL | drf_instamojo-0.0.1.tar.gz |
|---|---|
| Size | 13.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a50f683e69a98527ab09c650c3dd10c9a92e2e134d96d5573fc530577df5681
|
|
BLAKE2b-256 checksum How to use checksums |
bb5bccd54e15a95367026880e368fa41d642e9b27d0a94ebe330e09e51702995
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
|
Release files / drf_instamojo-0.0.1-py3-none-any.whl
| Download URL | drf_instamojo-0.0.1-py3-none-any.whl |
|---|---|
| Size | 27.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f246f4ea50cddbc060b7c3433496dd01d49d145cb7142868f15bf6d8ab462249
|
|
BLAKE2b-256 checksum How to use checksums |
ea53604812dd8e031c9b5810bfe8c839d88459d4a296a89e543ac2257ac121da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
|
Security for drf-instamojo 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.