def result(request):
    logger = logging.getLogger('webmoney.result')
    logger.debug(u'The beginning of the request', extra={'request': request})

    if request.method != 'POST':
        return HttpResponseNotAllowed(permitted_methods=('POST',))

    form = PrerequestForm(request.POST)
    if form.is_valid() and form.cleaned_data['LMI_PREREQUEST']:
        payment_no = int(form.cleaned_data['LMI_PAYMENT_NO'])
        try:
            Invoice.objects.get(payment_no=payment_no)
        except ObjectDoesNotExist:
            return HttpResponseBadRequest(
                "Invoice with number %s not found." % payment_no)
        return HttpResponse("YES")

    form = PaymentNotificationForm(request.POST)
    if form.is_valid():
        purse = Purse.objects.get(purse=form.cleaned_data['LMI_PAYEE_PURSE'])

        key = "%s%s%s%s%s%s%s%s%s%s" % (
            purse.purse,
            form.cleaned_data['LMI_PAYMENT_AMOUNT'],
            form.cleaned_data['LMI_PAYMENT_NO'],
            form.cleaned_data['LMI_MODE'],
            form.cleaned_data['LMI_SYS_INVS_NO'],
            form.cleaned_data['LMI_SYS_TRANS_NO'],
            form.cleaned_data['LMI_SYS_TRANS_DATE'].strftime(
                '%Y%m%d %H:%M:%S'),
            purse.secret_key,
            form.cleaned_data['LMI_PAYER_PURSE'],
            form.cleaned_data['LMI_PAYER_WM']
        )

        generated_hash = sha256(key).hexdigest().upper()

        if generated_hash == form.cleaned_data['LMI_HASH']:
            payment = Payment(
                payee_purse=purse,
                amount=form.cleaned_data['LMI_PAYMENT_AMOUNT'],
                payment_no=form.cleaned_data['LMI_PAYMENT_NO'],
                mode=form.cleaned_data['LMI_MODE'],
                sys_invs_no=form.cleaned_data['LMI_SYS_INVS_NO'],
                sys_trans_no=form.cleaned_data['LMI_SYS_TRANS_NO'],
                sys_trans_date=form.cleaned_data['LMI_SYS_TRANS_DATE'],
                payer_purse=form.cleaned_data['LMI_PAYER_PURSE'],
                payer_wm=form.cleaned_data['LMI_PAYER_WM'],
                paymer_number=form.cleaned_data['LMI_PAYMER_NUMBER'],
                paymer_email=form.cleaned_data['LMI_PAYMER_EMAIL'],
                telepat_phonenumber=form.cleaned_data[
                    'LMI_TELEPAT_PHONENUMBER'],
                telepat_orderid=form.cleaned_data['LMI_TELEPAT_ORDERID'],
                payment_creditdays=form.cleaned_data['LMI_PAYMENT_CREDITDAYS']
            )

            try:
                payment.invoice = Invoice.objects.get(
                    payment_no=form.cleaned_data['LMI_PAYMENT_NO'])
            except ObjectDoesNotExist:
                mail_admins(
                    'Unprocessed payment without invoice!',
                    'Payment NO is %s.' % form.cleaned_data['LMI_PAYMENT_NO'],
                    fail_silently=True)

            payment.save()

            webmoney_payment_accepted.send(
                sender=payment.__class__, payment=payment)
            return HttpResponse("OK")
        else:
            mail_admins(
                'Unprocessed payment with incorrect hash!',
                'Payment NO is %s.' % form.cleaned_data['LMI_PAYMENT_NO'],
                fail_silently=True)
            return HttpResponseBadRequest("Incorrect hash")
    logger.debug(u"PaymentNotificationForm Errors:\n {errors}".format(errors=form.errors), extra={'request': request})
    return HttpResponseBadRequest("Unknown error!")
