예제 #1
0
    def server_check_transaction(self, request=None):
        _get = {}
        for key in request.GET:
            _get.update({key: request.GET.get(key)})
        resp_obj = BankSignature(self.transaction)

        if resp_obj.verify_signature(
                _get.get('IB_CRC'),
                self.generate_digest(_get, _get.get('IB_SERVICE'))):
            log_message('VERIFIED Transaction',
                        params=_get,
                        object=self.transaction)
            if _get.get('IB_SERVICE') == '0003':
                self.transaction.status = Transaction.STATUSES.pending
            else:
                self.transaction.server_response = _get.get('IB_STATUS', '')
                self.transaction.status = self.get_transaction_status(
                    _get.get('IB_STATUS'))
                self.transaction.server_response_at = timezone.now()
                self.transaction.returned_server_ip = get_client_ip(request)

            self.transaction.save()
            return _get
        else:
            log_message('ERROR Transaction',
                        'Invalid MAC',
                        params=_get,
                        object=self.transaction)
            raise Exception('Invalid MAC')
예제 #2
0
    def verify_return(self, request):
        # if user is forwarded, then we receive POST request. From SERVER bank sends GET request.
        if request.POST.get('IB_FROM_SERVER', None) == 'N':
            self.transaction = Transaction.objects.get(
                id=request.POST.get('IB_PAYMENT_ID'))
        else:
            self.transaction = Transaction.objects.get(
                id=request.GET.get('IB_PAYMENT_ID'))

        if request.POST.get('IB_FROM_SERVER', None) is None:
            self.server_check_transaction(request)
            self.check_transaction_status()
            return HttpResponse('OK')

        status_dict = self.check_transaction(request)

        if not status_dict:
            return super().final_redirect(False, request)
        else:
            # User response.
            if status_dict.get('IB_SERVICE') == '0004':
                self.transaction.user_response = status_dict.get('IB_STATUS')
                self.transaction.status = self.get_transaction_status(
                    status_dict.get('IB_STATUS'))
                self.transaction.returned_user_ip = get_client_ip(request)
                self.transaction.user_response_at = timezone.now()
                self.transaction.save()

                return super().final_redirect(
                    status_dict.get('IB_STATUS') == 'ACCOMPLISHED', request)
            else:
                return HttpResponse('Something went wrong')
예제 #3
0
    def get_file(self):
        self.object = self.model.objects.get(slug=self.request.resolver_match.kwargs.get('slug'))
        my_file = Path(self.object.file.path)

        if not my_file.is_file():
            if self.object.payment.channel is not None:
                active_channel = self.object.payment.channel
            else:
                payment_channel = PaymentChannel.objects.values_list('id', flat=True).filter(is_bill=True)
                active_channel = ActivePaymentChannel.objects.filter(competition_id=self.object.competition.id, payment_channel_id__in=payment_channel).get()

            if self.object.payment.content_type.name == 'team':
                create_team_invoice(self.object.payment.content_object, active_channel, action="", invoice_object=self.object)
            elif self.object.payment.content_type.name == 'application':
                create_application_invoice(self.object.payment.content_object, active_channel, action="", invoice_object=self.object)
            else:
                raise Exception("Unknown invoice.payment.content_type.name %s" % self.object.payment.content_type.name)

        if not self.request.user.has_perm('registration.add_number'):
            if not self.object.access_time or not self.object.access_ip:
                if self.object.payment.status == 10:
                    self.object.payment.status = 20
                self.object.access_ip = get_client_ip(self.request)
                self.object.access_time = datetime.datetime.now()
                self.object.save(update_fields=["access_ip", "access_time"])
        return super(InvoiceDownloadView, self).get_file()
예제 #4
0
    def verify_return(self, request):
        # if user is forwarded, then we receive POST request. From SERVER bank sends GET request.
        if request.POST.get('VK_AUTO', None) == 'N':
            self.transaction = Transaction.objects.get(
                id=request.POST.get('VK_REF'))
        else:
            self.transaction = Transaction.objects.get(
                id=request.GET.get('VK_REF'))

        if request.POST.get('VK_AUTO', None) is None:
            self.server_check_transaction(request)
            self.check_transaction_status()
            return HttpResponse('OK')

        status_dict = self.check_transaction(request)

        if not status_dict:
            return super().final_redirect(False, request)
        else:
            # User response.
            if status_dict.get('VK_SERVICE') == '1101':
                self.transaction.user_response = 'OK'
            else:
                self.transaction.user_response = 'CANCELLED'
            self.transaction.status = self.get_transaction_status(
                status_dict.get('VK_SERVICE'))
            self.transaction.returned_user_ip = get_client_ip(request)
            self.transaction.user_response_at = timezone.now()
            self.transaction.save()

            return super().final_redirect(
                status_dict.get('VK_SERVICE') == '1101', request)
