# Path: payway/accounts/models.py
# class Invoice(RandomUIDAbstractModel, TimeStampedModel):
# 
#     account = models.ForeignKey(Account, related_name='invoices', verbose_name=_('account'))
#     money_amount = fields.MoneyField(_('money amount'), max_digits=MAX_MONEY_DIGITS, decimal_places=MAX_MONEY_PLACES) # for transmit
#     money_amount_without_percent = fields.MoneyField(_('money amount without percent'), max_digits=MAX_MONEY_DIGITS, decimal_places=MAX_MONEY_PLACES) # befor transmit
#     objects = ChainableQuerySetManager(InvoiceQuerySet)
# 
#     class Meta:
#         verbose_name = _('invoice')
#         verbose_name_plural = _('invoices')
#         db_table = 'payway_invoices'
# 
#     def __init__(self, *args, **kwargs):
#         money_amount = kwargs.get('money_amount') or None
#         if money_amount:
#             kwargs.setdefault('money_amount_without_percent', money_amount)
#         super(Invoice, self).__init__(*args, **kwargs)
# 
#     def get_success_response_payments(self):
#         return self.accounts_responsepayment_related.filter(is_OK=ResponsePayment.OK_STATUS.SUCCESS)
# 
#     def __unicode__(self):
#         return u'{0}'.format(self.uid)
# 
#     def update_money_amount_with_percent(self, percent=0.0):
#         self.money_amount_without_percent = self.money_amount
#         self.money_amount += round_down(percent % self.money_amount)
#         self.save()
# 
# Path: payway/qiwi/conf/settings.py
# QIWI_BILL_LIFETIME = getattr(settings, 'QIWI_BILL_LIFETIME', 24)  # hours
# 
# QIWI_CHECK_AGT = getattr(settings, 'QIWI_CHECK_AGT', False)
# 
# QIWI_PERCENT = getattr(settings, 'QIWI_PERCENT', 4.0)
# 
# Path: payway/qiwi/forms.py
# class RequestPaymentForm(forms.Form):
# 
#     txn_id = forms.RegexField(regex=TNX_ID_RE, label=_(u'unique payment number'), widget=forms.HiddenInput())
#     to = forms.IntegerField(
#         label=_('10 digits phone number'),
#         max_value=9999999999,
#         widget=forms.TextInput(attrs={'maxlength':'10'})
#     )
#     summ = forms.DecimalField(
#             max_digits=MAX_MONEY_DIGITS,
#             decimal_places=MAX_MONEY_PLACES,
#             label=u'{0} {1}% {2}'.format(_('sum with'), QIWI_PERCENT, _('percent')),
#             widget=forms.TextInput(attrs={'readonly':'readonly'}),
#     )
#     com = forms.CharField(label=_(u'description'), widget=forms.HiddenInput(), required=False)
#     lifetime = forms.IntegerField(required=False, widget=forms.HiddenInput())
#     check_agt = forms.BooleanField(required=False, widget=forms.HiddenInput())
# 
# 
#     def __init__(self, *args, **kwargs):
#         super(RequestPaymentForm, self).__init__(*args, **kwargs)
#         # because 'from' is keyword
#         self.fields['from'] = forms.IntegerField(label=_('from'), widget=forms.HiddenInput())
# 
# Path: payway/qiwi/conf/settings.py
# QIWI_LOGIN = getattr(settings, 'QIWI_LOGIN')


from django.shortcuts import get_object_or_404
from django.template.loader import render_to_string
from django.views.generic.base import TemplateView
from payway.accounts.models import Invoice
from payway.qiwi.conf.settings import QIWI_BILL_LIFETIME, QIWI_CHECK_AGT, QIWI_PERCENT
from payway.qiwi.forms import RequestPaymentForm
from payway.qiwi.conf.settings import QIWI_LOGIN
# -*- coding: UTF-8 -*-

__author__ = 'Razzhivin Alexander'
__email__ = 'admin@httpbots.com'


