Ejemplo n.º 1
0
def process_invoices():
    sys.path.append('/opt/ebs/web/')
    sys.path.append('/opt/ebs/web/ebscab/')
    sys.path.append('../../../')
    sys.path.append('../../')
    sys.path.append('.')
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'ebscab.settings'
   
    from paymentgateways.qiwi.models import Invoice
    a = Invoice.objects.filter(autoaccept=False, accepted=False, deleted=False)
    pattern='<bill txn-id="%s"/>'
    p=''
    for x in a:
        p+=pattern % x.id
        
    xml=make_request(params['get_invoices_status'] % p)
    o=xml2obj(xml)
    if status_code(o)[0]!=0: return 
    for x in a:
        if not o.bills_list:continue
        for item in o.bills_list.bill:
            p_code, p_status = payment_code(item)
            if p_code==60 and int(item.id)==x.id:
                x.accepted = True
                x.date_accepted = datetime.datetime.now()
                x.save()
                continue
        if p_code>100:
            x.deleted=True
            x.save()
Ejemplo n.º 2
0
def process_invoices():
    sys.path.append('/opt/ebs/web/')
    sys.path.append('/opt/ebs/web/ebscab/')
    sys.path.append('../../../')
    sys.path.append('../../')
    sys.path.append('.')

    os.environ['DJANGO_SETTINGS_MODULE'] = 'ebscab.settings'

    from paymentgateways.qiwi.models import Invoice
    a = Invoice.objects.filter(autoaccept=False, accepted=False, deleted=False)
    pattern = '<bill txn-id="%s"/>'
    p = ''
    for x in a:
        p += pattern % x.id

    xml = make_request(params['get_invoices_status'] % p)
    o = xml2obj(xml)
    if status_code(o)[0] != 0: return
    for x in a:
        if not o.bills_list: continue
        for item in o.bills_list.bill:
            p_code, p_status = payment_code(item)
            if p_code == 60 and int(item.id) == x.id:
                x.accepted = True
                x.date_accepted = datetime.datetime.now()
                x.save()
                continue
        if p_code > 100:
            x.deleted = True
            x.save()
Ejemplo n.º 3
0
    def create_invoice(phone_number, payment, summ=0, comment=''):
        xml = PaymentProcessor.make_request(
            params['create_invoice'] % {
                "TERMINAL_PASSWORD":
                PaymentProcessor.get_backend_setting('TERMINAL_PASSWORD'),
                "TERMINAL_ID":
                PaymentProcessor.get_backend_setting('TERMINAL_ID'),
                "PHONE":
                phone_number,
                "AMOUNT":
                summ,
                "PAYMENT_ID":
                payment.id,
                'ALARM_SMS':
                PaymentProcessor.get_backend_setting(
                    'ALARM_SMS', PaymentProcessor.ALARM_SMS),
                'ACCEPT_CALL':
                PaymentProcessor.get_backend_setting(
                    'ACCEPT_CALL', PaymentProcessor.ACCEPT_CALL),
                'LIFETIME':
                PaymentProcessor.get_backend_setting(
                    'LIFETIME', PaymentProcessor.LIFETIME),
                'COMMENT':
                u"Оплата за интернет по договору %s" %
                payment.account.contract,
            })

        if not xml: return None
        o = xml2obj(xml)
        status = status_code(o)
        return status
Ejemplo n.º 4
0
def accept_invoice_id(phone, password, transaction_id, date):
    txn_id = get_invoice_id(phone=phone, password=password, transaction_id=transaction_id, date=datetime.datetime.now())
    if txn_id != -1:
        xml = make_request(params['accept_payment'] % (phone, password, txn_id))
        if not xml: return None
        o = xml2obj(xml)
        return status_code(o)
    return -1, result_codes['-1']
Ejemplo n.º 5
0
def accept_invoice_id(phone, password, transaction_id, date):
    txn_id = get_invoice_id(phone=phone,
                            password=password,
                            transaction_id=transaction_id,
                            date=datetime.datetime.now())
    if txn_id != -1:
        xml = make_request(params['accept_payment'] %
                           (phone, password, txn_id))
        if not xml: return None
        o = xml2obj(xml)
        return status_code(o)
    return -1, result_codes['-1']
Ejemplo n.º 6
0
def get_invoice_id(phone, password, transaction_id, date):
    date_start = (date - datetime.timedelta(hours=24)).strftime("%d.%m.%Y")
    date_end = (date + datetime.timedelta(hours=24)).strftime("%d.%m.%Y")
    xml = make_request(params['get_invoices'] % (phone, password, date_start, date_end))
    if not xml: return None
    # print xml
    o = xml2obj(xml)
    if not o.account_list: return -1
    for a in o.account_list.account:
        if a['from'].prv == '%s' % term_id and a.term_ransaction == "%s" % transaction_id:
            return a.id
    return -1
