# Path: payway/qiwi/conf/settings.py
# QIWI_ALARM  = getattr(settings, 'QIWI_ALARM', 0)
# 
# QIWI_CREATE  = getattr(settings, 'QIWI_CREATE', False)
# 
# QIWI_SOAP_CLIENT_URL = getattr(settings, 'QIWI_SOAP_CLIENT_URL', 'https://ishop.qiwi.ru/services/ishop?wsdl')
# 
# QIWI_BILL_LIFETIME = getattr(settings, 'QIWI_BILL_LIFETIME', 24)  # hours
# 
# QIWI_DATETIME_FORMAT = getattr(settings, 'QIWI_DATETIME_FORMAT', '%d.%m.%Y %H:%M:%S')
# 
# Path: payway/qiwi/conf/settings.py
# QIWI_LOGIN = getattr(settings, 'QIWI_LOGIN')
# 
# QIWI_PASSWORD = getattr(settings, 'QIWI_PASSWORD')
# 
# XML_SCHEMA_PATH = 'file://' + os.path.join(QIWI_MODULE_PATH, 'templates', 'suds', 'XMLSchema.xml')


import datetime
import logging
from suds.xsd import sxbasic
from suds.client import Client
from payway.qiwi.conf.settings import QIWI_ALARM, QIWI_CREATE, QIWI_SOAP_CLIENT_URL, QIWI_BILL_LIFETIME, QIWI_DATETIME_FORMAT
from payway.qiwi.conf.settings import QIWI_LOGIN, QIWI_PASSWORD, XML_SCHEMA_PATH
class QiwiSoapClientException(Exception):
    pass

class QiwiSoapClient(object):
    url = QIWI_SOAP_CLIENT_URL

    @classmethod
    def createBill(cls, login=QIWI_LOGIN, password=QIWI_PASSWORD, user='', amount='', comment='', txn='', lifetime=QIWI_BILL_LIFETIME, alarm=QIWI_ALARM, create=QIWI_CREATE):
        if len(user) > 10: raise QiwiSoapClientException("User phone number should be less than 10")
        client = Client(cls.url)

        response = client.service.createBill(
            login=login,
            password=password,
            user=user,
            amount=amount,
            comment=comment,
            txn=txn,
            lifetime=cls.hours_to_lifetime(lifetime),
            alarm=alarm,
            create=create)
        return response

    @classmethod
    def hours_to_lifetime(cls, days):
        now = datetime.datetime.now()
        now += datetime.timedelta(days=days)
        return now.strftime(QIWI_DATETIME_FORMAT)

    @classmethod

# Path: payway/qiwi/conf/settings.py
# QIWI_ALARM  = getattr(settings, 'QIWI_ALARM', 0)
# 
# QIWI_CREATE  = getattr(settings, 'QIWI_CREATE', False)
# 
# QIWI_SOAP_CLIENT_URL = getattr(settings, 'QIWI_SOAP_CLIENT_URL', 'https://ishop.qiwi.ru/services/ishop?wsdl')
# 
# QIWI_BILL_LIFETIME = getattr(settings, 'QIWI_BILL_LIFETIME', 24)  # hours
# 
# QIWI_DATETIME_FORMAT = getattr(settings, 'QIWI_DATETIME_FORMAT', '%d.%m.%Y %H:%M:%S')
# 
# Path: payway/qiwi/conf/settings.py
# QIWI_LOGIN = getattr(settings, 'QIWI_LOGIN')
# 
# QIWI_PASSWORD = getattr(settings, 'QIWI_PASSWORD')
# 
# XML_SCHEMA_PATH = 'file://' + os.path.join(QIWI_MODULE_PATH, 'templates', 'suds', 'XMLSchema.xml')


# Path: payway/qiwi/soap/client.py
import datetime
import logging
from suds.xsd import sxbasic
from suds.client import Client
from payway.qiwi.conf.settings import QIWI_ALARM, QIWI_CREATE, QIWI_SOAP_CLIENT_URL, QIWI_BILL_LIFETIME, QIWI_DATETIME_FORMAT
from payway.qiwi.conf.settings import QIWI_LOGIN, QIWI_PASSWORD, XML_SCHEMA_PATH

class QiwiSoapClientException(Exception):
    pass

class QiwiSoapClient(object):
    url = QIWI_SOAP_CLIENT_URL

    @classmethod
    def createBill(cls, login=QIWI_LOGIN, password=QIWI_PASSWORD, user='', amount='', comment='', txn='', lifetime=QIWI_BILL_LIFETIME, alarm=QIWI_ALARM, create=QIWI_CREATE):
        if len(user) > 10: raise QiwiSoapClientException("User phone number should be less than 10")
        client = Client(cls.url)

        response = client.service.createBill(
            login=login,
            password=password,
            user=user,
            amount=amount,
            comment=comment,
            txn=txn,
            lifetime=cls.hours_to_lifetime(lifetime),
            alarm=alarm,
            create=create)
        return response

    @classmethod
    def hours_to_lifetime(cls, days):
        now = datetime.datetime.now()
        now += datetime.timedelta(days=days)
        return now.strftime(QIWI_DATETIME_FORMAT)

    @classmethod

    def cancelBill(cls, login=QIWI_LOGIN, password=QIWI_PASSWORD, txn=''):