class QiwiView(TemplateView):
    template_name = 'qiwi/add_money_request.html'

    def get(self, request, *args, **kwargs):
        context = super(QiwiView, self).get_context_data(**kwargs)
        invoice_uid = int(kwargs.get('invoice_uid', 0))
        invoice = get_object_or_404(Invoice, uid=invoice_uid)
        invoice.update_money_amount_with_percent(QIWI_PERCENT)

        context['request_form'] = RequestPaymentForm(initial={
            'txn_id': invoice.uid,

# Path: payway/accounts/models.py
# class Invoice(RandomUIDAbstractModel, TimeStampedModel):
# 
#     account = models.ForeignKey(Account, related_name='invoices', verbose_name=_('account'))
#     money_amount = fields.MoneyField(_('money amount'), max_digits=MAX_MONEY_DIGITS, decimal_places=MAX_MONEY_PLACES) # for transmit
#     money_amount_without_percent = fields.MoneyField(_('money amount without percent'), max_digits=MAX_MONEY_DIGITS, decimal_places=MAX_MONEY_PLACES) # befor transmit
#     objects = ChainableQuerySetManager(InvoiceQuerySet)
# 
#     class Meta:
#         verbose_name = _('invoice')
#         verbose_name_plural = _('invoices')
#         db_table = 'payway_invoices'
# 
#     def __init__(self, *args, **kwargs):
#         money_amount = kwargs.get('money_amount') or None
#         if money_amount:
#             kwargs.setdefault('money_amount_without_percent', money_amount)
#         super(Invoice, self).__init__(*args, **kwargs)
# 
#     def get_success_response_payments(self):
#         return self.accounts_responsepayment_related.filter(is_OK=ResponsePayment.OK_STATUS.SUCCESS)
# 
#     def __unicode__(self):
#         return u'{0}'.format(self.uid)
# 
#     def update_money_amount_with_percent(self, percent=0.0):
#         self.money_amount_without_percent = self.money_amount
#         self.money_amount += round_down(percent % self.money_amount)
#         self.save()
# 
# Path: payway/qiwi/conf/settings.py
# QIWI_BILL_LIFETIME = getattr(settings, 'QIWI_BILL_LIFETIME', 24)  # hours
# 
# QIWI_CHECK_AGT = getattr(settings, 'QIWI_CHECK_AGT', False)
# 
# QIWI_PERCENT = getattr(settings, 'QIWI_PERCENT', 4.0)
# 
# Path: payway/qiwi/forms.py
# class RequestPaymentForm(forms.Form):
# 
#     txn_id = forms.RegexField(regex=TNX_ID_RE, label=_(u'unique payment number'), widget=forms.HiddenInput())
#     to = forms.IntegerField(
#         label=_('10 digits phone number'),
#         max_value=9999999999,
#         widget=forms.TextInput(attrs={'maxlength':'10'})
#     )
#     summ = forms.DecimalField(
#             max_digits=MAX_MONEY_DIGITS,
#             decimal_places=MAX_MONEY_PLACES,
#             label=u'{0} {1}% {2}'.format(_('sum with'), QIWI_PERCENT, _('percent')),
#             widget=forms.TextInput(attrs={'readonly':'readonly'}),
#     )
#     com = forms.CharField(label=_(u'description'), widget=forms.HiddenInput(), required=False)
#     lifetime = forms.IntegerField(required=False, widget=forms.HiddenInput())
#     check_agt = forms.BooleanField(required=False, widget=forms.HiddenInput())
# 
# 
#     def __init__(self, *args, **kwargs):
#         super(RequestPaymentForm, self).__init__(*args, **kwargs)
#         # because 'from' is keyword
#         self.fields['from'] = forms.IntegerField(label=_('from'), widget=forms.HiddenInput())
# 
# Path: payway/qiwi/conf/settings.py
# QIWI_LOGIN = getattr(settings, 'QIWI_LOGIN')


# Path: payway/qiwi/views.py
from django.shortcuts import get_object_or_404
from django.template.loader import render_to_string
from django.views.generic.base import TemplateView
from payway.accounts.models import Invoice
from payway.qiwi.conf.settings import QIWI_BILL_LIFETIME, QIWI_CHECK_AGT, QIWI_PERCENT
from payway.qiwi.forms import RequestPaymentForm
from payway.qiwi.conf.settings import QIWI_LOGIN

# -*- coding: UTF-8 -*-

__author__ = 'Razzhivin Alexander'
__email__ = 'admin@httpbots.com'


class QiwiView(TemplateView):
    template_name = 'qiwi/add_money_request.html'

    def get(self, request, *args, **kwargs):
        context = super(QiwiView, self).get_context_data(**kwargs)
        invoice_uid = int(kwargs.get('invoice_uid', 0))
        invoice = get_object_or_404(Invoice, uid=invoice_uid)
        invoice.update_money_amount_with_percent(QIWI_PERCENT)

        context['request_form'] = RequestPaymentForm(initial={
            'txn_id': invoice.uid,

            'from': QIWI_LOGIN,