예제 #5
0
    def get_file(self):
        self.object = self.model.objects.get(slug=self.request.resolver_match.kwargs.get('slug'))
        my_file = Path(self.object.file.path)

        if not my_file.is_file():
            if self.object.payment.channel is not None:
                active_channel = self.object.payment.channel
            else:
                payment_channel = PaymentChannel.objects.values_list('id', flat=True).filter(is_bill=True)
                active_channel = ActivePaymentChannel.objects.filter(competition_id=self.object.competition.id,
                                                                     payment_channel_id__in=payment_channel).get()

            if self.object.payment.content_type.name == 'team':
                create_team_invoice(self.object.payment.content_object, active_channel, action="",
                                    invoice_object=self.object)
            elif self.object.payment.content_type.name == 'application':
                create_application_invoice(self.object.payment.content_object, active_channel, action="",
                                           invoice_object=self.object)
            else:
                raise Exception("Unknown invoice.payment.content_type.name %s" % self.object.payment.content_type.name)

        if not self.request.user.has_perm('registration.add_number'):
            if not self.object.access_time or not self.object.access_ip:
                if self.object.payment.status == 10:
                    self.object.payment.status = 20
                self.object.access_ip = get_client_ip(self.request)
                self.object.access_time = datetime.datetime.now()
                self.object.save(update_fields=["access_ip", "access_time"])
        return super(InvoiceDownloadView, self).get_file()
예제 #6
0
파일: bank.py 프로젝트: Ameriks/velo.lv
    def verify_return(self, request):
        # if user is forwarded, then we receive POST request. From SERVER bank sends GET request.
        if request.POST.get('IB_FROM_SERVER', None) == 'N':
            self.transaction = Transaction.objects.get(id=request.POST.get('IB_PAYMENT_ID'))
        else:
            self.transaction = Transaction.objects.get(id=request.GET.get('IB_PAYMENT_ID'))

        if request.POST.get('IB_FROM_SERVER', None) is None:
            self.server_check_transaction(request)
            self.check_transaction_status()
            return HttpResponse('OK')

        status_dict = self.check_transaction(request)

        if not status_dict:
            return super().final_redirect(False, request)
        else:
            # User response.
            if status_dict.get('IB_SERVICE') == '0004':
                self.transaction.user_response = status_dict.get('IB_STATUS')
                self.transaction.status = self.get_transaction_status(status_dict.get('IB_STATUS'))
                self.transaction.returned_user_ip = get_client_ip(request)
                self.transaction.user_response_at = timezone.now()
                self.transaction.save()

                return super().final_redirect(status_dict.get('IB_STATUS') == 'ACCOMPLISHED', request)
            else:
                return HttpResponse('Something went wrong')
예제 #7
0
파일: bank.py 프로젝트: Ameriks/velo.lv
    def verify_return(self, request):
        # if user is forwarded, then we receive POST request. From SERVER bank sends GET request.
        if request.POST.get('VK_AUTO', None) == 'N':
            self.transaction = Transaction.objects.get(id=request.POST.get('VK_REF'))
        else:
            self.transaction = Transaction.objects.get(id=request.GET.get('VK_REF'))

        if request.POST.get('VK_AUTO', None) is None:
            self.server_check_transaction(request)
            self.check_transaction_status()
            return HttpResponse('OK')

        status_dict = self.check_transaction(request)

        if not status_dict:
            return super().final_redirect(False, request)
        else:
            # User response.
            if status_dict.get('VK_SERVICE') == '1101':
                self.transaction.user_response = 'OK'
            else:
                self.transaction.user_response = 'CANCELLED'
            self.transaction.status = self.get_transaction_status(status_dict.get('VK_SERVICE'))
            self.transaction.returned_user_ip = get_client_ip(request)
            self.transaction.user_response_at = timezone.now()
            self.transaction.save()

            return super().final_redirect(status_dict.get('VK_SERVICE') == '1101', request)
예제 #8
0
파일: bank.py 프로젝트: Ameriks/velo.lv
 def verify_return(self, request):
     status_dict = self.check_transaction()
     if not status_dict:
         return super().final_redirect(False, request)
     else:
         self.transaction.user_response = status_dict.get('RESULT')
         self.transaction.server_response = self.transaction.user_response
         self.transaction.returned_user_ip = get_client_ip(request)
         self.transaction.user_response_at = timezone.now()
         self.transaction.server_response_at = self.transaction.user_response_at
         self.transaction.status = self.get_transaction_status(status_dict.get('RESULT'))
         self.transaction.save()
         return super().final_redirect(status_dict.get('RESULT') == 'OK', request)
예제 #9
0
 def verify_return(self, request):
     status_dict = self.check_transaction()
     if not status_dict:
         return super().final_redirect(False, request)
     else:
         self.transaction.user_response = status_dict.get('RESULT')
         self.transaction.server_response = self.transaction.user_response
         self.transaction.returned_user_ip = get_client_ip(request)
         self.transaction.user_response_at = timezone.now()
         self.transaction.server_response_at = self.transaction.user_response_at
         self.transaction.status = self.get_transaction_status(
             status_dict.get('RESULT'))
         self.transaction.save()
         return super().final_redirect(
             status_dict.get('RESULT') == 'OK', request)