Example #2
0
def result(request):
    logger = logging.getLogger('webmoney.result')
    logger.debug(u'The beginning of the request', extra={'request': request})

    if request.method != 'POST':
        return HttpResponseNotAllowed(permitted_methods=('POST', ))

    form = PrerequestForm(request.POST)
    if form.is_valid() and form.cleaned_data['LMI_PREREQUEST']:
        payment_no = int(form.cleaned_data['LMI_PAYMENT_NO'])
        try:
            Invoice.objects.get(payment_no=payment_no)
        except ObjectDoesNotExist:
            return HttpResponseBadRequest("Invoice with number %s not found." %
                                          payment_no)
        return HttpResponse("YES")

    form = PaymentNotificationForm(request.POST)
    if form.is_valid():
        purse = Purse.objects.get(purse=form.cleaned_data['LMI_PAYEE_PURSE'])

        key = "%s%s%s%s%s%s%s%s%s%s" % (
            purse.purse, form.cleaned_data['LMI_PAYMENT_AMOUNT'],
            form.cleaned_data['LMI_PAYMENT_NO'], form.cleaned_data['LMI_MODE'],
            form.cleaned_data['LMI_SYS_INVS_NO'],
            form.cleaned_data['LMI_SYS_TRANS_NO'], form.
            cleaned_data['LMI_SYS_TRANS_DATE'].strftime('%Y%m%d %H:%M:%S'),
            purse.secret_key, form.cleaned_data['LMI_PAYER_PURSE'],
            form.cleaned_data['LMI_PAYER_WM'])

        generated_hash = sha256(key).hexdigest().upper()

        if generated_hash == form.cleaned_data['LMI_HASH']:
            payment = Payment(
                payee_purse=purse,
                amount=form.cleaned_data['LMI_PAYMENT_AMOUNT'],
                payment_no=form.cleaned_data['LMI_PAYMENT_NO'],
                mode=form.cleaned_data['LMI_MODE'],
                sys_invs_no=form.cleaned_data['LMI_SYS_INVS_NO'],
                sys_trans_no=form.cleaned_data['LMI_SYS_TRANS_NO'],
                sys_trans_date=form.cleaned_data['LMI_SYS_TRANS_DATE'],
                payer_purse=form.cleaned_data['LMI_PAYER_PURSE'],
                payer_wm=form.cleaned_data['LMI_PAYER_WM'],
                paymer_number=form.cleaned_data['LMI_PAYMER_NUMBER'],
                paymer_email=form.cleaned_data['LMI_PAYMER_EMAIL'],
                telepat_phonenumber=form.
                cleaned_data['LMI_TELEPAT_PHONENUMBER'],
                telepat_orderid=form.cleaned_data['LMI_TELEPAT_ORDERID'],
                payment_creditdays=form.cleaned_data['LMI_PAYMENT_CREDITDAYS'])

            try:
                payment.invoice = Invoice.objects.get(
                    payment_no=form.cleaned_data['LMI_PAYMENT_NO'])
            except ObjectDoesNotExist:
                mail_admins('Unprocessed payment without invoice!',
                            'Payment NO is %s.' %
                            form.cleaned_data['LMI_PAYMENT_NO'],
                            fail_silently=True)

            payment.save()

            webmoney_payment_accepted.send(sender=payment.__class__,
                                           payment=payment)
            return HttpResponse("OK")
        else:
            mail_admins('Unprocessed payment with incorrect hash!',
                        'Payment NO is %s.' %
                        form.cleaned_data['LMI_PAYMENT_NO'],
                        fail_silently=True)
            return HttpResponseBadRequest("Incorrect hash")
    logger.debug(u"PaymentNotificationForm Errors:\n {errors}".format(
        errors=form.errors),
                 extra={'request': request})
    return HttpResponseBadRequest("Unknown error!")
