我已经根据文档https://developer.payumoney.com/redirect/
实施了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 =键| 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>
请帮助找到我犯错的地方
答案 0 :(得分:0)
对于Payu测试,请使用此凭据
def Home(request):
key = "gtKFFx"
SALT = "eCwWELxi"
PAYU_BASE_URL = "https://test.payu.in/_payment'"
希望有帮助
有关更多详细信息,请参见this
答案 1 :(得分:0)
首先,您不需要在视图中传递任何值,就像传递给posted []字段一样。 其次,请确保您已在Payumoney个人资料上切换到测试模式。您可以使用此模式下可用的凭据。 最后请确保在您的表单呈现时填写所有必填的详细信息。