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
def __test_api_channel(self): # 充值通道管理 新增通道 channel_enum = ChannelConfigEnum.CHANNEL_1001 post_data = dict(channel_id=channel_enum.value, fee="2.3", fee_type="1", limit_per_min="2000", limit_per_max="50000", limit_day_max="50000", start_time="09:00", end_time="23:59", state="10", settlement_type="1", priority="1") post_data["state"] = 10 # 数值型参数类型错误 self.path = '/channel/deposit/add' response = self.do_request(post_data) self.assertEqual(response.status_code, ParameterException.code) self.assertEqual(response.json['error_code'], ParameterException.error_code) # print(response.json['message'], "this field must be String type") post_data["state"] = "10" # 测试交易日期为空的情况 response = self.do_request(post_data) print(response.json) self.assertEqual(ResponseSuccess.code, response.status_code, response.json['message']) self.assertEqual(ResponseSuccess.error_code, response.json['error_code'], response.json['message']) # print(response.json['message'], "this field must be String type") post_data['maintain_begin'] = "2019-09-27 09:10:00" post_data['maintain_end'] = "2019-10-20 23:09:00" # 测试每笔交易上限大于日交易上限 post_data['limit_day_max'] = "40000" response = self.do_request(post_data) print(response.json) self.assertEqual(PerLimitMustLittleDayLimitError.code, response.status_code) self.assertEqual(PerLimitMustLittleDayLimitError.error_code, response.json['error_code']) # print(response.json['message'], "this field must be String type") # self.assertEqual(response.json['message'], "单笔交易最大值必须小于当日交易限额") post_data['limit_day_max'] = "60000" # 时间类型参数业务数据不对 post_data["maintain_begin"] = "2020-08-23 09:30:00" response = self.do_request(post_data) self.assertEqual(response.status_code, DateStartMoreThanError.code) self.assertEqual(response.json['error_code'], DateStartMoreThanError.error_code) self.assertEqual(response.json['message'], DateStartMoreThanError.message) post_data["maintain_begin"] = "2019-09-27 09:00:00" # 业务类型数据不对 post_data["limit_per_min"] = "100000" response = self.do_request(post_data) self.assertEqual(response.status_code, DataStartMoreThanError.code) self.assertEqual(response.json['error_code'], DataStartMoreThanError.error_code) self.assertEqual(response.json['message'], DataStartMoreThanError.message) post_data["limit_per_min"] = "2000" # 时间类型数据格式错误 post_data["maintain_begin"] = "2019/09/27 09:00:00" response = self.do_request(post_data) self.assertEqual(response.status_code, ParameterException.code) self.assertEqual(response.json['error_code'], ParameterException.error_code) # self.assertEqual(response.json['message'], "无效的时间格式") post_data["maintain_begin"] = "2019-09-27 09:00:00" # 测试成功添加数据 response = self.do_request(post_data) self.assertEqual(response.status_code, ResponseSuccess.code) channel = ChannelConfig.query_latest_one( dict(channel_enum=channel_enum)) self.assertEqual(channel.channel_enum.value, post_data['channel_id']) self.assertEqual(channel.settlement_type.value, int(post_data['settlement_type'])) # 渠道管理:编辑通道 self.path = '/channel/deposit/edit' post_data['settlement_type'] = '3' response = self.do_request(post_data) self.assertEqual(response.status_code, ResponseSuccess.code) channel = ChannelConfig.query_latest_one( dict(channel_enum=channel_enum)) self.assertEqual(channel.channel_enum.value, post_data['channel_id']) self.assertEqual(channel.settlement_type.value, 3) # 测试 不支持的 枚举类型数据 self.path = '/channel/deposit/edit' post_data['state'] = '110' response = self.do_request(post_data) self.assertEqual(response.status_code, ParameterException.code) self.assertEqual(response.json['error_code'], ParameterException.error_code) # self.assertEqual(response.json['message'], "无效的通道状态") post_data['state'] = "10" # 代付通道管理: 新增代付通道 self.path = "/channel/withdraw/add" withdraw_postdata = dict(channel_id=channel_enum.value, fee="2.3", fee_type="1", limit_per_min="2000", limit_per_max="50000", limit_day_max="50000", start_time="09:00", end_time="23:59", maintain_begin="2019-09-27 09:00:00", maintain_end="2019-10-20 23:00:00", state="10", banks=["1", "2", "4", "6", "3", "5", "15"]) # 测试参数类型错误 withdraw_postdata['channel_id'] = '123' response = self.do_request(withdraw_postdata) self.assertEqual(response.status_code, ParameterException.code) self.assertEqual(response.json['error_code'], ParameterException.error_code) # self.assertEqual(response.json['message'], str({'channel_id': 'this field must be Integer type'})) # 测试时间格式错误 withdraw_postdata['channel_id'] = channel_enum.value withdraw_postdata["maintain_begin"] = "2019/09/27 09:00:00" response = self.do_request(withdraw_postdata) self.assertEqual(response.status_code, ParameterException.code) self.assertEqual(response.json['error_code'], ParameterException.error_code) # self.assertEqual(response.json['message'], "无效的时间格式") withdraw_postdata["maintain_begin"] = "2019-09-27 09:00:00" # 测试成功添加代付通道 ProxyChannelConfig.delete_all() response = self.do_request(withdraw_postdata) self.assertEqual(response.status_code, ResponseSuccess.code) self.assertEqual(response.json['error_code'], ResponseSuccess.error_code) channel = ProxyChannelConfig.query_latest_one( dict(channel_enum=channel_enum)) self.assertEqual(withdraw_postdata['maintain_begin'], DateTimeKit.datetime_to_str(channel.maintain_begin)) self.assertEqual(withdraw_postdata['channel_id'], channel.channel_enum.value) # 测试编辑 代付通道 self.path = "/channel/withdraw/edit" withdraw_postdata['banks'] = ["4", "6", "3"] withdraw_postdata['limit_day_max'] = '180000' withdraw_postdata['maintain_begin'] = "2019-10-30 09:30:01" withdraw_postdata['maintain_end'] = "2019-12-30 09:30:01" response = self.do_request(withdraw_postdata) self.assertEqual(response.status_code, ResponseSuccess.code) self.assertEqual(response.json['error_code'], ResponseSuccess.error_code) channel = ProxyChannelConfig.query_latest_one( dict(channel_enum=channel_enum)) self.assertEqual(channel_enum.value, channel.channel_enum.value) self.assertEqual(withdraw_postdata['maintain_begin'], DateTimeKit.datetime_to_str(channel.maintain_begin)) self.assertEqual(withdraw_postdata['maintain_end'], DateTimeKit.datetime_to_str(channel.maintain_end)) self.assertEqual( [PaymentBankEnum(4), PaymentBankEnum(6), PaymentBankEnum(3)], channel.banks) self.assertEqual(180000, channel.limit_day_max) # 测试代付列表 self.path = "/channel/withdraw/list" response = self.do_request() self.assertEqual(response.status_code, ResponseSuccess.code) self.assertEqual(response.json['error_code'], ResponseSuccess.error_code) self.assertEqual('1', response.json['data']['counts']) self.assertEqual(channel_enum.value, response.json['data']['withdraws'][0]['channel_id']) ProxyChannelConfig.delete_all()
def __test_api_withdraw(self): """ 1. 新建用户提现订单 :return: """ order_cls = OrderWithdraw uid = 1000 channel_enum = ChannelConfigEnum.CHANNEL_1001 banks = [ PaymentBankEnum(int(bank)) for bank in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] ] proxy_channel = dict(fee=Decimal("2.5"), fee_type=PaymentFeeTypeEnum.PERCENT_PER_ORDER, limit_per_min=300, limit_per_max=1000, limit_day_max=0, trade_begin_hour=0, trade_begin_minute=0, trade_end_hour=23, trade_end_minute=59, maintain_begin=DateTimeKit.str_to_datetime( "2019-12-11 09:00:00", DateTimeFormatEnum.SECONDS_FORMAT), maintain_end=DateTimeKit.str_to_datetime( "2025-12-20 23:00:00", DateTimeFormatEnum.SECONDS_FORMAT), state=ChannelStateEnum.TESTING, banks=banks) ProxyChannelConfig.update_channel(channel_enum, **proxy_channel) merchant = MerchantEnum.TEST # 准备配置数据 bank = BankCard.add_bank_card( merchant, uid=uid, bank_name="中国工商银行", bank_code="ICBC", card_no="6212260405014627955", account_name="张三", branch="广东东莞东莞市长安镇支行", province="广东省", city="东莞市", ) OrderMixes.add_one_channel_config(channel_enum) OrderMixes.add_one_merchant_config(merchant, channel_enum, payment_way=PayTypeEnum.WITHDRAW) channel_config = ChannelConfig.query_latest_one( dict(channel_enum=channel_enum)) merchant_fee_config = MerchantFeeConfig.query_latest_one( dict( merchant=merchant, payment_way=PayTypeEnum.WITHDRAW, payment_method=channel_enum.conf.payment_method, )) amount = Decimal("500") fee = BalanceKit.round_4down_5up( Decimal(merchant_fee_config.value) * amount / Decimal(100)) # 创建提现订单 params = dict( uid=uid, merchant=merchant, channel_id=channel_config.channel_id, mch_fee_id=merchant_fee_config.config_id, source=OrderSourceEnum.TESTING, order_type=PayTypeEnum.WITHDRAW, in_type=InterfaceTypeEnum.CASHIER_H5, amount=amount, bank_id=bank.id, fee=fee, ) order, ref_id = OrderCreateCtl.create_order_event(**params) event = OrderEvent.query_one(dict(ref_id=ref_id), merchant=merchant, date=order.create_time) data = order_cls.query_by_order_id(order_id=event.order_id, merchant=merchant) begin_time, end_time = DateTimeKit.get_month_begin_end( year=int(DateTimeKit.get_cur_datetime().year), month=int(DateTimeKit.get_cur_datetime().month)) withdraw_params = dict(merchant_name="TEST", page_size=10, page_index=1, begin_time=DateTimeKit.datetime_to_str( begin_time, DateTimeFormatEnum.SECONDS_FORMAT), end_time=DateTimeKit.datetime_to_str( end_time, DateTimeFormatEnum.SECONDS_FORMAT), state="0") self.path = "/trade_manage/withdraw/list" # 通过接口 查询提现订单 response = self.do_request(json_data=withdraw_params) print(response.json, "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") self.assertEqual("1", response.json['data']['total']) self.assertEqual("待认领", response.json['data']['entries'][0]['state']) self.path = "/trade_manage/order/allowed" # 通过接口, 认领订单 allowed_params = dict(order_id=order.id, merchant_name="TEST") response = self.do_request(allowed_params) self.assertEqual(ResponseSuccess.code, response.status_code) self.assertEqual(ResponseSuccess.error_code, response.json['error_code']) # 查询当前订单状态是否已修改为已认领 data = order_cls.query_by_order_id(order_id=event.order_id, merchant=merchant) self.assertEqual(OrderStateEnum.ALLOC, data.state) # 通过接口查询 审核列表 已有的认领订单为1 self.path = '/trade_manage/withdraw/review/list' request_review_params = dict( year=str(DateTimeKit.get_cur_datetime().year), mouth=str(DateTimeKit.get_cur_datetime().month)) response = self.do_request(json_data=request_review_params) self.assertEqual(1, len(response.json['data']['entries'])) self.assertEqual("已认领", response.json['data']['entries'][0]['state']) # 通过接口查询 当前可用的 代付通道 proxy_channel_suppor = dict(bank_type=bank.bank_enum.name, merchant_name="TEST", amount=str(amount)) self.path = "/trade_manage/withdraw/available/channel" response = self.do_request(json_data=proxy_channel_suppor) self.assertEqual(WithdrawBankEntryResult.code, response.status_code) self.assertEqual(WithdrawBankEntryResult.error_code, response.json['error_code']) self.assertEqual( channel_enum.conf['provider'] + channel_enum.conf['mch_id'], response.json['data']['entries'][0]['key']) # 测试人工出款 处理订单 self.path = '/trade_manage/withdraw/person/execute' execute_params = dict(order_id=order.order_id, merchant="Test") response = self.do_request(json_data=execute_params) self.assertEqual(ResponseSuccess.code, response.status_code) self.assertEqual(ResponseSuccess.error_code, response.json['error_code']) data = order_cls.query_by_order_id(order_id=event.order_id, merchant=merchant) self.assertEqual(OrderStateEnum.DEALING, data.state) # 测试人工出款 出款 self.path = "/trade_manage/withdraw/person/done" done_params = dict(order_id=order.order_id, merchant='TEST', comment='测试', fee='5') response = self.do_request(json_data=done_params) self.assertEqual(ResponseSuccess.code, response.status_code) self.assertEqual(ResponseSuccess.error_code, response.json['error_code']) data = order_cls.query_by_order_id(order_id=event.order_id, merchant=merchant) self.assertEqual(OrderStateEnum.SUCCESS, data.state)
def __add_event(self, uid, merchant, channel_enum, order_type): order_cls = OrderDeposit if order_type == PayTypeEnum.DEPOSIT else OrderWithdraw channel_config = ChannelConfig.query_latest_one( dict(channel_enum=channel_enum)) merchant_fee_config = MerchantFeeConfig.query_latest_one( dict( merchant=merchant, payment_way=PayTypeEnum.DEPOSIT, payment_method=channel_enum.conf.payment_method, )) params = dict( uid=uid, merchant=merchant, channel_id=channel_config.channel_id, mch_fee_id=merchant_fee_config.config_id, source=OrderSourceEnum.TESTING, order_type=order_type, in_type=InterfaceTypeEnum.CASHIER_H5, amount=Decimal("500"), comment='谢谢', op_account='xxx', bank_id=123, fee=10 if order_type == PayTypeEnum.WITHDRAW else 0, ) order, ref_id = OrderCreateCtl.create_order_event(**params) self.assertIsNotNone(order) event = OrderEvent.query_one(dict(ref_id=ref_id), merchant=merchant, date=order.create_time) self.assertIsNotNone(event) self.assertEqual(order.order_id, event.order_id) self.assertEqual(order.uid, event.uid) self.assertEqual(ref_id, event.ref_id) order = order_cls.query_by_order_id(order_id=event.order_id, merchant=merchant) self.assertIsNotNone(order) self.assertEqual(params['uid'], order.uid) self.assertEqual(params['merchant'], order.merchant) self.assertEqual(params['channel_id'], order.channel_id) self.assertEqual(params['source'], order.source) self.assertEqual(params['amount'], order.amount) self.assertTrue(len(order.mch_tx_id) > 0) self.assertTrue(len(order.sys_tx_id) > 0) # 更新订单 order, ref_id = OrderUpdateCtl.update_order_event( order_id=order.order_id, uid=order.uid, merchant=merchant, state=OrderStateEnum.SUCCESS if order_type == PayTypeEnum.DEPOSIT else OrderStateEnum.ALLOC, tx_amount=Decimal("500.32"), channel_tx_id='1232283838229929292', settle=SettleStateEnum.DONE, deliver=DeliverStateEnum.DONE, channel_id=channel_config.channel_id, mch_fee_id=merchant_fee_config.config_id, op_account='xxxx', comment='改了改了', offer=Decimal('1.22'), fee=Decimal('1.22'), cost=Decimal('1.22'), profit=Decimal('1.22'), deliver_type=DeliverTypeEnum.PROXY, alloc_time=DateTimeKit.get_cur_datetime(), deal_time=DateTimeKit.get_cur_datetime(), ) self.assertIsNotNone(order) event = OrderEvent.query_one(dict(ref_id=ref_id), merchant=merchant, date=order.create_time) self.assertEqual(order.order_id, event.order_id) self.assertEqual(order.uid, event.uid) self.assertEqual(ref_id, event.ref_id) order3 = order_cls.query_by_order_id(order_id=event.order_id, merchant=merchant) self.assertIsNotNone(order3) self.assertEqual(params['uid'], order3.uid) self.assertEqual(params['merchant'], order3.merchant) self.assertEqual(params['channel_id'], order3.channel_id) self.assertEqual(params['source'], order3.source) self.assertEqual(Decimal("500.32"), order3.tx_amount) self.assertEqual(order.order_id, order3.order_id) self.assertEqual(order.mch_tx_id, order3.mch_tx_id) self.assertEqual(order.sys_tx_id, order3.sys_tx_id) order3 = order_cls.query_by_tx_id(tx_id=order.sys_tx_id) self.assertIsNotNone(order3) self.assertEqual(params['uid'], order3.uid) self.assertEqual(params['merchant'], order3.merchant) self.assertEqual(params['channel_id'], order3.channel_id) self.assertEqual(params['source'], order3.source) self.assertEqual(Decimal("500.32"), order3.tx_amount) self.assertEqual(order.order_id, order3.order_id) self.assertEqual(order.mch_tx_id, order3.mch_tx_id) self.assertEqual(order.sys_tx_id, order3.sys_tx_id) order3 = order_cls.query_by_uid_someday( merchant=merchant, uid=uid, someday=order.create_time).all()[0] self.assertIsNotNone(order3) self.assertEqual(params['uid'], order3.uid) self.assertEqual(params['merchant'], order3.merchant) self.assertEqual(params['channel_id'], order3.channel_id) self.assertEqual(params['source'], order3.source) self.assertEqual(Decimal("500.32"), order3.tx_amount) self.assertEqual(order.order_id, order3.order_id) self.assertEqual(order.mch_tx_id, order3.mch_tx_id) self.assertEqual(order.sys_tx_id, order3.sys_tx_id) begin_time, end_time = DateTimeKit.get_day_begin_end(order.create_time) orders = order_cls.query_by_create_time(begin_time, end_time, merchant=merchant, uid=uid).all() order3 = orders[-1] self.assertIsNotNone(order3) self.assertFalse(order3.is_cold_table()) self.assertEqual(params['uid'], order3.uid) self.assertEqual(params['merchant'], order3.merchant) self.assertEqual(params['channel_id'], order3.channel_id) self.assertEqual(params['source'], order3.source) self.assertEqual(Decimal("500.32"), order3.tx_amount) self.assertEqual(order.order_id, order3.order_id) self.assertEqual(order.mch_tx_id, order3.mch_tx_id) self.assertEqual(order.sys_tx_id, order3.sys_tx_id) # 冷表查询测试 begin_time, end_time = DateTimeKit.get_day_begin_end(order.create_time) clean_date = order_cls.get_clean_date() if clean_date.month == begin_time.month: begin_time = clean_date orders = order_cls.query_by_create_time(begin_time, end_time, merchant=merchant, uid=uid).all() order3 = orders[-1] self.assertIsNotNone(order3) self.assertTrue(order3.is_cold_table()) self.assertEqual(params['uid'], order3.uid) self.assertEqual(params['merchant'], order3.merchant) self.assertEqual(params['channel_id'], order3.channel_id) self.assertEqual(params['source'], order3.source) self.assertEqual(Decimal("500.32"), order3.tx_amount) self.assertEqual(order.order_id, order3.order_id) self.assertEqual(order.mch_tx_id, order3.mch_tx_id) self.assertEqual(order.sys_tx_id, order3.sys_tx_id)
def order_create(cls, user, amount, channel_enum, client_ip, source: OrderSourceEnum, in_type: InterfaceTypeEnum, notify_url=None, result_url=None, mch_tx_id=None, extra=None): """ 申请创建订单 :return: """ merchant = user.merchant # 找出最新版本的商户费率配置 channel_config = ChannelConfig.query_latest_one(query_fields=dict( channel_enum=channel_enum)) if not channel_config: current_app.logger.error( 'no channel config found, channel_enum: %s', channel_enum.desc) return None, InvalidDepositChannelError() if channel_config.is_in_maintain_time(): current_app.logger.error('channel in maintain, channel_enum: %s', channel_enum.desc) return None, ChannelNoValidityPeriodError(message="通道(%s)维护中" % channel_enum.desc) if not channel_config.is_in_trade_time(): current_app.logger.error( 'channel not in trade time, channel_enum: %s', channel_enum.desc) return None, ChannelNoValidityPeriodError( message="当前时间不在通道(%s)交易时间内" % channel_enum.desc) if channel_config.is_amount_per_limit(amount): current_app.logger.error( 'per amount limit, channel_enum: %s, amount: %s', channel_enum.desc, amount) return None, DepositOrderAmountInvalidError( message="%s,通道(%s)" % (DepositOrderAmountInvalidError.message, channel_enum.desc)) if channel_enum.is_fixed_amount_channel( ) and not channel_enum.is_amount_in_fixed_list(amount): current_app.logger.error( 'invalid amount, channel: %s, input amount: %s, fixed amounts: %s', channel_enum.desc, amount, channel_enum.get_fixed_amounts()) return DepositOrderAmountInvalidError(message="固额支付类型额度匹配失败") if not channel_config.state.is_available(user.is_test_user): current_app.logger.error( 'channel state not available, channel_enum: %s, uid: %s, merchant: %s', channel_enum.desc, user.uid, merchant.name) return None, ChannelNoValidityPeriodError( message="通道(%s)状态:%s" % (channel_enum.desc, channel_config.state.desc)) # 找出最新版本的商户费率配置 merchant_fee = MerchantFeeConfig.query_latest_one( query_fields=dict(merchant=merchant, payment_way=PayTypeEnum.DEPOSIT, payment_method=channel_enum.conf.payment_method)) if not merchant_fee: current_app.logger.error( 'no merchant fee config for channel, channel_enum: %s, uid: %s, merchant: %s', channel_enum.desc, user.uid, merchant.name) return None, MerchantConfigDepositError() kwargs = dict( uid=user.uid, merchant=merchant, amount=amount, channel_id=channel_config.channel_id, mch_fee_id=merchant_fee.config_id, order_type=PayTypeEnum.DEPOSIT, source=source, in_type=in_type, ip=client_ip, pay_method=channel_enum.conf.payment_method, notify_url=notify_url, result_url=result_url, mch_tx_id=mch_tx_id, extra=extra, ) try: order, _ = OrderCreateCtl.create_order_event(**kwargs) except Exception as e: return None, PreOrderCreateError(message=str(e)) if not order: return None, PreOrderCreateError() return order, None
def get_deposit_channel2(cls): return ChannelConfig.query_latest_one(query_fields=dict( channel_enum=cls.channel_enum2))
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
def post(self): """ 手动补单 :return: """ form, error = CreateDepositOrderForm().request_validate() if error: return error.as_response() ''' 根据商户查询用户是否存在 构造数据 创建充值订单 更改订单状态为完成 ''' # 根据商户查询用户是否存在 user = User.query_user(form.merchant.data, uid=form.uid.data) if not user: return AccountNotExistError().as_response() # 构造数据 client_ip = form.client_ip.data channel_enum = form.channel_id.data payment_type = form.payment_type.data amount = Decimal(form.amount.data) # 判断当前传入的支付类型是否该渠道支持 if payment_type != channel_enum.conf['payment_type']: return InvalidDepositPaymentTypeError() merchant = form.merchant.data # 找出最新版本的商户费率配置 channel_config = ChannelConfig.query_latest_one(query_fields=dict( channel_enum=channel_enum)) if not channel_config: return InvalidDepositChannelError().as_response() if not channel_config.is_channel_valid(merchant.is_test): return ChannelNoValidityPeriodError().as_response() if ChannelListHelper.is_amount_out_of_range( amount=amount, merchant=merchant, payment_way=PayTypeEnum.DEPOSIT, client_ip=client_ip): return DepositOrderAmountInvalidError().as_response() # limit_min, limit_max = ChannelLimitCacheCtl( # PayTypeEnum.DEPOSIT).get_channel_limit() # try: # if limit_min > amount or limit_max < amount: # return DepositOrderAmountInvalidError().as_response() # except Exception as e: # return MustRequestDepositLimitError().as_response() # 找出最新版本的商户费率配置 merchant_fee = MerchantFeeConfig.query_latest_one( query_fields=dict(merchant=merchant, payment_way=PayTypeEnum.DEPOSIT, payment_method=channel_enum.conf.payment_method)) if not merchant_fee: return MerchantConfigDepositError().as_response() try: with db.auto_commit(): # 创建待支付订单 order, _ = OrderCreateCtl.create_order_event( uid=user.uid, merchant=merchant, amount=amount, channel_id=channel_config.channel_id, mch_fee_id=merchant_fee.config_id, order_type=PayTypeEnum.DEPOSIT, source=OrderSourceEnum.MANUALLY, in_type=InterfaceTypeEnum.CASHIER_H5, ip=client_ip, pay_method=channel_enum.conf.payment_method, op_account=g.user.account, # 后台管理员账号,后台人工修改数据时必填 comment=form.remark.data, # 管理后台修改备注,后台人工修改数据时必填 mch_tx_id=form.mch_tx_id.data, commit=False, ) if not order: raise Exception('order create failed') # 支付成功 if not DepositTransactionCtl.success_order_process( order=order, tx_amount=amount, channel_tx_id=form.mch_tx_id.data, comment="手动补单订单", commit=False, ): raise Exception('order process failed') except Exception as e: if str(e).find("Duplicate entry") >= 0: return PreOrderCreateError(message="商户订单号重复: {}".format( form.mch_tx_id.data)).as_response() return PreOrderCreateError(message=str(e)).as_response() return ResponseSuccess().as_response()