3

I have implemented according to docs https://developer.payumoney.com/redirect/

But i am getting error checksum failed, I am using sandbox test url enter image description here

view.py

import hashlib
from random import randint

from django.shortcuts import render


def Home(request):
    MERCHANT_KEY = "KeytCX7l"
    key = "keytCX7l"
    SALT = "salt2TuHze"
    PAYU_BASE_URL = "https://sandboxsecure.payu.in/_payment"
    posted = {}
    # Merchant Key and Salt provided y the PayU.
    for i in request.POST:
        posted[i] = request.POST[i]
    hash_object = hashlib.sha256(str(randint(0,20)).encode('utf-8'))
    txnid = hash_object.hexdigest()[0:20]
    posted['txnid'] = "b17ef6d19c7a5b1ee83b"
    posted['amount'] =  10.00
    posted['firstname'] = "Ravi"
    posted['email'] = "ravibhushan29@gmail.com"
    # posted['phone'] = "70007240543"
    posted["productinfo"] = "new product"
    hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5"
    posted['key'] = key

    hash_string = ''
    hashVarsSeq = hashSequence.split('|')
    for i in hashVarsSeq:
        try:
            hash_string += str(posted[i])
        except Exception:
            hash_string += ''
        hash_string += '|'

    hash_string += SALT
    hashh = hashlib.sha512(hash_string.encode('utf-8')).hexdigest().lower()
    return render(request, 'payment.html', {"posted": posted, "hash": hashh,
                                                    "MERCHANT_KEY": MERCHANT_KEY,
                                                    "txnid": txnid,
                                                    "hash_string": hash_string,
                                                    "action": PAYU_BASE_URL})

I have passing value according to docs of payumoney, I have checked hash and hash_sequence as same as:

hashSequence = key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||salt.

payment.html

<html>
  <head onload="submitPayuForm()">
  <script type="text/javascript">
    var hash = "{{ hashh }}";
    function submitPayuForm() {
      if(hash =='') {
        return;
      }
      var payuForm = document.forms.payuForm;
      payuForm.submit();
    }
  </script>
  </head>
  <body>
    <h2>PayU Form</h2>
    <br/>
    {% if error %}

      <span style="color:red">Please fill all mandatory fields.</span>
      <br/>
      <br/>
      {% endif %}

      <form action={{ action }} method="post" name="payuForm">{% csrf_token %}
      <input type="hidden" name="key" value="{{ MERCHANT_KEY }}" />
      <input type="hidden" name="hash_string" value="{{ hash_string }}" />
      <input type="hidden" name="hash" value="{{ hash }}"/>
       <input type="hidden" name="posted" value="{{ posted }}"/>
      <input type="hidden" name="txnid" value="{{ txnid }}" />
      <table>
        <tr>
          <td><b>Mandatory Parameters</b></td>
        </tr>
        <tr>
         <td>Amount: </td>
          <td><input name="amount" value="{{ posted.amount }}" /></td>
          <td>First Name: </td>
          <td><input name="firstname" id="firstname" value="{{ posted.firstname|default:'' }}" /></td>
        </tr>
        <tr>
          <td>Email: </td>
          <td><input name="email" id="email" value="{{ posted.email|default:'' }}" /></td>
        </tr>
        <tr>
          <td>Product Info: </td>
          <td colspan="3"><textarea name="productinfo">{{ posted.productinfo|default:'' }}</textarea></td>
        </tr>
        <tr>
          <td>Success URI: </td>
          <td colspan="3"><input name="surl" value="http://127.0.0.1:8000/Success/" size="64" /></td>
        </tr>
        <tr>
          <td>Failure URI: </td>
          <td colspan="3"><input name="furl" value="http://127.0.0.1:8000/Failure/" size="64" /></td>
        </tr>

        <tr>
          <td colspan="3"><input type="hidden" name="service_provider" value="payu_paisa" size="64" /></td>
        </tr>
             <tr>

     <td colspan="4"><input type="submit" value="Submit" /></td>

        </tr>
      </table>
    </form>
  </body>
</html>

please help to find where i have made mistake

Ravi Bhushan
  • 942
  • 2
  • 11
  • 19

2 Answers2

0

For payu test use this credentials

def Home(request):
    key = "gtKFFx"
    SALT = "eCwWELxi"
    PAYU_BASE_URL = "https://test.payu.in/_payment'"

hope it helps

for more details refer this

rahul.m
  • 5,572
  • 3
  • 23
  • 50
  • 1
    i have posted dummy MERCHANT_KEY, and key and salt, according to doc test url https://test.payu.in/_payment is changed to https://sandboxsecure.payu.in/_payment – Ravi Bhushan Apr 04 '19 at 11:35
  • user **gtKFFx** as MERCHANT_KEY for payu test – rahul.m Apr 04 '19 at 11:37
  • No , now after change Merchant key and salt , i am getting error Sorry, Some Problem Occurred – Ravi Bhushan Apr 04 '19 at 12:39
  • did any one get the solution still i am getting 'Sorry, Some Problem Occurred.' currently i am using test credentials key = "gtKFFx" SALT = "eCwWELxi" – pavan Apr 28 '20 at 21:13
0

first of all you need not to pass any value in the the view, like you are passing to the posted[] fields. Second make sure you have switched to the testing mode on your payumoney profile. You can use the credentials available in this mode. lastly make sure when your form renders on you fill all the mandatory details.

raven404
  • 1,039
  • 9
  • 14