Пример #1
0
    def form_valid(self, form):
        if settings.ZENAIDA_BILLING_PAYMENT_TIME_FREEZE_SECONDS:
            my_latest_unfinished_payment = payments.latest_payment(
                owner=self.request.user,
                status_in=[
                    'started',
                    'cancelled',
                    'declined',
                ],
            )
            if my_latest_unfinished_payment:
                if timezone.now(
                ) - my_latest_unfinished_payment.started_at < datetime.timedelta(
                        seconds=settings.
                        ZENAIDA_BILLING_PAYMENT_TIME_FREEZE_SECONDS, ):
                    messages.info(
                        self.request,
                        'Please wait few minutes and then try again.')
                    return shortcuts.redirect('billing_new_payment')

        my_pending_payment = payments.latest_payment(
            owner=self.request.user,
            status_in=[
                'paid',
            ],
        )
        if my_pending_payment:
            messages.info(
                self.request,
                'Your previous payment is pending for verification. Please wait few minutes before starting a new transaction.'
            )
            return shortcuts.redirect('billing_payments')

        payment_method = form.cleaned_data['payment_method']
        payment_amount = float(form.cleaned_data['amount'])

        new_payment = payments.start_payment(
            owner=self.request.user,
            amount=payment_amount,
            payment_method=payment_method,
        )

        # TODO: for the future, if we need to implement other types of payments
        # https://www.dreamhost.com/blog/10-online-payment-gateways-compared/

        if payment_method == 'pay_4csonline':
            return shortcuts.render(
                self.request, 'billing/4csonline/start_payment.html', {
                    'transaction_id': new_payment.transaction_id,
                })

        elif payment_method == 'pay_btcpay':
            return shortcuts.render(
                self.request, 'billing/btcpay/start_payment.html', {
                    'transaction_id': new_payment.transaction_id,
                    'amount': new_payment.amount
                })

        messages.error(self.request, self.error_message)
        return super().form_valid(form)
Пример #2
0
    def form_valid(self, form):
        if not settings.ZENAIDA_BILLING_BYPASS_PAYMENT_TIME_CHECK:
            my_latest_payment = payments.latest_payment(self.request.user)
            if my_latest_payment:
                if timezone.now(
                ) - my_latest_payment.started_at < datetime.timedelta(
                        minutes=3):
                    messages.info(
                        self.request,
                        'Please wait few minutes and then try again.')
                    return shortcuts.redirect('billing_new_payment')

        new_payment = payments.start_payment(
            owner=self.request.user,
            amount=form.cleaned_data['amount'],
            payment_method=form.cleaned_data['payment_method'],
        )

        if new_payment.method == 'pay_4csonline':
            return shortcuts.render(
                self.request, 'billing/4csonline/start_payment.html', {
                    'transaction_id': new_payment.transaction_id,
                })

        elif new_payment.method == 'pay_btcpay':
            return shortcuts.render(
                self.request, 'billing/btcpay/start_payment.html', {
                    'transaction_id': new_payment.transaction_id,
                    'amount': new_payment.amount
                })

        messages.error(self.request, self.error_message)
        return super().form_valid(form)
Пример #3
0
    def form_valid(self, form):
        email = form.cleaned_data.get('email')
        amount = form.cleaned_data.get('amount')
        payment_reason = form.cleaned_data.get('reason')

        account = Account.objects.filter(email=email).first()
        if not Account.objects.filter(email=email).first():
            messages.warning(self.request, 'This user does not exist.')
            return super().form_valid(form)

        payment = payments.start_payment(
            owner=account,
            amount=amount,
            payment_method='pay_by_admin',
        )

        payments.finish_payment(
            transaction_id=payment.transaction_id,
            status='processed',
            notes=f'{payment_reason} (by {self.request.user.email})',
        )

        messages.success(
            self.request,
            f'You successfully added {amount} USD to the balance of {email}')

        return super().form_valid(form)
Пример #4
0
def prepare_tester_payment(tester=None, amount=100, payment_method='pay_4csonline'):
    if not tester:
        tester = prepare_tester_account()
    new_payment = payments.start_payment(
        owner=tester,
        amount=amount,
        payment_method=payment_method,
    )
    return new_payment