コード例 #1
0
ファイル: requests.py プロジェクト: satels/django-telepay
def verify(xml_tree):
    tags = xml_tree.xpath("/request/verify")
    if len(tags) != 1:
        return get_error(u'Request must contain exactly one verification element')
    verify_tag = tags[0]
    form = VerifyForm(verify_tag.attrib)
    if form.is_valid():
        form_data = form.cleaned_data
        response_data = _backend.verify(form_data)
    else:
        response_data ={'code': form.get_code()}
    response_text = get_result(response_data)
    response = get_response(response_text)
    return response
コード例 #2
0
ファイル: requests.py プロジェクト: satels/django-telepay
def status(xml_tree):
    tags = xml_tree.xpath("/request/status")
    if len(tags) < 1:
        return get_error(u'Request must contain one or more status elements')
    response_text = ''
    for status_tag in tags:
        data = status_tag.attrib
        form = StatusForm(data)
        if form.is_valid():
            form_data = form.cleaned_data
            response_data = _backend.status(form_data)
        else:
            id = data['id']
            code = form.get_code()
            response_data = {'id': id, 'code': code, 'final': 0}
        response_text += get_result(response_data)
    response = get_response(response_text)
    return response
コード例 #3
0
ファイル: views.py プロジェクト: satels/django-telepay
def telepay(request):
    if TELEPAY_CHECK_CERT:
        expected_value = TELEPAY_CERT_VALUE
        value = request.META.get(TELEPAY_CERT_KEY)
        if value != expected_value:
            response_text = '<error>Invalid client SSL certificate</error>'
            return HttpResponse(response_text, mimetype='text/xml', status=403)
    # everything is OK below
    body = request.raw_post_data
    response_text = None
    for request_type in telepay_requests.__all__:
        part = '<%s ' % request_type
        if part in body and '<request>' in body:
            try:
                xml_tree = etree.fromstring(body)
            except etree.XMLSyntaxError, e:
                response_text = get_error(u'XML Error: %s' % e)
            else:
                response_func = getattr(telepay_requests, request_type)
                response_text = response_func(xml_tree)
コード例 #4
0
ファイル: requests.py プロジェクト: satels/django-telepay
def payment(xml_tree):
    tags = xml_tree.xpath("/request/payment")
    if len(tags) < 1:
        return get_error(u'Request must contain one or more payment elements')
    response_text = ''
    for payment_tag in tags:
        data = payment_tag.attrib
        form = PaymentForm(data)
        if form.is_valid():
            form_data = form.cleaned_data
            response_data = _backend.payment(form_data)
            telepay_payment = form.save(commit=False)
            telepay_payment.code = response_data['code']
            telepay_payment.save()
        else:
            id = data['id']
            code = form.get_code()
            response_data = {'id': id, 'code': code, 'final': 0}
        response_text += get_result(response_data)
    response = get_response(response_text)
    return response
コード例 #5
0
ファイル: views.py プロジェクト: satels/django-telepay
from django_telepay.helpers import get_error
from lxml import etree
import django_telepay.requests as telepay_requests


def telepay(request):
    if TELEPAY_CHECK_CERT:
        expected_value = TELEPAY_CERT_VALUE
        value = request.META.get(TELEPAY_CERT_KEY)
        if value != expected_value:
            response_text = '<error>Invalid client SSL certificate</error>'
            return HttpResponse(response_text, mimetype='text/xml', status=403)
    # everything is OK below
    body = request.raw_post_data
    response_text = None
    for request_type in telepay_requests.__all__:
        part = '<%s ' % request_type
        if part in body and '<request>' in body:
            try:
                xml_tree = etree.fromstring(body)
            except etree.XMLSyntaxError, e:
                response_text = get_error(u'XML Error: %s' % e)
            else:
                response_func = getattr(telepay_requests, request_type)
                response_text = response_func(xml_tree)
    if not response_text:
        response_text = get_error(
            u'Not found verify, payment or status tag in request. Stopped'
        )
    return HttpResponse(response_text, mimetype='text/xml')