Esempio n. 1
0
    def charge(json_data):
        if 'id' in json_data.keys():
            mer_id = json_data['id']
        else:
            raise InvalidMerchantException

        amount = json_data['amount'] if 'amount' in json_data.keys() else 123

        # 根据mer_id获取商户数据
        db = Sqlite()
        merchant = db.get_upmp_data_by_merid(mer_id)

        if not merchant:
            # 更新商户数据库
            repo = RepoGit("../data/")
            repo.pull()

            # 商户数据不存在,则抛出异常
            if not os.path.isfile(os.path.join("data/2014", mer_id + ".txt")):
                raise InvalidMerchantException

            mer_name, mer_key = UpmpHandler.get_merchant_info_by_merid(
                "data/2014/", mer_id)
            db.set_upmp_basic_info(mer_name, mer_id, mer_key)
            merchant = db.get_upmp_data_by_merid(mer_id)

        if not merchant or not merchant['sk']:
            raise InvalidMerchantException

        # 交易请求
        mer_key = merchant['sk']
        uc = UpmpChannel(mer_id, mer_key)
        ret = uc.charge(amount)

        if not ret:
            raise ChargeFailException

        print(ret)
        post_data, res_data, req_dict, res_dict = ret

        res = dict()
        res['upmp'] = dict()
        res['upmp']['tn'] = res_dict['tn']
        res['upmp']['mode'] = '01'

        if not merchant['charge_notify']:
            print('=========charge========')
            db.set_upmp_charge_data(mer_id, post_data, res_data)

        return res
Esempio n. 2
0
    def charge(json_data):
        if 'id' in json_data.keys():
            mer_id = json_data['id']
        else:
            raise InvalidMerchantException

        amount = json_data['amount'] if 'amount' in json_data.keys() else 123

        # 根据mer_id获取商户数据
        db = Sqlite()
        merchant = db.get_upmp_data_by_merid(mer_id)

        if not merchant:
            # 更新商户数据库
            repo = RepoGit("../data/")
            repo.pull()

            # 商户数据不存在,则抛出异常
            if not os.path.isfile(os.path.join("data/2014", mer_id + ".txt")):
                raise InvalidMerchantException

            mer_name, mer_key = UpmpHandler.get_merchant_info_by_merid("data/2014/", mer_id)
            db.set_upmp_basic_info(mer_name, mer_id, mer_key)
            merchant = db.get_upmp_data_by_merid(mer_id)

        if not merchant or not merchant['sk']:
            raise InvalidMerchantException

        # 交易请求
        mer_key = merchant['sk']
        uc = UpmpChannel(mer_id, mer_key)
        ret = uc.charge(amount)

        if not ret:
            raise ChargeFailException

        print(ret)
        post_data, res_data, req_dict, res_dict = ret

        res = dict()
        res['upmp'] = dict()
        res['upmp']['tn'] = res_dict['tn']
        res['upmp']['mode'] = '01'

        if not merchant['charge_notify']:
            print('=========charge========')
            db.set_upmp_charge_data(mer_id, post_data, res_data)

        return res
Esempio n. 3
0
    def notify(data):
        notify_data = data
        notify_dict = urlparse.parse_qs(data)
        notify_dict = {key: notify_dict[key][0] for key in notify_dict}
        mer_id = notify_dict['merId']

        db = Sqlite()
        merchant = db.get_upmp_data_by_merid(mer_id)

        if not merchant or not merchant['sk']:
            raise InvalidMerchantException

        mer_key = merchant['sk']
        uc = UpmpChannel(mer_id, mer_key)
        notify_dict = uc.notify(notify_data)
        UpmpHandler.to_log(notify_data, notify_dict, mer_id, uc)

        return
Esempio n. 4
0
    def notify(data):
        notify_data = data
        notify_dict = urlparse.parse_qs(data)
        notify_dict = {key: notify_dict[key][0] for key in notify_dict}
        mer_id = notify_dict['merId']

        db = Sqlite()
        merchant = db.get_upmp_data_by_merid(mer_id)

        if not merchant or not merchant['sk']:
            raise InvalidMerchantException

        mer_key = merchant['sk']
        uc = UpmpChannel(mer_id, mer_key)
        notify_dict = uc.notify(notify_data)
        UpmpHandler.to_log(notify_data, notify_dict, mer_id, uc)

        return