Exemplo n.º 1
0
    def __update_channel(self, data, latest, count):
        ChannelConfig.update_channel(**data)

        channels = ChannelConfig.query_all()
        self.assertEqual(count, len(channels))

        all_configs = list(ChannelConfig.filter_latest_items(channels))
        self.assertEqual(latest, len(all_configs))
Exemplo n.º 2
0
    def post(self):
        """
        通道管理: 新建通道
        :return:
        """

        form, error = ChannelAddForm().request_validate()
        if error:
            return error.as_response()

        # if form.start_time.data >= form.end_time.data:
        #     return DateStartMoreThanError().as_response()

        if form.maintain_begin.data:
            if form.maintain_begin.data >= form.maintain_end.data or form.maintain_begin.data < DateTimeKit.get_cur_datetime(
            ):
                return DateStartMoreThanError().as_response()

        if Decimal(form.limit_per_min.data) >= Decimal(
                form.limit_per_max.data):
            return DataStartMoreThanError().as_response()

        if form.limit_day_max.data and Decimal(
                form.limit_per_max.data) > Decimal(form.limit_day_max.data):
            return PerLimitMustLittleDayLimitError().as_response()

        kwargs = dict(fee=form.fee.data,
                      fee_type=form.fee_type.data,
                      limit_per_min=form.limit_per_min.data,
                      limit_per_max=form.limit_per_max.data,
                      limit_day_max=form.limit_day_max.data
                      if form.limit_day_max.data != "" else 0,
                      trade_begin_hour=form.start_time.data.hour,
                      trade_begin_minute=form.start_time.data.minute,
                      trade_end_hour=form.end_time.data.hour,
                      trade_end_minute=form.end_time.data.minute,
                      maintain_begin=form.maintain_begin.data,
                      maintain_end=form.maintain_end.data,
                      settlement_type=form.settlement_type.data,
                      state=form.state.data,
                      priority=form.priority.data)

        rst, error = ChannelConfig.update_channel(form.channel_id.data,
                                                  **kwargs)
        if error:
            return error.as_response()

        # 同步缓存
        # ChannelLimitCacheCtl(PayTypeEnum.DEPOSIT).sync_db_channels_to_cache()

        return ResponseSuccess().as_response()
Exemplo n.º 3
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
Exemplo n.º 4
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'])
Exemplo n.º 5
0
    def init_channel2(cls):
        if not cls.get_deposit_channel2():
            # 充值通道配置
            kwargs = dict(fee="2.5",
                          fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER,
                          limit_per_min="500",
                          limit_per_max="20000",
                          trade_begin_hour="0",
                          trade_begin_minute="0",
                          trade_end_hour="0",
                          trade_end_minute="0",
                          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
                          if cls.merchant.is_test else ChannelStateEnum.ONLINE,
                          priority="101")

            ChannelConfig.update_channel(cls.channel_enum2, **kwargs)
            channel_config = ChannelConfig.query_latest_one(query_fields=dict(
                channel_enum=cls.channel_enum2))
            # print(channel_config)

            # limit_min, limit_max = ChannelLimitCacheCtl(PayTypeEnum.DEPOSIT).get_channel_limit()
            limit_min, limit_max = ChannelListHelper.get_channel_limit_range(
                merchant=cls.merchant,
                payment_way=PayTypeEnum.DEPOSIT,
            )
            # print('limit_min: %s, limit_max: %s' % (limit_min, limit_max))
            assert 0 != limit_min
            assert 0 != limit_max

        if not cls.get_withdraw_channel2():
            # 提款代付通道配置
            withdraw_item = dict(
                fee="1.3",
                fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER,
                limit_per_min="300",
                limit_per_max="10000",
                limit_day_max="500000",
                trade_begin_hour="0",
                trade_begin_minute="0",
                trade_end_hour="0",
                trade_end_minute="0",
                maintain_begin=DateTimeKit.str_to_datetime(
                    "2019-09-07 09:00:00"),
                maintain_end=DateTimeKit.str_to_datetime(
                    "2019-09-07 09:00:00"),
                state=ChannelStateEnum.TESTING
                if cls.merchant.is_test else ChannelStateEnum.ONLINE,
                banks=[
                    PaymentBankEnum.ZHONGGUO,
                    PaymentBankEnum.GONGSHANG,
                    PaymentBankEnum.JIANSHE,
                ])
            ProxyChannelConfig.update_channel(cls.channel_enum2,
                                              **withdraw_item)

            channel_config = ProxyChannelConfig.query_latest_one(
                query_fields=dict(channel_enum=cls.channel_enum2))
            # print(channel_config)

            # limit_min, limit_max = ChannelLimitCacheCtl(PayTypeEnum.WITHDRAW).get_channel_limit()
            limit_min, limit_max = ChannelListHelper.get_channel_limit_range(
                merchant=cls.merchant,
                payment_way=PayTypeEnum.WITHDRAW,
            )
            # print('limit_min: %s, limit_max: %s' % (limit_min, limit_max))
            assert 0 != limit_min
            assert 0 != limit_max