Ejemplo n.º 7
0
def get_balance(phone=None, password=None):
    if not (phone and password):
        xml = make_request(params['get_balance'] % (term_password, term_id))
    if phone and password:
        xml = make_request(params['get_balance'] % (password, phone))
    if not xml: return None
    o = xml2obj(xml)
    status = status_code(o)
    if status[0] == 0:
        if o.extra[0]['name'] == 'BALANCE':
            return o.extra[0].data, status[1]
    else:
        return 0, status[1]
Ejemplo n.º 8
0
def get_invoice_id(phone, password, transaction_id, date):
    date_start = (date - datetime.timedelta(hours=24)).strftime("%d.%m.%Y")
    date_end = (date + datetime.timedelta(hours=24)).strftime("%d.%m.%Y")
    xml = make_request(params['get_invoices'] %
                       (phone, password, date_start, date_end))
    if not xml: return None
    #print xml
    o = xml2obj(xml)
    if not o.account_list: return -1
    for a in o.account_list.account:
        if a['from'].prv == '%s' % term_id and a.term_ransaction == "%s" % transaction_id:
            return a.id
    return -1
Ejemplo n.º 9
0
def get_balance(phone=None, password=None):
    if not (phone and password):
        xml = make_request(params['get_balance'] % (term_password, term_id))
    if phone and password:
        xml = make_request(params['get_balance'] % (password, phone))
    if not xml: return None
    o = xml2obj(xml)
    status = status_code(o)
    if status[0] == 0:
        if o.extra[0]['name'] == 'BALANCE':
            return o.extra[0].data, status[1]
    else:
        return 0, status[1]
Ejemplo n.º 10
0
def create_invoice(phone_number,
                   transaction_id,
                   summ=0,
                   comment='',
                   lifetime=48):
    xml = make_request(params['create_invoice'] % (
        phone_number,
        summ,
        transaction_id,
        lifetime,
        comment,
    ))
    if not xml: return None
    o = xml2obj(xml)
    status = status_code(o)
    return status
Ejemplo n.º 11
0
 def create_invoice(phone_number, payment, summ=0, comment=''):
     xml = PaymentProcessor.make_request(params['create_invoice'] % {
                                                                     "TERMINAL_PASSWORD": PaymentProcessor.get_backend_setting('TERMINAL_PASSWORD'),
                                                                     "TERMINAL_ID":  PaymentProcessor.get_backend_setting('TERMINAL_ID'),
                                                                     "PHONE": phone_number,
                                                                     "AMOUNT": summ, 
                                                                     "PAYMENT_ID": payment.id,
                                                                     'ALARM_SMS': PaymentProcessor.get_backend_setting('ALARM_SMS', PaymentProcessor.ALARM_SMS), 
                                                                     'ACCEPT_CALL': PaymentProcessor.get_backend_setting('ACCEPT_CALL', PaymentProcessor.ACCEPT_CALL),
                                                                     'LIFETIME': PaymentProcessor.get_backend_setting('LIFETIME', PaymentProcessor.LIFETIME),
                                                                     'COMMENT': u"Оплата за интернет по договору %s" % payment.account.contract,
                                                                     })
     
     if not xml: return None
     o=xml2obj(xml)
     status = status_code(o)
     return status
Ejemplo n.º 12
0
def create_invoice(phone_number, transaction_id, summ=0, comment='', lifetime=48):
    xml = make_request(params['create_invoice'] % (phone_number, summ, transaction_id, lifetime, comment,))
    if not xml: return None
    o = xml2obj(xml)
    status = status_code(o)
    return status
Ejemplo n.º 13
0
    except Exception, x:
        print "I am unable to connect to the database: %s" % x

    cur.execute("SELECT id, phone, summ, account_id, login, type, email, phone_sms FROM payments_qiwi WHERE accepted=false AND deleted=false")
    a = cur.fetchall()
    if not a:
        return
    pattern = '<bill txn-id="%s"/>'
    p = ''
    for x in a:
        p += pattern % x[0]
    log.info(str(p))
    # exit()
    xml = make_request(params['get_invoices_status'] % p)
    log.info("xml='%s'" % xml)
    o = xml2obj(xml)
    if status_code(o)[0] != 0: return

    for x in a:
        log.info('x=%s' % str(x))
        p_code = p_status = ''
        for item in o.bills_list.bill:
            # log.info("item.id='%s'" % (item.id,))
            try:
                if int(item.id) == x[0]:
                    p_code, p_status = payment_code(item)
                    break
            except:
                continue
        log.info("item.id='%s' p_code='%s' p_status='%s'" % (item.id, p_code, p_status))
        if not p_code or not p_status: