Сбой контрольной суммы в payumoney в Django? - PullRequest
1 голос
/ 04 апреля 2019

Я реализовал в соответствии с документами https://developer.payumoney.com/redirect/

Но при получении контрольной суммы ошибки произошел сбой, я использую тестовый 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})

У меня есть передаваемое значение в соответствии с документами payumoney, я проверил hash и hash_sequence так же, как:

hashSequence = key | txnid | сумма | productinfo | имя | электронная почта | udf1 | udf2 | udf3 | udf4 | udf5 |||||| соль.

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>

пожалуйста, помогите найти, где я допустил ошибку

1 Ответ

0 голосов
/ 04 апреля 2019

Для теста Payu используйте эти учетные данные

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

надеюсь, это поможет

для более подробной информации см. это

...