def config_list(self): _list = list() value = json.loads(self._config_list) for x in value: x['payment_type'] = PaymentTypeEnum.from_name(x['payment_type']) _list.append(x) return _list
def validate_config_list(self, value): try: config_list = list() for x in value.data: x['payment_type'] = PaymentTypeEnum.from_name( x['payment_type']) x['priority'] = int(x['priority']) config_list.append(x) self.config_list.data = config_list except Exception as e: raise StopValidation("无效的 config_list")
def post(self): """ 通道管理: 获取通道配置信息 :return: """ form, error = ChannelConfigQueryForm().request_validate() if error: return error.as_response() pay_type = form.pay_type.data config_channels_dict = ChannelListHelper.get_config_channels( pay_type, ret_dict=True) if pay_type == PayTypeEnum.DEPOSIT: configs = [ c for c in ChannelConfigEnum if c.value not in config_channels_dict and c.conf['payment_type'] ] else: configs = [ c for c in ChannelConfigEnum if c.value not in config_channels_dict and not c.conf['payment_type'] ] channel_config_list = [ dict( channel_id=i.value, channel_desc=i.desc, id=i.conf["id"], provider=i.conf["provider"], name=i.conf["name"], payment_type=i.conf["payment_type"].desc if i.conf['payment_type'] else '', payment_method=i.conf["payment_method"].desc if i.conf['payment_method'] else '', ) for i in configs ] data = dict( channel_config=channel_config_list, payment_fee_type=PaymentFeeTypeEnum.get_desc_value_pairs(), settlement_type=SettleTypeEnum.get_name_value_pairs(), channel_state=ChannelStateEnum.get_desc_value_pairs(), banks=PaymentBankEnum.get_desc_value_pairs(), # banks=[item.value for item in PaymentBankEnum], interfaces=InterfaceTypeEnum.get_name_value_pairs(), payment_method=PayMethodEnum.get_desc_value_pairs(), merchant_name=MerchantEnum.get_name_value_pairs(), payment_types=PaymentTypeEnum.get_desc_name_pairs(), ) return ChannelConfigResult(bs_data=data).as_response()
def __test_get_config(self, merchant): self.path = "/config/get" post_data = dict(merchant_id=merchant.value, user_ip="127.0.0.1") post_data['sign'] = GatewaySign(merchant).generate_sign(post_data) post_data['user_id'] = '1000000' rsp = self.do_request(post_data) self.assertEqual(200, rsp.status_code) self.assertEqual(GatewayResponseConfig.error_code, rsp.json['error_code'], rsp.json['message']) payment_types = rsp.json['data']['payment_types'] self.assertIsInstance(payment_types, (list, )) item = payment_types[0] self.assertEqual(InitData.channel_enum.conf.payment_type, PaymentTypeEnum.from_name(item['name'])) print('payment_types:', payment_types)
), 'amount': fields.Float( required=True, description='(必填,参与签名)充值金额,必须是整数或浮点数字符串,最多保留2位小数', example="500.34", ), 'mch_tx_id': fields.String( required=True, description='(必填,参与签名)商户订单号,最大128个字符', ), 'payment_type': fields.String( required=True, description="(必填,参与签名)" + PaymentTypeEnum.description_name_desc(), example=PaymentTypeEnum.ZHIFUBAO.name, ), 'notify_url': fields.String( required=True, description='(必填,参与签名)回调通知URL', example="https://google.com", ), 'user_id': fields.String( required=False, description='(可选,不参与签名)用户ID', example="999", ), 'user_ip':
def validate_payment_type(self, value): try: self.payment_type.data = PaymentTypeEnum(int(value.data)) except Exception as e: raise StopValidation("无效的支付方式")
example="WX101" ), 'provider': fields.String( required=True, description='支付公司', example="腾讯" ), 'name': fields.String( required=True, description='渠道', example="微信网页支付" ), 'payment_type': fields.String( required=True, description='支付类型', example=PaymentTypeEnum.description() ), 'payment_method': fields.String( required=True, description='支付方法', example=PayMethodEnum.description() ) }) NameValuePair = api.model("NameValuePair", { "name": fields.String( description="支付方式描述", example=PayMethodEnum.WEIXIN_H5.desc, ), "value": fields.String( description='支付方式数值',
description="支付方式描述", example=PaymentTypeEnum.ZHIFUBAO.desc, ), "value": fields.String( description='支付方式数值', example=PaymentTypeEnum.ZHIFUBAO.value, ), }) DescValueChannelPair = api.model( "DescValueChannelPair", { "desc": fields.String( description="支付方式描述", example=PaymentTypeEnum.get_desc_list(), ), "value": fields.String( description='支付方式数值', example=PaymentTypeEnum.description_value_desc(), ), "channel_id": fields.String( description='通道ID', example="通道ID,发起充值时原样传回", ), "channel_prompt": fields.String( description='通道备注信息', example="农行卡不能使用",
def post(self): """ 充值通道列表 :return: """ router2_dict = ChannelListHelper.get_router2_dict() channel_list = [] channels = ChannelConfig.query_all() channels = ChannelConfig.filter_latest_items(channels) for channel in channels: channel_enum = channel.channel_enum channel_conf = channel_enum.conf merchants = list() router = router2_dict.get(channel_enum) if router: merchants = router.merchants channel_list.append( dict( channel_id=channel_enum.value, channel_desc=channel_enum.desc, id=channel_conf['mch_id'], provider=channel_conf['provider'], payment_type=dict(desc=PaymentTypeEnum( channel_conf['payment_type']).desc, value=PaymentTypeEnum( channel_conf['payment_type']).value), payment_method=dict( desc=PayMethodEnum( channel_conf['payment_method']).desc, value=PayMethodEnum( channel_conf['payment_method']).value), fee=channel.fee, fee_type=dict( desc=PaymentFeeTypeEnum(channel.fee_type).desc, value=PaymentFeeTypeEnum(channel.fee_type).value), limit_per_min=channel.limit_per_min, limit_per_max=channel.limit_per_max, limit_day_max=channel.limit_day_max, settlement_type=dict( key=SettleTypeEnum(channel.settlement_type).value, value=SettleTypeEnum(channel.settlement_type).name), trade_start_time=":".join([ str(channel.trade_begin_hour), str(channel.trade_begin_minute) ]), # trade_start_time=dict(trade_begin_hour=channel.trade_begin_hour, # trade_begin_minute=channel.trade_begin_minute), trade_end_time=":".join([ str(channel.trade_end_hour), str(channel.trade_end_minute) ]), # trade_end_time=dict(trade_end_hour=channel.trade_end_hour, # trade_end_minute=channel.trade_end_minute), main_time=dict(maintain_begin=channel.maintain_begin if channel.maintain_begin else None, maintain_end=channel.maintain_end if channel.maintain_end else None), state=dict(desc=channel.state.desc, value=channel.state.value), reason=channel.get_reason_desc(), priority=channel.priority, merchants=[x.name for x in merchants], )) channel_list = sorted(channel_list, key=lambda item: item['state']['value']) data = dict(counts=len(channel_list), channels=channel_list) return ChannelListResult(bs_data=data).as_response()
def post(self): merchant = MerchantEnum.TEST_API amount = Decimal(request.form['amount']) domain = MerchantDomainConfig.get_latest_domain(merchant) # 模拟商户发起支付请求 scheme_host = UrlKit.get_scheme_host(host=domain) url = scheme_host + url_for('gateway_deposit_request') if not request.form['payment_type']: return redirect( scheme_host + url_for('gateway_demo_merchant_deposit', error="请选择支付类型")) payment_type = PaymentTypeEnum.from_name(request.form['payment_type']) # 模拟商户的回调URL notify_url = UrlKit.join_host_path(url_for('gateway_demo_notify'), host=domain) post_data = dict( merchant_id=merchant.value, amount=str(amount), mch_tx_id=OrderUtils.generate_mch_tx_id( DateTimeKit.get_cur_timestamp()), payment_type=payment_type.name, notify_url=notify_url, user_ip=IpKit.get_remote_ip(), ) print('post_data:', post_data) post_data['sign'] = GatewaySign(merchant).generate_sign(post_data) post_data['redirect_url'] = "https://google.com" post_data['extra'] = json.dumps(dict(x=1, y=2)) post_data['user_id'] = "100" print('post_data:', post_data) rsp = requests.post(url, json=post_data) if rsp.status_code != 200: return redirect(scheme_host + url_for('gateway_demo_merchant_deposit', error="http请求失败,状态码:%s, url: %s" % (rsp.status_code, url))) if rsp.json()['error_code'] != 200: return redirect(scheme_host + url_for( 'gateway_demo_merchant_deposit', error=rsp.json()['message'])) sys_tx_id = rsp.json()['data']['sys_tx_id'] return redirect(scheme_host + url_for( 'gateway_demo_merchant_deposit', success=True, post_data=json.dumps(post_data), notify_url=scheme_host + url_for('demo_deposit_notify', tx_id=sys_tx_id), redirect_url=rsp.json()['data']['redirect_url'], sys_tx_id=sys_tx_id, mch_tx_id=rsp.json()['data']['mch_tx_id'], valid_time=rsp.json()['data']['valid_time'], ))
def validate_payment_type(self, value): try: self.payment_type.data = PaymentTypeEnum.from_name(value.data) except Exception as e: raise StopValidation("无效的 payment_type, 可用支付类型包括:%s" % PaymentTypeEnum.get_desc_name_pairs())
'user_ip': fields.String( required=True, description='(可选,不参与签名)用户ID', example="999", ), }) ############################################## # API的响应的数据model ############################################## PaymentConfig = api.model( 'PaymentConfig', { "name": fields.String( description=PaymentTypeEnum.description_name_desc(), example=PaymentTypeEnum.ZHIFUBAO.name, ), "limit_min": fields.Float( description='最小限额', example="100.19", ), "limit_max": fields.Float( description='最大限额', example="5000.19", ), "fixed_amounts": fields.List( fields.Float(example="50.19", ),