示例#1
0
文件: api.py 项目: ajiboyemary/phd2
    def POST(tablename, revnum, **fields):
        if not tablename == 'rev_charged': raise HTTP(401, json.dumps({'message': 'Bad Request'}))
        #test for revcard
        if not db.rev_wallet(revnumber=revnum):
            raise HTTP(404, json.dumps({'message': 'Invalid revcard'}))
        if (db.rev_wallet(revnumber=revnum).amount < float(request.vars.amount)):
            raise HTTP(402, json.dumps({'message':'insuficient fund'}))

        ret=db.rev_charged.validate_and_insert(wallet=db.rev_wallet(revnumber=revnum).id, **fields)
        if ret.errors:
            raise HTTP(401, json.dumps(ret.errors.as_dict()))
        # reconcille account
        reconcilled = myutils.reconcile(revnum)

        return dict(message='Charge successfully posted!', charge=db.rev_charged(id=ret.id))
示例#2
0
文件: api.py 项目: ajiboyemary/phd2
def getsms():

    response.view = 'generic.json'
    phone = request.vars['phone']
    msg = request.vars['text']
    smscenter = request.vars['smscenter']

    #split msg
    args = msg.split()
    if not args:
        raise HTTP(401, json.dumps({'msg': 'Bad Request'}))
    else:

        SA = 'EdoSRS'
        DA = str(phone)[1:]
        M = ''
        #Check Balance
        if args[0].upper() == 'BAL':
            # call getbalance api
            reventry = db.rev_wallet(revnumber=args[1])
            if not reventry:
                M = 'Balance Check unsuccessful; Wrong Revenue Card Number'
                rs = myutils.sendSMS(DA, SA, M)
                raise HTTP(401, json.dumps({'msg' : 'wrong revcard'}))
            else:

                M = 'Your Account Bal is NGN' + str(reventry['amount'])
                return dict(msg = reventry['amount'], result=myutils.sendSMS(DA, SA, M))

        # load RFID card
        elif args[0].upper() == 'LOAD':

            if not db.scratch_card(scratch_number=args[2]):
                M = 'Error loading account; Wrong Rechard Card Number'
                myutils.sendSMS(DA, SA, M)
                raise HTTP(401, json.dumps({'msg' : 'wrong recharge card'}))
            if not db.rev_wallet(revnumber = args[1]):
                M = 'Error loading account; wrong Revenue Card Number'
                myutils.sendSMS(DA, SA, M)

                raise HTTP(401, json.dumps({'msg' : 'wrong revcard'}))

            qryscratch = db.scratch_card.scratch_number == args[2]
            qryrev = db.rev_wallet.revnumber == args[1]
            scratch = db(qryscratch).select().first()
            rev = db(qryrev).select().first()
            rec = rev.update_record(amount = rev.amount + scratch.amount)

            M = 'Your Account Bal. is NGN' + str(db.rev_wallet(id = rec).amount)
            rs = myutils.sendSMS(DA, SA, M)
            return dict(record=rec, rs=rs)

        # Make Payment
        elif args[0].upper() == 'PAY':
            #check if Pay with TIN i.e 'pay tinNum scratchcardnumber
            #if len(args) == 3:
            qryrev = db.rev_wallet.revnumber == args[1]
            #Check Validity of pin
            if not db.rev_wallet(revnumber = args[1]):
                M = 'Invalid pin number'
                #rs = myutils.sendSMS(DA, SA, M)
                raise HTTP(404, json.dumps({'msg' : M}))
            else:
                #Post-charge
                revwallet = db(db.rev_wallet.revnumber == args[1]).select().first()
                ret=db.rev_charged.validate_and_insert(device=2,
                                                       wallet=revwallet.id,
                                                       amount=revwallet.amount,
                                                       time_charged='now',
                                                       reconcilled='no',
                                                       receipt_issued=1
                                                      )
                #raise HTTP(410, json.dumps({'ID':ret.id}))
                if ret.errors:
                    myutils.sendSMS(DA, SA, 'Error Paying; pls try again')
                    raise HTTP(401, json.dumps({'msg' : 'insert errors'}))
                else:
                    Tin = None
                    if len(args) == 3: Tin = args[2] # if it is pay with the TIN
                    result = myutils.reconcile(args[1])
                    gencode = random.randint(100000,999999)
                    confirm = db.confirmation.validate_and_insert(code=gencode,
                                                                  tin=Tin,
                                                                  pin=revwallet.id,
                                                                  amount=db.rev_charged(id=ret.id).amount,
                                                                  phone_no=DA,
                                                                 )



                    M = 'Your Smart Wallet code is ' + str(gencode) + '; with a balance of NGN' + str(db.rev_charged(id=ret.id).amount) + ' pls proceed to your service points to make your payment'
                    rs = myutils.sendSMS(DA, SA, M)
                    return dict(msg=M, rs=rs, code=str(gencode), amount=str(db.rev_charged(id=ret.id).amount))


        else:
            return dict(msg = 'Error in message sent')


    return locals() #dict(phone=phone, smscenter=smscenter, msg=msg)