# Path: konfera/settings.py
# CURRENCY = getattr(settings, 'CURRENCY', ('€', 'EUR'))
# 
# EMAIL_NOTIFY_BCC = getattr(settings, 'EMAIL_NOTIFY_BCC', [])
# 
# SITE_URL = getattr(settings, 'ABSOLUTE_URL', 'https://www.pycon.sk').rstrip('/')
# 
# UNPAID_ORDER_NOTIFICATION_REPEAT = getattr(settings, 'UNPAID_ORDER_NOTIFICATION_REPEAT', 3)
# 
# UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY = getattr(settings, 'UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY', 5)
# 
# Path: konfera/utils.py
# def send_email(addresses, subject, template_name, formatting_dict=None, **kwargs):
#     formatting_dict = formatting_dict or {}
#     template = get_email_template(template_name)
#     text_template = getattr(template, 'text_template', '')
#     html_template = getattr(template, 'html_template', '')
# 
#     if not text_template:
#         logger.critical('Missing text template (required) for the input {}.'.format(text_template))
#         raise EmailTemplateError("Email template is not valid for the input.")
#     if not html_template:
#         logger.warning('Invalid html template (not required) for the input {}.'.format(html_template))
# 
#     text_content = validate_email_template(text_template, formatting_dict)
#     html_content = validate_email_template(html_template, formatting_dict, False)
# 
#     to = addresses.get('to', [])
#     cc = addresses.get('cc', [])
#     bcc = addresses.get('bcc', EMAIL_NOTIFY_BCC)
# 
#     msg = EmailMultiAlternatives(subject, text_content, to=to, cc=cc, bcc=bcc)
#     if html_content:
#         msg.attach_alternative(html_content, "text/html")
# 
#     try:
#         msg.send()
#     except (SMTPException, ConnectionRefusedError) as e:
#         logger.critical('Sending email raised an exception: %s', e)
#     else:
#         # increase count on email_template
#         template.add_count()
#         if kwargs.get('verbose', 0) > 1:
#             print(msg)
#         return True
# 
# Path: payments/settings.py
# PAYMENT_PROCESS_EMAIL_NOTIFY = getattr(settings, 'PAYMENT_PROCESS_EMAIL_NOTIFY', False)
# FIO_BANK_TOKEN = getattr(settings, 'FIO_BANK_TOKEN', 'token')
# FIO_BANK_PROCESS_DAYS = 3
# PAYMENT_ERROR_RATE = getattr(settings, 'PAYMENT_ERROR_RATE', 0)
# PAYPAL_ADDITIONAL_CHARGE = getattr(settings, 'PAYPAL_ADDITIONAL_CHARGE', 2)
# PAYPAL_MODE = getattr(settings, 'PAYPAL_MODE', 'sandbox')
# PAYPAL_CLIENT_ID = getattr(settings, 'PAYPAL_CLIENT_ID', 'client_id')
# PAYPAL_CLIENT_SECRET = getattr(settings, 'PAYPAL_CLIENT_SECRET', 'secret')


from datetime import timedelta
from decimal import Decimal
from django.db.models import Q
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django import VERSION
from fiobank import FioBank
from konfera.models import Order
from konfera.settings import (CURRENCY, EMAIL_NOTIFY_BCC, SITE_URL,
                              UNPAID_ORDER_NOTIFICATION_REPEAT, UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY)
from konfera.utils import send_email
from payments import settings
from payments.models import ProcessedTransaction
    from django.core.urlresolvers import reverse
    from django.urls import reverse
import requests
import logging





if VERSION[1] in (8, 9):
else:


DATE_FORMAT = '%Y-%m-%d'


logger = logging.getLogger(__name__)


def _get_last_payments():
    """ Get list of payments for last three days from FioBank """
    client = FioBank(token=settings.FIO_BANK_TOKEN)

    today = timezone.now()

