示例#1
0
    def post(self):
        """
        充值请求
        """
        if not EnvironEnum.is_local_evn(current_app.config['FLASK_ENV']):
            # 无论如何都记录一条log
            current_app.logger.info('path: %s, ip: %s, args: %s, data: %s',
                                    url_for("gateway_config_get"),
                                    IpKit.get_remote_ip(), request.args,
                                    request.json)

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

        merchant = form.merchant_id.data

        checker = GatewayFormChecker(merchant)

        # 1. IP白名单校验
        if not checker.verify_ip(form.client_ip.data):
            current_app.logger.error('msg: %s, ip: %s, white ips: %s',
                                     GatewayIPError.message,
                                     IpKit.get_remote_ip(),
                                     checker.get_white_ips())
            return GatewayIPError().as_response()

        # 2. 签名校验
        sign_fields = form.get_sign_fields()
        if not checker.verify_sign(form.sign.data, sign_fields):
            current_app.logger.error(
                'msg: %s, sign: %s, fields: %s, sign_str: %s',
                GatewaySignError.message, form.sign.data, sign_fields,
                checker.get_sign_str(sign_fields))
            return GatewaySignError().as_response()

        # 3. 返回可用的支付方式以及限额
        # 充值每种支付类型的限额
        payment_types = ChannelListHelper.get_channels_for_gateway(
            merchant,
            PayTypeEnum.DEPOSIT,
            client_ip=form.user_ip.data,
        )
        # 提现限额
        # limit_min, limit_max = ChannelLimitCacheCtl(PayTypeEnum.WITHDRAW).get_channel_limit()
        limit_min, limit_max = ChannelListHelper.get_channel_limit_range(
            merchant=merchant,
            payment_way=PayTypeEnum.WITHDRAW,
            client_ip=form.user_ip.data,
        )

        withdraw_config = dict(
            limit_min=limit_min,  # 最小限额列表的最小值
            limit_max=limit_max,  # 最大限额列表的最大值
        )

        return GatewayResponseConfig(bs_data=dict(
            payment_types=payment_types,
            withdraw_config=withdraw_config,
        )).as_response()
示例#2
0
    def post(self):
        """
        获取单笔交易最低最高限额
        """
        form, error = DomainForm().request_validate()
        if error:
            return error.as_response()

        # 获取用户余额
        uid = g.user.uid
        merchant = g.user.merchant

        user_balance = UserBalance.query_balance(uid=uid,
                                                 merchant=merchant).first()

        # limit_min, limit_max = ChannelLimitCacheCtl(PayTypeEnum.WITHDRAW).get_channel_limit()
        limit_min, limit_max = ChannelListHelper.get_channel_limit_range(
            merchant=merchant,
            payment_way=PayTypeEnum.WITHDRAW,
            client_ip=form.client_ip.data,
        )

        deposit_limit_config = dict(
            balance=user_balance.real_balance,
            limit_min=limit_min,
            limit_max=limit_max,
        )
        return ResponseWithdrawLimitConfig(
            bs_data=deposit_limit_config).as_response()
示例#3
0
    def post(self):
        """
        获取单笔交易最低最高限额
        """
        form, error = DomainForm().request_validate()
        if error:
            return error.as_response()

        merchant = form.merchant.data

        # limit_min, limit_max = ChannelLimitCacheCtl(PayTypeEnum.DEPOSIT).get_channel_limit()
        limit_min, limit_max = ChannelListHelper.get_channel_limit_range(
            merchant=merchant,
            payment_way=PayTypeEnum.DEPOSIT,
            client_ip=form.client_ip.data,
        )

        return ResponseDepositLimitConfig(bs_data=dict(
            limit_min=limit_min, limit_max=limit_max)).as_response()
示例#4
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