Esempio n. 1
0
    def post(self):
        """
        商户编辑 编辑费率
        """
        # 验证费率表单
        form, error = EditMerchantRateForm().request_validate()
        if error:
            return error.as_response()

        merchant = form.data['name']
        merchant_fee_dict = []

        for item in form.deposit_info:
            merchant_fee_dict.append(dict(
                merchant=merchant,
                payment_way=PayTypeEnum.DEPOSIT,
                value=item.data['value'],
                fee_type=item.data['fee_type'],
                payment_method=item.data['name'],
            ))

        if form.withdraw_info.data['value']:
            merchant_fee_dict.append(dict(
                merchant=merchant,
                payment_way=PayTypeEnum.WITHDRAW,
                value=form.withdraw_info.data['value'],
                fee_type=form.withdraw_info.data['fee_type'],
                cost_type=form.withdraw_info.data['cost_type'],
            ))

        MerchantFeeConfig.update_fee_config(merchant, merchant_fee_dict)

        return ResponseSuccess().as_response()
Esempio n. 2
0
    def init_merchant(cls):
        # 先创建商户
        if not cls.get_merchant_info():
            MerchantInfo.create_merchant(m_name=cls.merchant,
                                         m_type=MerchantTypeEnum.TEST)

            # 给商户加钱
            rst, msg = MerchantBalanceEvent.update_balance(
                merchant=cls.merchant,
                ref_id=OrderUtils.gen_unique_ref_id(),
                source=OrderSourceEnum.MANUALLY,
                order_type=PayTypeEnum.MANUALLY,
                bl_type=BalanceTypeEnum.AVAILABLE,
                ad_type=BalanceAdjustTypeEnum.PLUS,
                tx_id=OrderUtils.gen_normal_tx_id(10),
                value=100000000,
                comment="手动脚本修改商户可用余额")
            # print(rst, msg)

        merchant_fee_list = list()
        if not cls.get_merchant_fee_config(PayTypeEnum.DEPOSIT):
            # 商户费率配置
            merchant_fee_list.append(
                dict(
                    merchant=cls.merchant,
                    payment_way=PayTypeEnum.DEPOSIT,
                    value="3",
                    fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER,
                    payment_method=cls.channel_enum.conf.payment_method,
                ))
            MerchantFeeConfig.update_fee_config(cls.merchant,
                                                merchant_fee_list)

            # 商户费率配置
            merchant_fee_list.append(
                dict(
                    merchant=cls.merchant,
                    payment_way=PayTypeEnum.DEPOSIT,
                    value="3",
                    fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER,
                    payment_method=cls.channel_enum2.conf.payment_method,
                ))
            MerchantFeeConfig.update_fee_config(cls.merchant,
                                                merchant_fee_list)

        if not cls.get_merchant_fee_config(PayTypeEnum.WITHDRAW):
            merchant_fee_list.append(
                dict(merchant=cls.merchant,
                     payment_way=PayTypeEnum.WITHDRAW,
                     value="3.2",
                     fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER))
            MerchantFeeConfig.update_fee_config(cls.merchant,
                                                merchant_fee_list)

        merchant_config = cls.get_merchant_fee_config(PayTypeEnum.DEPOSIT)
        assert merchant_config.fee_type == PaymentFeeTypeEnum.PERCENT_PER_ORDER

        merchant_config = cls.get_merchant_fee_config(PayTypeEnum.WITHDRAW)
        assert merchant_config.fee_type == PaymentFeeTypeEnum.PERCENT_PER_ORDER