# Path: konfera/settings.py
# CURRENCY = getattr(settings, 'CURRENCY', ('€', 'EUR'))
# 
# EMAIL_NOTIFY_BCC = getattr(settings, 'EMAIL_NOTIFY_BCC', [])
# 
# SITE_URL = getattr(settings, 'ABSOLUTE_URL', 'https://www.pycon.sk').rstrip('/')
# 
# UNPAID_ORDER_NOTIFICATION_REPEAT = getattr(settings, 'UNPAID_ORDER_NOTIFICATION_REPEAT', 3)
# 
# UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY = getattr(settings, 'UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY', 5)
# 
# Path: konfera/utils.py
# def send_email(addresses, subject, template_name, formatting_dict=None, **kwargs):
#     formatting_dict = formatting_dict or {}
#     template = get_email_template(template_name)
#     text_template = getattr(template, 'text_template', '')
#     html_template = getattr(template, 'html_template', '')
# 
#     if not text_template:
#         logger.critical('Missing text template (required) for the input {}.'.format(text_template))
#         raise EmailTemplateError("Email template is not valid for the input.")
#     if not html_template:
#         logger.warning('Invalid html template (not required) for the input {}.'.format(html_template))
# 
#     text_content = validate_email_template(text_template, formatting_dict)
#     html_content = validate_email_template(html_template, formatting_dict, False)
# 
#     to = addresses.get('to', [])
#     cc = addresses.get('cc', [])
#     bcc = addresses.get('bcc', EMAIL_NOTIFY_BCC)
# 
#     msg = EmailMultiAlternatives(subject, text_content, to=to, cc=cc, bcc=bcc)
#     if html_content:
#         msg.attach_alternative(html_content, "text/html")
# 
#     try:
#         msg.send()
#     except (SMTPException, ConnectionRefusedError) as e:
#         logger.critical('Sending email raised an exception: %s', e)
#     else:
#         # increase count on email_template
#         template.add_count()
#         if kwargs.get('verbose', 0) > 1:
#             print(msg)
#         return True
# 
# Path: payments/settings.py
# PAYMENT_PROCESS_EMAIL_NOTIFY = getattr(settings, 'PAYMENT_PROCESS_EMAIL_NOTIFY', False)
# FIO_BANK_TOKEN = getattr(settings, 'FIO_BANK_TOKEN', 'token')
# FIO_BANK_PROCESS_DAYS = 3
# PAYMENT_ERROR_RATE = getattr(settings, 'PAYMENT_ERROR_RATE', 0)
# PAYPAL_ADDITIONAL_CHARGE = getattr(settings, 'PAYPAL_ADDITIONAL_CHARGE', 2)
# PAYPAL_MODE = getattr(settings, 'PAYPAL_MODE', 'sandbox')
# PAYPAL_CLIENT_ID = getattr(settings, 'PAYPAL_CLIENT_ID', 'client_id')
# PAYPAL_CLIENT_SECRET = getattr(settings, 'PAYPAL_CLIENT_SECRET', 'secret')


# Path: payments/utils.py
from datetime import timedelta
from decimal import Decimal
from django.db.models import Q
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django import VERSION
from fiobank import FioBank
from konfera.models import Order
from konfera.settings import (CURRENCY, EMAIL_NOTIFY_BCC, SITE_URL,
                              UNPAID_ORDER_NOTIFICATION_REPEAT, UNPAID_ORDER_NOTIFICATION_REPEAT_DELAY)
from konfera.utils import send_email
from payments import settings
from payments.models import ProcessedTransaction
    from django.core.urlresolvers import reverse
    from django.urls import reverse
import requests
import logging






if VERSION[1] in (8, 9):
else:


DATE_FORMAT = '%Y-%m-%d'


logger = logging.getLogger(__name__)


def _get_last_payments():
    """ Get list of payments for last three days from FioBank """
    client = FioBank(token=settings.FIO_BANK_TOKEN)

    today = timezone.now()

    date_from = (today - timedelta(days=settings.FIO_BANK_PROCESS_DAYS)).strftime(DATE_FORMAT)