PayTM Integration based on Django REST Framework
GPL-3.0 License
A package for PayTM integration in Django REST Framework
PayTM | Django REST Framework
is a Django packaged app that provides necessary views
based in Django REST Framework.
It enables easy integration of PayTM Payment Gateway with Web/Mobile Application with a RESTful API based server.
Contributors: WE'RE LOOKING FOR SOMEONE WHO CAN CONTRIBUTE IN DOCS
CMT
only.pip
pip install drf_paytm
or
Download and Install via easy_install
easy_install drf_paytm
drfaddons
in INSTALLED_APPS
(This is although not required!)INSTALLED_APPS = [
...
'drf_paytm',
...
]
INSTALLED_APPS
INSTALLED_APPS = [
...
'drfaddons',
...
]
drf_paytm
in urls.py
urlpatterns = [
...
path('api/paytm/', include('drf_paytm.urls')),
...
]
# or
urlpatterns = [
...
url(r'^api/paytm/', include('drf_paytm.urls')),
...
]
python manage.py migrate
json
data to post on request/
view: {"oid": "ORDER_ID", "amount": "200", "callback_url": "FRONT_END APP URL"}
callback_url
: FrontEnd URL to open when payment is successful. Must not have any queryset as ?oid=ORDER_ID
isrequest/
and parse response to prepare a HTML form as per code shown below.<input>
for empty and null
fields from json response of request/
API.CALLBACK_URL
in HTML from paytm_callback_url
of JSON.response/
view which will verify payment.http://callback_url?oid=ORDER_ID
.order/ORDER_ID/
API to get is_completed
status. If it's false
, check last_payment_status
.Note: In case of critical failure, server's JSON response is shown.
Sample HTML Code to be generated by FrontEnd App(from PayTM)
<html>
<head>
<title>Merchant Check Out Page</title>
</head>
<body>
<center><h1>Please do not refresh this page...</h1></center>
<form method="post" action="https://securegw-stage.paytm.in/theia/processTransaction" name="f1">
<table border="1">
<tbody>
<input type="hidden" name="MID" value="rxazcv89315285244163">
<input type="hidden" name="WEBSITE" value="WEBSTAGING">
<input type="hidden" name="ORDER_ID" value="order1">
<input type="hidden" name="CUST_ID" value="cust123">
<input type="hidden" name="MOBILE_NO" value="7777777777">
<input type="hidden" name="EMAIL" value="[email protected]">
<input type="hidden" name="INDUSTRY_TYPE_ID" value="Retail">
<input type="hidden" name="CHANNEL_ID" value="WEB">
<input type="hidden" name="TXN_AMOUNT" value="100.12">
<input type="hidden" name="CALLBACK_URL" value="https://Merchant_Response_URL>">
<input type="hidden" name="CHECKSUMHASH" value="ZWdMJOr1yGiFh1nns2U8sDC9VzgUDHVnQpG
pVnHyrrPb6bthwro1Z8AREUKdUR/K46x3XvFs6Xv7EnoSOLZT29qbZJKXXvyEuEWQIJGkw=">
</tbody>
</table>
<script type="text/javascript">
document.f1.submit();
</script>
</form>
</body>
</html>
The application has three models:
PayTMConfiguration
: You need to define your PayTM configurations in this model. Only one object can haveis_active
set to True
which will be used with PayTM API.TransactionRequest
: This will contain all the PayTM Transaction Request that one will create with PayTM.TransactionResponse
: This will contain all the responses received from PayTM API against transaction.The application has following views:
ListAddTransactionRequestView
: All payment request should be made on this view. Requires a logged in user.checksum hash
that will be used with PayTM API.AddTransactionResponseView
: Response from PayTM is posted on this view. URL for this view should go asCALLBACK_URL
. This view then redirects user to FrontEnd app with OID
as queryset parameter.PayNowTransaction
: This view is for testing w/o a frontend client. It will open PayTM payment page.request/
: All payment request to be made via this URL.response/
: All response from PayTM is posted on this URL.order/OID/
: Retrieve specific payment request data.now/
: For immediate testing of API, open this url.Installation Steps
(mentioned above)Django Admin
in PayTM Configuration
.base_url
of your Backend Server.is_active
to True
/api/paytm/now/
endpointPayTM Testing Credential
:Mobile: 7777777777
OTP: 489871
Password: Paytm12345