Esempio n. 3
0
    def post(self):
        """
        新建商户 新增费率
        """
        form, error = MerchantFeeAddForm().request_validate()
        if error:
            return error.as_response()

        # 充值费率设置
        for item in form.deposit_info:
            if not isinstance(item.data['value'], str):
                return ParameterException(message="充值费率必须传入字符串类型").as_response()

        # 提现费率
        if not isinstance(form.withdraw_info.data['value'], str):
            return ParameterException(message="提现费率必须传入字符串类型").as_response()

        merchant = form.data['name']

        # 第一步向数据库中插入商户数据
        models = MerchantInfo.create_merchant_models(merchant, form.data['type'])

        # 充值费率设置
        merchant_fee_dict = []
        for item in form.deposit_info:
            merchant_fee_dict.append(dict(
                merchant=merchant,
                payment_way=PayTypeEnum.DEPOSIT,
                value=item.data['value'],
                fee_type=item.data['fee_type'],
                payment_method=item.data['name'],
            ))

        # 提现费率
        merchant_fee_dict.append(dict(
            merchant=merchant,
            payment_way=PayTypeEnum.WITHDRAW,
            value=form.withdraw_info.data['value'],
            fee_type=form.withdraw_info.data['fee_type'],
            cost_type=form.withdraw_info.data['cost_type'],
        ))

        rst, error = MerchantFeeConfig.update_fee_config(merchant, merchant_fee_dict, models)
        if error:
            return error.as_response()

        return ResponseSuccess().as_response()
Esempio n. 4
0
    def __test_callback_ponypay_deposit(self):
        self.path = "/callback/ponypay/deposit"

        # 初始化数据
        kwargs = dict(
            fee="2.5",
            fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER,
            limit_per_min="200",
            limit_per_max="10000",
            trade_begin_hour="00",
            trade_begin_minute="00",
            trade_end_hour="23",
            trade_end_minute="59",
            maintain_begin=DateTimeKit.str_to_datetime("2019-09-07 09:00:00"),
            maintain_end=DateTimeKit.str_to_datetime("2019-09-07 09:00:00"),
            settlement_type=SettleTypeEnum.D0,
            state=ChannelStateEnum.TESTING,
            priority="101")
        rst, error = ChannelConfig.update_channel(
            ChannelConfigEnum.CHANNEL_1001, **kwargs)
        self.assertEqual(rst, True)
        self.assertEqual(error, None)
        # ChannelLimitCacheCtl(PayTypeEnum.DEPOSIT).sync_db_channels_to_cache()

        merchant = MerchantEnum.TEST
        merchant_fee_list = [
            dict(merchant=merchant,
                 payment_way=PayTypeEnum.DEPOSIT,
                 value="3",
                 fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER,
                 payment_method=PayMethodEnum.ZHIFUBAO_SAOMA),
            dict(merchant=merchant,
                 payment_way=PayTypeEnum.WITHDRAW,
                 value="3.2",
                 fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER)
        ]

        ret, error = MerchantFeeConfig.update_fee_config(
            merchant, merchant_fee_list)
        self.assertEqual(rst, True)
        self.assertEqual(error, None)

        info = dict(
            account="+8618977772222",
            merchant=MerchantEnum.TEST,
            ac_type=AccountTypeEnum.MOBILE,
            login_pwd="123456789",
        )
        MerchantInfo.create_merchant(MerchantEnum.TEST, MerchantTypeEnum.TEST)
        user = User.register_account(merchant=info['merchant'],
                                     account=info['account'],
                                     ac_type=info['ac_type'],
                                     login_pwd=info['login_pwd'])

        uid = user.id
        channel_config = ChannelConfig.query_latest_one(query_fields=dict(
            channel_enum=ChannelConfigEnum.CHANNEL_1001))
        channel_conf = ChannelConfigEnum.CHANNEL_1001.conf
        channel_conf['white_ip'].append("127.0.0.1")
        merchant_fee = MerchantFeeConfig.query_latest_one(
            query_fields=dict(merchant=MerchantEnum.TEST,
                              payment_way=PayTypeEnum.DEPOSIT,
                              payment_method=channel_conf.payment_method))

        self.__test_callback_order_success(uid, channel_config, merchant_fee,
                                           '1')
        self.__test_callback_order_success(uid, channel_config, merchant_fee,
                                           '-1')

        stop = 1
Esempio n. 5
0
 def add_one_config(self, merchant, params):
     MerchantFeeConfig.update_fee_config(merchant, params)
     for conf_dict in params:
         self.check_result(conf_dict)
