I have a django app and i am trying to integrate it with EBS payment gateway. So below are my codes
settings.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.
urls.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'),
)
views.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 %}
forms.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)
So from the code above i am displaying a Payment form
and submitting all the entered details including secure_hash
variable data to the url http://127.0.0.1:8000/ebs/ebspayment/response
.
But even after submitting hash string, i am getting Error! SecureHash validation failed
after redirecting to this url, so am i doing anything wrong in the above code
- Actually is there any module/code/package that satisfies
EBS
payment gateway integration with django ? - In order to integrate we need to have a
EBS merchant account
for sure ? because for other payment gateways like authorize.net needs a sandbox account that can be used for integration purposes - In the above code i am hardcoding the string values that creates a hash, but actually that needs to come from form after validating but don't know how to validate the form in this case because as indicated we are posting to another url like
http://127.0.0.1:8000/ebs/ebspayment/response
and hence we cannot validate the form through view right ?(we may do validation through javascript :)) - So finally can anyone point me in a right direction in order to integrate a django app with EBS payment gateway
- Also can anyone please let me know the requirements that needs to be there to integrate a django app with EBS gateway ?
- Please let me know what to be done to the above code in order to avoid
secure validation error
?