Vrushank
Vrushank

Reputation: 89

Django session issue while redirecting to other

I am developing the e-commerce website with Django, So after successful payment through Paytm payment gateway(Integration testing)

I have a session issue in the local server, after redirecting from Paytm test integration portal to a payment success page (local server ), user session logout automatically while I am on the payment success page.

Payment.html file

 {% extends 'shop/base.html' %}
 {% load static %}
 {% block title%}
  Paytm merchant payment page
 {% endblock %}

{% block content %}
{% csrf_token %}
<h1>Redirecting you to the merchant....</h1>
<h1>Please do not refresh your page....</h1>


<form action="https://securegw-stage.paytm.in/order/process"  
  method="post" 
  name="paytm">

 {{ form.as_p }}
{% for key, value in param_dict.items %}
<input type="hidden" name="{{key}}" value="{{value}}">
{% endfor %}
</form>
<script>
    document.paytm.submit()
</script>
 {% endblock %}

paymentstatus.html file

{% extends 'shop/base.html' %}
{% load static %}
{% block title%}Shoppy hub{% endblock %}
{% block content %}
{% csrf_token %}
<div class="container">

<div class="col my-4">

    <h1>Payment status regarding your order Id : {{response.ORDERID}}</h1>
    {% if response.RESPCODE == '01' %}
    <h3>Amount paid:{{response.TXNAMOUNT}} </h3>
    <h3><img style="height:50px;"src="/static/img/success.png" >Your order 
    has been received successfully</h3 >

    <h3>Thank you for your purchase! </h3>
    {% else %}
    <h2> <img style="height:50px;"src="/static/img/fail.jpg" >Your order 
    has been failed</h2 >
    {% endif%}

  </div>

  </div>
   {% endblock %}
   {% block js %}
   <script>


   </script>
   {% endblock %}

Checkout page(user logged in)

Payment page

Payment success page

Session issue might be due to the redirecting from (Django local server) to the Paytm payment portal, But in the payment portal (product price and user name) is being successfully forwarded in integration testing payment page, but after the payment is successfully done and it redirects to the payment success page(local server). At that time user gets logout automatically, although the amount is displayed correctly on the success page.

So guys please help me to maintain the session while redirecting to the other page and then redirecting back to the local server.

settings.py

 INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts.apps.AccountsConfig',
'cart.apps.CartConfig',
'shop.apps.ShopConfig',
'orders.apps.OrdersConfig',
'about.apps.AboutConfig',
'contact.apps.ContactConfig',
'search.apps.SearchConfig',
'offers.apps.OffersConfig',
 ]

 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',
 ]

How can I identify key /value in response headers,Response header(After Logged In):HTTP/1.1 200 OK Date: Thu, 14 May 2020 05:21:02 GMT Server: WSGIServer/0.2 CPython/3.7.3 Content-Type: text/html; charset=utf-8 X-Frame-Options: SAMEORIGIN Content-Length: 39759 Vary: Cookie Set-Cookie: sessionid=frnyglh4tzkp2fgqjv2p3acs2sut5to9; expires=Thu, 28 May 2020 05:21:02 GMT; HttpOnly; Max-Age=1209600; Path=/; SameSite=Lax

After Payment Done:HTTP/1.1 200 OK Date: Thu, 14 May 2020 05:30:06 GMT Server: WSGIServer/0.2 CPython/3.7.3 Content-Type: text/html; charset=utf-8 X-Frame-Options: SAMEORIGIN Vary: Cookie Content-Length: 3652 Set-Cookie: csrftoken=19FoDcypCYyUBy2DHCnxkMn3Zfjn9RufUoqiVKBu4duZxcqNhrHL5MAtqtg9ZNdh; expires=Thu, 13 May 2021 05:30:05 GMT; Max-Age=31449600; Path=/; SameSite=Lax Set-Cookie: sessionid=g2ctxjjt8llz8d7khdub6aa3fvcxxkcy; expires=Thu, 28 May 2020 05:30:05 GMT; HttpOnly; Max-Age=1209600; Path=/; SameSite=Lax

Upvotes: 2

Views: 700

Answers (1)

Yash Kalsariya
Yash Kalsariya

Reputation: 1

When you redirect to success page after successsful payment try to use HttpResponseRedirect('/success/') instead of render('...')

i hope your problem will be solved..

Upvotes: 0

Related Questions