Esempio n. 6
0
    def __test_api_withdraw(self):
        """
        后台准备数据:
            充值通道数据
            代付通道数据
            商户费率配置数据

        钱包端:
            1. 创建充值订单
            2. 充值
            3. 用户设置支付密码
            4. 用户绑定银行卡
            5. 获取充值配置信息(用户余额,充值最低最高限制)

        发起提现请求:

        :return:
        """
        merchant = MerchantEnum.from_name("TEST")
        info = dict(merchant=merchant,
                    account="+8618988888888",
                    auth_code="8888",
                    password="******",
                    trade_pwd="b943a52cc24dcdd12bf2ba3afda92351",
                    ac_type=AccountTypeEnum.MOBILE)
        user = User.register_account(info['merchant'], info['account'],
                                     info['ac_type'], info['password'])

        self.path = '/auth/account/login'

        login_data = dict(number=info['account'], password=info['password'])
        response = self.do_request(login_data)
        self.assertEqual(ResponseSuccessLogin.code, response.status_code)
        self.assertEqual(ResponseSuccessLogin.error_code,
                         response.json['error_code'])
        self.token = response.json['data']['token']

        self.path = "/withdraw/banks/list"

        # 1. 向数据库添加代付通道信息
        withdraw_item = dict(fee="2.5",
                             fee_type=PaymentFeeTypeEnum(1),
                             limit_per_min="200",
                             limit_per_max="5000",
                             limit_day_max="50000",
                             trade_begin_hour="00",
                             trade_begin_minute="00",
                             trade_end_hour="23",
                             trade_end_minute="59",
                             maintain_begin=DateTimeKit.str_to_datetime(
                                 "2019-09-27 00:00:00",
                                 DateTimeFormatEnum.SECONDS_FORMAT),
                             maintain_end=DateTimeKit.str_to_datetime(
                                 "2019-10-20 23:59:00",
                                 DateTimeFormatEnum.SECONDS_FORMAT),
                             state=ChannelStateEnum(10),
                             banks=[
                                 PaymentBankEnum(1),
                                 PaymentBankEnum(2),
                                 PaymentBankEnum(4),
                                 PaymentBankEnum(3),
                                 PaymentBankEnum(15)
                             ])

        ProxyChannelConfig.update_channel(ChannelConfigEnum.CHANNEL_1001,
                                          **withdraw_item)

        # 2. 向数据库插入 商户费率配置信息
        # 充值费率设置
        merchant_fee_dict = []
        merchant_fee_dict.append(
            dict(
                merchant=MerchantEnum.from_name('TEST'),
                payment_way=PayTypeEnum.DEPOSIT,
                value="3.5",
                fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER,
                payment_method=PayMethodEnum.ZHIFUBAO_SAOMA,
            ))

        # 提现费率
        merchant_fee_dict.append(
            dict(
                merchant=MerchantEnum.from_name('TEST'),
                payment_way=PayTypeEnum.WITHDRAW,
                value="3.5",
                fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER,
            ))

        rst, error = MerchantFeeConfig.update_fee_config(
            merchant, merchant_fee_dict)
        self.assertEqual(True, rst)

        # 3. 给用户和商户充值
        uid = user.uid

        ref_id = hashlib.md5('lakjdflasjfadl;kfja'.encode('utf8')).hexdigest()

        data = dict(
            uid=uid,
            merchant=merchant,
            ref_id=ref_id,
            source=OrderSourceEnum.TESTING,
            order_type=PayTypeEnum.DEPOSIT,
            bl_type=BalanceTypeEnum.AVAILABLE,
            ad_type=BalanceAdjustTypeEnum.PLUS,
            tx_id=OrderUtils.gen_normal_tx_id(uid),
            value=Decimal("10000.00"),
            comment="xxx",
        )
        rst, msg = UserBalanceEvent.update_user_balance(**data)
        self.assertEqual(0, rst)

        balance = UserBalance.query_balance(data['uid'],
                                            data['merchant']).first()

        # 添加商户余额
        data = dict(
            merchant=MerchantEnum.TEST,
            source=OrderSourceEnum.TESTING,
            order_type=PayTypeEnum.DEPOSIT,
            bl_type=BalanceTypeEnum.AVAILABLE,
            ad_type=BalanceAdjustTypeEnum.PLUS,
            tx_id=OrderUtils.gen_normal_tx_id(100),
            value=Decimal("10000.00"),
            comment=msg,
        )

        ref_id = hashlib.md5(
            RandomString.gen_random_str(
                length=128).encode('utf8')).hexdigest()
        data['ref_id'] = ref_id
        event_check = dict(total=1)
        event_check.update(data)
        rst, msg = MerchantBalanceEvent.update_balance(**data)

        self.assertEqual(0, rst)

        # 设置支付密码
        flag = User.set_payment_password(merchant,
                                         uid=uid,
                                         trade_pwd=info["trade_pwd"])

        self.assertEqual(True, flag)

        # 绑定银行卡
        bank_info = {
            "payment_password": info['trade_pwd'],
            "bank_name": "中国工商银行",
            "bank_code": "ICBC",
            "card_no": "6212260405014627955",
            "account_name": "张三",
            "branch": "广东东莞东莞市长安镇支行",
            "province": "广东省",
            "city": "东莞市"
        }

        flag = BankCard.add_bank_card(merchant,
                                      uid=uid,
                                      bank_name=bank_info['bank_name'],
                                      bank_code=bank_info['bank_code'],
                                      card_no=bank_info['card_no'],
                                      account_name=bank_info['account_name'],
                                      branch=bank_info['branch'],
                                      province=bank_info['province'],
                                      city=bank_info['city'])
        self.assertEqual(bank_info['card_no'], flag.card_no)

        self.path = "/withdraw/limit/config/get"
        response = self.do_request()
        self.assertEqual(ResponseBankWithdraw.code, response.status_code)
        self.assertEqual(ResponseBankWithdraw.error_code,
                         response.json['error_code'])
        self.assertEqual("10000", response.json['data']['balance'])
        self.assertEqual("200", response.json['data']['limit_min'])
        self.assertEqual("5000", response.json['data']['limit_max'])

        self.path = "/withdraw/order/create"
        create_data = dict(amount=1000.001,
                           user_bank=1,
                           trade_password=info['trade_pwd'])

        # 测试小于 最低限额

        create_data['amount'] = 100

        response = self.do_request(json_data=create_data)
        self.assertEqual(WithdrawOrderAmountInvalidError.code,
                         response.status_code)
        self.assertEqual(WithdrawOrderAmountInvalidError.error_code,
                         response.json['error_code'])

        create_data['amount'] = 6000

        response = self.do_request(json_data=create_data)
        self.assertEqual(WithdrawOrderAmountInvalidError.code,
                         response.status_code)
        self.assertEqual(WithdrawOrderAmountInvalidError.error_code,
                         response.json['error_code'])

        create_data['amount'] = str(500.56)
        create_data['user_bank'] = 100

        response = self.do_request(json_data=create_data)
        self.assertEqual(WithdrawBankNoExistError.code, response.status_code)
        self.assertEqual(WithdrawBankNoExistError.error_code,
                         response.json['error_code'], response.json['message'])

        use_balance = UserBalance.query_balance(user.uid, merchant).first()
        ori_merchant = MerchantInfo.query_merchant(merchant)

        balance = ori_merchant.bl_ava - BalanceKit.round_4down_5up(
            Decimal(create_data['amount'])) * 100 - BalanceKit.round_4down_5up(
                Decimal(create_data['amount']) * Decimal(3.5))
        merchant_balance = BalanceKit.round_4down_5up(
            balance / Decimal(100)) * 100

        u_balance = BalanceKit.round_4down_5up(
            Decimal(use_balance.balance) / Decimal(100) -
            Decimal(create_data['amount'])) * Decimal(100)
        create_data['user_bank'] = 1

        response = self.do_request(json_data=create_data)
        self.assertEqual(ResponseSuccess.code, response.status_code)
        self.assertEqual(ResponseSuccess.error_code,
                         response.json['error_code'])

        cur_balance = UserBalance.query_balance(user.uid, merchant).first()
        cur_merchant = MerchantInfo.query_merchant(merchant)

        self.assertEqual(int(merchant_balance), int(cur_merchant.bl_ava))
        self.assertEqual(int(u_balance), int(cur_balance.balance))
