Giter Site home page Giter Site logo

raj457036 / paytm-api-for-django Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 2.0 534 KB

High performance Paytm Gateway api for Django. Just plug and play app.

License: MIT License

Python 93.30% HTML 6.70%
django paytm-payments paytm-merchant paytm-api paytm-dajngo paytm-gateway-django paytm-gateway-python paytm-app python3 django2

paytm-api-for-django's Introduction

Paytm-api-for-django

High performance Paytm Gateway api for Django. Just plug and play app. good luck.

Requirements

Python 3+ Django 2+

Installation

Step 1 : clone this repo and paste it in your project directory Step 2 : open settings.py file of your project and add paytm to INSTALLED_APPS paste the below settings

# settings.py

INSTALLED_APPS = [
    .
    .
    .
    'paytm',
]

# other settings...

PAYTM_STAGING_URL = 'https://securegw-stage.paytm.in'
PAYTM_PRODUCTION_URL = 'https://securegw.paytm.in'

HOSTNAME = '127.0.0.1:8000'

if DEBUG:
    PAYTM_URL = PAYTM_STAGING_URL
else:
    PAYTM_URL = PAYTM_PRODUCTION_URL

PAYTM_MERCHANT_KEY = 'XXXXXXXXXXXX' # replace with original merchangt key
PAYTM_GATEWAY_SETTINGS = {
    'MID':'XXXXXXXXXXXXXXXXXXXX', # replace with original merchangt id or MID
    'INDUSTRY_TYPE_ID':'Retail',
    'WEBSITE':'APPSTAGING', # WEBSTAGING for websites -->> change this with production variables
    'CHANNEL_ID':'WAP', #WEB for websites
    'CALLBACK_URL':f'http://{HOSTNAME}/paytm/payment_response/', } # https:// if you are on production server

PAYTM_SAVE_SUCCESS_TRANSECTIONS_ONLY = True  # if this is true paytm will save only successful transection else it willsave all transections

Step 3 : Run migrations and migrate after that Replace "XXXXX..." above with respective merchant key and MID

Step 4 : open urls.py and add

#urls.py

urlpatterns = [
  #other urls ...
  path('paytm/', include('paytm.urls'))
]

Step 5 : Setup complete and you are good to go

Test your api

  • Fill the details and test your api

URLS

### To request for payment
url: https://{HOST}/paytm/payment_response/ 
method: POST
minimum requirements = ['ORDER_ID', 'TXN_AMOUNT', 'CUST_ID'] send these fields
NOTE: This api is also optimized for PAYMENT_MODE_ONLY field for more info go through paytm gateway docs below


### To check status of transection
url: https://{HOST}/paytm/status/
method: POST
minimum requirements = ['ORDER_ID'] send these fields

for all the available fields go through
PAYTM Gateway Documentation
https://business.paytm.com/developers-api/integration/payment-gateway/documentation

NOTES

  • Every api need the user to be logged in So if you dont want it to check for logged in just remove LoginRequiredMixin from views.py in paytm folder

  • All the response are in json format

  • Apis are checked and highly optimized for performance

  • This package also include Refund API But Paytm suggest not to use apis for this use PAYTM DASHBOARD

  • you will need to install pycrypto for paytm to work.

    pip install pycrypto

    if above give error, i included pre-compiled wheel file

    pip install pycrypto-2.6.1-cp36-cp36m-win_amd64.whl

    this will solve the problem for windows users too.

Any problem? raise an issue

LICENCE

  • MIT

paytm-api-for-django's People

Contributors

raj457036 avatar rajsingh457036 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

paytm-api-for-django's Issues

Incorrect AES key length (12 bytes)

Cannot fix this ValueError in utils.py

File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\django\views\generic\base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\django\contrib\auth\mixins.py", line 52, in dispatch
return super().dispatch(request, *args, **kwargs)
File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\django\views\generic\base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\django\views\generic\base.py", line 158, in get
context = self.get_context_data(**kwargs)
File "C:\Users\yashk\Dev\ecom\paytm\views.py", line 53, in get_context_data
'CHECKSUMHASH': generate_checksum(ctx['paytm_req_data'], settings.PAYTM_MERCHANT_KEY)
File "C:\Users\yashk\Dev\ecom\paytm\utils.py", line 23, in generate_checksum
return encode(hash_string, IV, merchant_key)
File "C:\Users\yashk\Dev\ecom\paytm\utils.py", line 108, in encode
c = AES.new(key.encode('utf-8'), AES.MODE_CBC, iv.encode('utf-8'))
File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\Crypto\Cipher\AES.py", line 232, in new
return create_cipher(sys.modules[name], key, mode, *args, **kwargs)
File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\Crypto\Cipher_init
.py", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\Crypto\Cipher_mode_cbc.py", line 274, in _create_cbc_cipher
cipher_state = factory._create_base_cipher(kwargs)
File "C:\Users\yashk\Dev\ecom\env\lib\site-packages\Crypto\Cipher\AES.py", line 93, in _create_base_cipher
raise ValueError("Incorrect AES key length (%d bytes)" % len(key))
ValueError: Incorrect AES key length (12 bytes)

Key Error at csfrmiddlewaretoken

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/paytm/

Django Version: 2.1.15
Python Version: 3.8.2
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_registration',
'django_filters',
'rest_framework',
'phone_verify',
'crispy_forms',
'carts',
'orders',
'products',
'paytm',
'marketing']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback:

File "C:\Users\yashk\Dev\prescart\env\lib\site-packages\django\core\handlers\exception.py" in inner
34. response = get_response(request)

File "C:\Users\yashk\Dev\prescart\env\lib\site-packages\django\core\handlers\base.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)

File "C:\Users\yashk\Dev\prescart\env\lib\site-packages\django\core\handlers\base.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\yashk\Dev\prescart\env\lib\site-packages\django\views\generic\base.py" in view
68. return self.dispatch(request, *args, **kwargs)

File "C:\Users\yashk\Dev\prescart\env\lib\site-packages\django\utils\decorators.py" in _wrapper
45. return bound_method(*args, **kwargs)

File "C:\Users\yashk\Dev\prescart\env\lib\site-packages\django\views\decorators\csrf.py" in wrapped_view
54. return view_func(*args, **kwargs)

File "C:\Users\yashk\Dev\prescart\env\lib\site-packages\django\contrib\auth\mixins.py" in dispatch
52. return super().dispatch(request, *args, **kwargs)

File "C:\Users\yashk\Dev\prescart\env\lib\site-packages\django\views\generic\base.py" in dispatch
88. return handler(request, *args, **kwargs)

File "C:\Users\yashk\Dev\prescart\env\lib\site-packages\django\views\generic\base.py" in get
149. context = self.get_context_data(**kwargs)

File "C:\Users\yashk\Dev\prescart\paytm\views.py" in get_context_data
49. ctx['paytm_req_data'] = self.get_payment_data()

File "C:\Users\yashk\Dev\prescart\paytm\views.py" in get_payment_data
42. req_data.pop('csrfmiddlewaretoken')

Exception Type: KeyError at /paytm/
Exception Value: 'csrfmiddlewaretoken'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.