2

我有一个 django 应用程序,我正在尝试将它与 EBS 支付网关集成。所以下面是我的代码

设置.py

INSTALLED_APPS = (
    .............  
    'ebspayment',
)
EBS_ACCOUNT_ID = '5880'   #Enter Your Account Id here.This is a test id. 
EBS_SECRET_KEY = 'ebskey' #Enter Your Secret Key here.This is a test key.
EBS_ACTION_URL = 'https://secure.ebs.in/pg/ma/sale/pay' #Do not edit this URL.
EBS_RETURN_URL = 'http://127.0.0.1:8000/ebs/ebspayment/response' #Enter your domain URL instead of 127.0.0.1:8000. 

网址.py

from django.conf.urls import url, patterns
from ebspayment.views import ebspayment, ebsresponse


urlpatterns = patterns('',
    url(r'^ebspayment/(?P<app_id>\d+)/$', ebspayment, name='ebsindex'), 
    url(r'^ebspayment/response', ebsresponse, name='ebsresponse'), 
)

视图.py

def ebspayment(request, app_id):
    app = get_object_or_404(App, pk=campaign_id)
    form = PaymentForm()
    # string = settings.EBS_SECRET_KEY+"|"+form.cleaned_data['account_id']+"|"
    #               +form.cleaned_data['amount']+"|"+form.cleaned_data['reference_no'] +"|"
    #               +form.cleaned_data['return_url']+"|"+form.cleaned_data['mode']
    string = settings.EBS_SECRET_KEY+"|"+'5880'+"|"+'1.00'+"|"+'223'+"|"+settings.EBS_RETURN_URL+"|"+"TEST"
    secure_hash = hashlib.md5(string).hexdigest()                 
    return render_to_response('ebspayment/payment_form.html', {'form': form,
                                                      'app_obj' : app,
                                                      'ebs_url': settings.EBS_ACTION_URL,
                                                      'secure_hash' : secure_hash},
                                                      context_instance=RequestContext(request))

payment_form.html

{% block content %}
<h1>Enter Card Details</h1> 
<form class="form-horizontal" action="{{ ebs_url }}" method="POST" name="frmTransaction" id="frmTransaction" onSubmit="return validate()">
        {{form.as_p}}
         <input type='hidden' name='secure_hash' value='{{secure_hash}}'>
         <button type="submit" value="submit"  class="btn btn-primary" >Submit</button>
    </form>
{% endblock %} 

表格.py

#Transaction Modes
MODES = (
     ('TEST', 'TEST'),
     ('LIVE', 'LIVE'),
)

#EBS Payment Form
class PaymentForm(forms.Form):

    account_id = forms.IntegerField(initial=settings.EBS_ACCOUNT_ID, required=True)
    reference_no = forms.IntegerField(required=True, initial="223")
    amount = forms.DecimalField(max_digits=10, decimal_places=2, required=True, initial='1.00')
    name = forms.CharField(max_length=255, required=True, initial="Sheeba") 
    email = forms.EmailField(max_length=70, required=True, initial="xyz@ebs.in")
    address = forms.CharField(required=True, initial="Kodambakkam")
    city = forms.CharField(max_length=60, required=True, initial="Chennai")
    state = forms.CharField(max_length=60, required=True, initial="Tamil Nadu")
    country = CountryField()
    postal_code = forms.IntegerField(required=True, initial="600098")
    phone = forms.IntegerField(required=True, initial="044123456")   
    return_url = forms.URLField(label="Return URL", required=True, initial=settings.EBS_RETURN_URL+'?DR={DR}')
    description = forms.CharField(required=True, initial="Testing EBS-Django")
    mode = forms.ChoiceField(choices=MODES)

因此,从上面的代码中,我将显示 aPayment form并将所有输入的详细信息(包括secure_hash变量数据)提交到 url http://127.0.0.1:8000/ebs/ebspayment/response

但即使在提交哈希字符串之后,我Error! SecureHash validation failed在重定向到这个 url 之后也得到了,所以我在上面的代码中做错了什么

  1. 实际上是否有任何模块/代码/包可以满足EBS支付网关与 django 的集成?
  2. 为了整合,我们需要有一个EBS merchant account确定的?因为对于其他支付网关,如 authorize.net 需要一个可用于集成目的的沙箱帐户
  3. 在上面的代码中,我正在对创建哈希的字符串值进行硬编码,但实际上这需要在验证后来自表单,但在这种情况下不知道如何验证表单,因为如所示我们正在发布到另一个 url http://127.0.0.1:8000/ebs/ebspayment/response,因此我们不能通过视图验证表单吗?(我们可以通过 javascript 进行验证:))
  4. 所以最后谁能指出我正确的方向,以便将 django 应用程序与 EBS 支付网关集成
  5. 也有人可以让我知道将 django 应用程序与 EBS 网关集成所需的要求吗?
  6. 请让我知道要对上述代码做什么以避免secure validation error
4

1 回答 1

0

如果您无法处理哈希验证,则可以禁用商家帐户的安全验证检查。

于 2013-12-18T21:22:34.170 回答