Esempio n. 7
0
    def __test_api_deposit(self):
        self.path = "/auth/account/register"
        register_data = dict(number="+8618912341234",
                             auth_code="8888",
                             password="******")

        response = self.do_request(register_data)
        self.assertEqual(ResponseSuccess.code, response.status_code)
        self.assertEqual(ResponseSuccess.error_code,
                         response.json['error_code'])

        self.path = '/auth/account/login'

        login_data = dict(number="+8618912341234",
                          password="******")
        response = self.do_request(login_data)
        print(response.json)
        self.assertEqual(ResponseSuccessLogin.code, response.status_code)
        self.assertEqual(ResponseSuccessLogin.error_code,
                         response.json['error_code'])
        self.token = response.json['data']['token']

        kwargs = dict(
            fee="2.5",
            fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER,
            limit_per_min="200",
            limit_per_max="10000",
            trade_begin_hour="00",
            trade_begin_minute="00",
            trade_end_hour="23",
            trade_end_minute="59",
            maintain_begin=DateTimeKit.str_to_datetime("2019-09-07 09:00:00"),
            maintain_end=DateTimeKit.str_to_datetime("2019-09-07 09:00:00"),
            settlement_type=SettleTypeEnum.D0,
            state=ChannelStateEnum.TESTING,
            priority="101")

        # print(channel1['channel_id'])
        ChannelConfig.update_channel(ChannelConfigEnum.CHANNEL_1001, **kwargs)

        merchant = MerchantEnum.TEST
        merchant_fee_list = [
            dict(merchant=merchant,
                 payment_way=PayTypeEnum.DEPOSIT,
                 value="3",
                 fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER,
                 payment_method=PayMethodEnum.ZHIFUBAO_SAOMA),
            dict(merchant=merchant,
                 payment_way=PayTypeEnum.WITHDRAW,
                 value="3.2",
                 fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER)
        ]

        ret, error = MerchantFeeConfig.update_fee_config(
            merchant, merchant_fee_list)

        self.path = "/deposit/limit/config/get"
        response = self.do_request()
        self.assertEqual(ResponseDepositLimitConfig.code, response.status_code)
        self.assertEqual(ResponseDepositLimitConfig.error_code,
                         response.json['error_code'])

        self.path = "/deposit/payment/type/list"
        response = self.do_request(dict(amount=500))
        self.assertEqual(ResponsePaymentType.code, response.status_code)
        self.assertEqual(ResponsePaymentType.error_code,
                         response.json['error_code'], response.json['message'])

        self.path = "/deposit/order/create"
        create_order_data = dict(
            payment_type="20",
            amount="400.03",
            channel_id=ChannelConfigEnum.CHANNEL_1001.value,
        )

        response = self.do_request(create_order_data)
        self.assertEqual(InvalidDepositPaymentTypeError.code,
                         response.status_code)
        self.assertEqual(InvalidDepositPaymentTypeError.error_code,
                         response.json['error_code'], response.json['message'])

        # create_order_data['payment_type'] = '10'
        # response = self.do_request(create_order_data)
        # self.assertEqual(ResponseSuccess.code, response.status_code)
        # self.assertEqual(ResponseSuccess.error_code, response.json['error_code'])

        # create_order_data['channel_id'] = '105'
        # response = self.do_request(create_order_data)
        # self.assertEqual(InvalidDepositChannelError.code, response.status_code)
        # self.assertEqual(InvalidDepositChannelError.error_code, response.json['error_code'])

        # create_order_data['channel_id'] = '101'
        # create_order_data['payment_type'] = "20"
        # response = self.do_request(create_order_data)
        # self.assertEqual(ChannelNoValidityPeriodError.code, response.status_code)
        # self.assertEqual(ChannelNoValidityPeriodError.error_code, response.json['error_code'])

        # create_order_data['payment_type'] = "30"
        # create_order_data['channel_id'] = '107'
        # response = self.do_request(create_order_data)
        # self.assertEqual(ResponseSuccess.code, response.status_code)
        # self.assertEqual(ResponseSuccess.error_code, response.json['error_code'])

        self.path = "/user/balance/get"
        response = self.do_request()
        print(response.json)
        self.assertEqual(ResponseUserBalance.code, response.status_code)
        self.assertEqual(ResponseUserBalance.error_code,
                         response.json['error_code'])