コード例 #1
0
ファイル: reseller.py プロジェクト: Rhizomatica/rccn
 def validate_data(self, pin):
     res_log.debug('Check PIN length')
     if len(pin) > 4 or len(pin) < 4:
         raise ResellerException('PIN invalid length')
 
 
     res_log.debug('Check if Reseller exists')
     # check if reseller exists in the database and the PIN is valid
     try:
         cur = db_conn.cursor()
         cur.execute('SELECT msisdn,pin FROM resellers WHERE msisdn=%(msisdn)s', {'msisdn': str(self.reseller_msisdn)})
         if cur.rowcount > 0:
             res_log.debug('Valid Reseller found')
             res_log.debug('Auth PIN')
             data = cur.fetchone()
             if data[1] != pin:
                 raise ResellerException('Invalid PIN!')
             res_log.debug('Check if subscriber is valid')
             # check if subscriber exists
             try:
                 sub = Subscriber()
                 sub.get(self.subscriber_msisdn)
             except SubscriberException as e:
                 raise ResellerException('Invalid subscriber')
     
         else:
             raise ResellerException('Invalid Reseller')
     except psycopg2.DatabaseError as e:
         raise ResellerException('Database error getting reseller msisdn: %s' % e)
コード例 #2
0
ファイル: reseller.py プロジェクト: ereedsanchez/saycel-1
    def validate_data(self, pin):
        res_log.debug('Check PIN length')
        if len(pin) > 4 or len(pin) < 4:
            raise ResellerException('PIN invalid length')

        res_log.debug('Check if Reseller exists')
        # check if reseller exists in the database and the PIN is valid
        try:
            cur = db_conn.cursor()
            cur.execute(
                'SELECT msisdn,pin FROM resellers WHERE msisdn=%(msisdn)s',
                {'msisdn': str(self.reseller_msisdn)})
            if cur.rowcount > 0:
                res_log.debug('Valid Reseller found')
                res_log.debug('Auth PIN')
                data = cur.fetchone()
                if data[1] != pin:
                    raise ResellerException('Invalid PIN!')
                res_log.debug('Check if subscriber is valid')
                # check if subscriber exists
                try:
                    sub = Subscriber()
                    sub.get(self.subscriber_msisdn)
                except SubscriberException as e:
                    raise ResellerException('Invalid subscriber')

            else:
                raise ResellerException('Invalid Reseller')
        except psycopg2.DatabaseError as e:
            raise ResellerException(
                'Database error getting reseller msisdn: %s' % e)
コード例 #3
0
ファイル: reseller.py プロジェクト: Rhizomatica/rccn
    def add(self, msisdn, pin, balance):
        # check if subscriber exists
        try:
            sub = Subscriber()
            sub.get(msisdn)
        except SubscriberException as e:
            raise ResellerException('Invalid subscriber: %s' % e)

        # provision the reseller
        try:
            cur = db_conn.cursor()
            cur.execute('INSERT INTO resellers(msisdn,pin,balance) VALUES(%(msisdn)s,%(pin)s,%(balance)s)', {'msisdn': msisdn, 'pin': pin, 'balance': Decimal(str(balance))})
            db_conn.commit()
        except psycopg2.DatabaseError as e:
            raise ResellerException('PG_HLR error provisioning reseller: %s' % e)
コード例 #4
0
    def add(self, msisdn, credit):
        sub = Subscriber()
        sms = SMS();
        try:
            mysub = sub.get(msisdn)
        except SubscriberException as e:
            raise CreditException(e)

        current_balance = sub.get_balance(msisdn)
        new_balance = Decimal(str(credit)) + Decimal(str(current_balance))

        # update subscriber balance
        try:
            cur = db_conn.cursor()
            cur.execute('UPDATE subscribers SET balance=%(new_balance)s WHERE msisdn=%(msisdn)s', {'new_balance': Decimal(str(new_balance)), 'msisdn': msisdn})
            sms.send(config['smsc'], msisdn, sms_credit_added % (credit, new_balance))
        except psycopg2.DatabaseError as e:
            raise CreditException('PG_HLR error updating subscriber balance: %s' % e)

        # insert transaction into the credit history
        try:
            cur = db_conn.cursor()
            cur.execute('INSERT INTO credit_history(msisdn,previous_balance,current_balance,amount) VALUES(%s,%s,%s,%s)', (msisdn, current_balance, new_balance, credit))
        except psycopg2.DatabaseError as e:
            db_conn.rollback()
            raise CreditException('PG_HLR error inserting invoice in the history: %s' % e)
        finally:
            db_conn.commit()
コード例 #5
0
ファイル: reseller.py プロジェクト: ereedsanchez/saycel-1
    def add(self, msisdn, pin, balance):
        # check if subscriber exists
        try:
            sub = Subscriber()
            sub.get(msisdn)
        except SubscriberException as e:
            raise ResellerException('Invalid subscriber: %s' % e)

        # provision the reseller
        try:
            cur = db_conn.cursor()
            cur.execute(
                'INSERT INTO resellers(msisdn,pin,balance) VALUES(%(msisdn)s,%(pin)s,%(balance)s)',
                {
                    'msisdn': msisdn,
                    'pin': pin,
                    'balance': Decimal(str(balance))
                })
            db_conn.commit()
        except psycopg2.DatabaseError as e:
            raise ResellerException('PG_HLR error provisioning reseller: %s' %
                                    e)