Example #3
0
def result(request):
    form = PrerequestForm(request.POST)
    if form.is_valid() and form.cleaned_data['LMI_PREREQUEST']:
        cleaned_data = form.cleaned_data
        pre_payment = PrePayment(
            id_pay=cleaned_data['ID_PAY'],
            desc_pay=cleaned_data['DESC_PAY'],
            zp_type_pay=cleaned_data['ZP_TYPE_PAY']
        )
        payment_no = cleaned_data['LMI_PAYMENT_NO']
        try:
            invoice = Invoice.objects.get(payment_no=payment_no)
        except Invoice.DoesNotExist:
            return HttpResponseBadRequest(
                "Invoice with number %s not found." % payment_no
            )
        else:
            pre_payment.webmoney_invoice = invoice
            pre_payment.save()
        return HttpResponse("YES")
    form = PaymentNotificationForm(request.POST)
    if form.is_valid():
        cleaned_data = form.cleaned_data
        purse = Purse.objects.get(purse=cleaned_data['LMI_PAYEE_PURSE'])
        key = "%s%s%s%s%s%s%s%s%s%s" % (
            purse.purse,
            cleaned_data['LMI_PAYMENT_AMOUNT'],
            cleaned_data['LMI_PAYMENT_NO'],
            cleaned_data['LMI_MODE'],
            cleaned_data['LMI_SYS_INVS_NO'],
            cleaned_data['LMI_SYS_TRANS_NO'],
            cleaned_data['LMI_SYS_TRANS_DATE'].strftime('%Y%m%d %H:%M:%S'),
            purse.secret_key,
            cleaned_data['LMI_PAYER_PURSE'],
            cleaned_data['LMI_PAYER_WM']
        )
        generated_hash = md5(key).hexdigest().upper()
        payment_no = cleaned_data['LMI_PAYMENT_NO']
        if WebmoneyPayment.objects.filter(payment_no=payment_no):
            mail_admins('Dublicate payment', 'Payment NO is %s.' % payment_no, fail_silently=True)
            return HttpResponse("OK")
        if generated_hash == form.cleaned_data['LMI_HASH']:
            payment = WebmoneyPayment(
                payee_purse=purse,
                amount=cleaned_data['LMI_PAYMENT_AMOUNT'],
                payment_no=payment_no,
                mode=cleaned_data['LMI_MODE'],
                sys_invs_no=cleaned_data['LMI_SYS_INVS_NO'],
                sys_trans_no=cleaned_data['LMI_SYS_TRANS_NO'],
                sys_trans_date=cleaned_data['LMI_SYS_TRANS_DATE'],
                payer_purse=cleaned_data['LMI_PAYER_PURSE'],
                payer_wm=cleaned_data['LMI_PAYER_WM'],
                paymer_number=cleaned_data['LMI_PAYMER_NUMBER'],
                paymer_email=cleaned_data['LMI_PAYMER_EMAIL'],
                telepat_phonenumber=cleaned_data['LMI_TELEPAT_PHONENUMBER'],
                telepat_orderid=cleaned_data['LMI_TELEPAT_ORDERID'],
                payment_creditdays=cleaned_data['LMI_PAYMENT_CREDITDAYS']
            )
            try:
                invoice = Invoice.objects.get(payment_no=payment_no)
                payment.invoice = invoice
            except Invoice.DoesNotExist:
                subject = 'Unprocessed payment without invoice!',
                message = 'Payment NO is %s.' % payment_no
                mail_admins(subject, message, fail_silently=True)
            payment.save()
            Payment.objects.create(
                webmoney_payment=payment,
                zp_type_pay=cleaned_data['ZP_TYPE_PAY']
            )
            webmoney_payment_accepted.send(
                sender=payment.__class__, payment=payment
            )
            return HttpResponse("OK")
        else:
            subject = 'Unprocessed payment with incorrect hash!'
            message = 'Payment NO is %s.' % payment_no
            mail_admins(subject, message, fail_silently=True)
            return HttpResponseBadRequest("Incorrect hash")
    return HttpResponseBadRequest("Unknown error!")