예제 #10
0
파일: utils.py 프로젝트: cash2one/velo.lv
def create_bank_transaction(instance, active_payment_type, request):
    instance_name = instance.__class__.__name__
    if instance_name == 'Application':
        information = "Pieteikums nr.%i" % instance.id if not instance.invoice else "Rekins nr.%s" % instance.invoice.invoice_nr
        if instance.donation > 0:
            information += (" + %s" % instance.competition.params_dict.get(
                "donation", {}).get("bank_code",
                                    "Ziedojums - %s")) % instance.donation
    elif instance_name == 'Team':
        information = "Komandas %s profila apmaksa %s" % (str(instance), instance.distance.competition.get_full_name) \
            if not instance.invoice else "Rekins nr.%s" % instance.invoice.invoice_nr
    else:
        raise Exception()

    # For testing purposes. To test successful SEB and Swedbank transactions.
    if request.user.is_authenticated() and request.user.id == 6:
        instance.final_price = Decimal('0.01')

    content_type = ContentType.objects.get_for_model(instance)
    payment, created = Payment.objects.get_or_create(
        content_type=content_type,
        object_id=instance.id,
        competition=instance.competition,
        total=instance.final_price,
        donation=instance.donation if hasattr(instance, "donation") else 0.00,
        defaults={"status": Payment.STATUSES.pending})

    if not created:
        if payment.status == Payment.STATUSES.ok:
            raise Exception("Already payed")
        payment.status = Payment.STATUSES.pending
        payment.save()

    transaction = Transaction.objects.create(
        channel=active_payment_type.payment_channel,
        payment=payment,
        language=request.LANGUAGE_CODE,
        status=Transaction.STATUSES.new,
        amount=instance.final_price,
        created_ip=get_client_ip(request),
        information=information,
    )

    return reverse('payment:transaction', kwargs=({'slug': transaction.code}))
예제 #11
0
파일: utils.py 프로젝트: Ameriks/velo.lv
def create_bank_transaction(instance, active_payment_type, request):
    instance_name = instance.__class__.__name__
    if instance_name == 'Application':
        information = "Pieteikums nr.%i" % instance.id if not instance.invoice else "Rekins nr.%s" % instance.invoice.invoice_nr
        if instance.donation > 0:
            information += (" + %s" % instance.competition.params_dict.get("donation", {}).get("bank_code", "Ziedojums - %s")) % instance.donation
    elif instance_name == 'Team':
        information = "Komandas %s profila apmaksa %s" % (str(instance), instance.distance.competition.get_full_name) \
            if not instance.invoice else "Rekins nr.%s" % instance.invoice.invoice_nr
    else:
        raise Exception()

    # For testing purposes. To test successful SEB and Swedbank transactions.
    if request.user.is_authenticated() and request.user.id == 6:
        instance.final_price = Decimal('0.01')

    content_type = ContentType.objects.get_for_model(instance)
    payment, created = Payment.objects.get_or_create(
                content_type=content_type,
                object_id=instance.id,
                competition=instance.competition,
                total=instance.final_price,
                donation=instance.donation if hasattr(instance, "donation") else 0.00,
                defaults={"status": Payment.STATUSES.pending}
            )

    if not created:
        if payment.status == Payment.STATUSES.ok:
            raise Exception("Already payed")
        payment.status = Payment.STATUSES.pending
        payment.save()

    transaction = Transaction.objects.create(
        channel=active_payment_type.payment_channel,
        payment=payment,
        language=request.LANGUAGE_CODE,
        status=Transaction.STATUSES.new,
        amount=instance.final_price,
        created_ip=get_client_ip(request),
        information=information,
    )

    return reverse('payment:transaction', kwargs=({'slug': transaction.code}))
예제 #12
0
파일: bank.py 프로젝트: Ameriks/velo.lv
    def server_check_transaction(self, request=None):
        _get = {}
        for key in request.GET:
            _get.update({key: request.GET.get(key)})
        resp_obj = BankSignature(self.transaction)

        if resp_obj.verify_signature(_get.get('VK_MAC'), self.generate_digest(_get)):
            log_message('VERIFIED Transaction', params=_get, object=self.transaction)
            if _get.get('VK_SERVICE') == '1101':
                self.transaction.server_response = 'OK'
            else:
                self.transaction.server_response = 'FAILED'
            self.transaction.status = self.get_transaction_status(_get.get('VK_SERVICE'))
            self.transaction.server_response_at = timezone.now()
            self.transaction.returned_server_ip = get_client_ip(request)
            self.transaction.save()
            return _get
        else:
            log_message('ERROR Transaction', 'Invalid MAC', params=_get, object=self.transaction)
            raise Exception('Invalid MAC')