def create_one_refund_order(cls): """ 创建一个失败的订单,最后退款 :return: """ amount = Decimal("300") order = cls.init_withdraw_order_deal(amount) WithdrawTransactionCtl.order_fail(order)
def get(self): """ 立马付充值回调 :return: """ if not EnvironEnum.is_local_evn(current_app.config['FLASK_ENV']): # 无论如何都记录一条log current_app.logger.info( 'ponypay withdraw callback, ip: %s, data: %s', IpKit.get_remote_ip(), request.args) form, error = PonyPayWithdrawForm().request_validate() if error: current_app.logger.fatal('msg: %s, data: %s', error.message, request.args) return BaseResponse('FAIlURE') # 交易订单id tx_id = form.corderid.data # 实际支付金额 tx_amount = Decimal(form.money.data) # 订单状态: 成功/失败 status = form.status.data # 签名 sign = form.sign.data # 客户端IP client_ip = form.client_ip.data order = WithdrawTransactionCtl.get_order(tx_id) if not order: return BaseResponse('FAIlURE') channel_config = ChannelConfig.query_by_channel_id(order.channel_id) controller = WithdrawCallbackPonypay(channel_config.channel_enum) # IP白名单校验 if not controller.check_ip(client_ip): current_app.logger.fatal('ip not allow, client_ip: %s, data: %s', client_ip, request.args) return BaseResponse('FAIlURE') # 签名验证 if not controller.check_sign(tx_id, tx_amount, sign): current_app.logger.fatal('invalid sign, client_ip: %s, data: %s', client_ip, request.args) return BaseResponse('FAIlURE') if status == '1': # 支付成功 if not WithdrawTransactionCtl.order_success(order, tx_amount): return BaseResponse('FAIlURE') else: # 支付失败 if not WithdrawTransactionCtl.order_fail(order): return BaseResponse('FAIlURE') return BaseResponse('SUCCESS')
def withdraw_epay_tong(): from app.main import flask_app with flask_app.app_context(): tasks = list(OrderTasks.query_all()) for task in tasks: order_id = task.order_id batch_date = DateTimeKit.datetime_to_str(task.create_time, DateTimeFormatEnum.TIGHT_DAY_FORMAT) current_app.logger.info('EpayTong withdraw check: order_id: %s, batch_date: %s', order_id, batch_date) order = WithdrawTransactionCtl.get_order_by_order_id(order_id) current_app.logger.info('EpayTong withdraw check: order_state: %s, state_type: %s', order.state, type(order.state)) if not order: current_app.logger.info('EpayTong withdraw check, order_id: %s', order_id) OrderTasks.delete_task(task_id=task.id) continue if order.state.name == OrderStateEnum.SUCCESS.name or order.state.name == OrderStateEnum.FAIL.name: OrderTasks.delete_task(task_id=task.id) continue elif order.state.name != "DEALING": current_app.logger.info('EpayTong withdraw check, order_id: %s, order_state: %s', order_id, order.state) continue current_app.logger.info('EpayTong withdraw check, order_id: %s, order_state: %s', order_id, order.state) params = { "tx_id": order.sys_tx_id, "batch_date": batch_date } rst = EpayTongWithdrawRequest(channel_enum=ChannelConfigEnum.CHANNEL_6013).launch_pay(params) if rst['code'] == 0: tx_amount = rst['data']['tx_amount'] code = rst['data']['tradeFeedbackcode'] print(code, "******************") if code == "成功": if WithdrawTransactionCtl.order_success(order, tx_amount): OrderTasks.delete_task(task_id=task.id) elif code == "失败": if WithdrawTransactionCtl.order_fail(order): OrderTasks.delete_task(task_id=task.id)
def post(self): if not EnvironEnum.is_local_evn(current_app.config['FLASK_ENV']): # 无论如何都记录一条log current_app.logger.info('yinsao withdraw callback, ip: %s, data: %s, headers: %s', IpKit.get_remote_ip(), request.form, request.headers) # form, error = YinSaoForm.request_validate() # if error: # current_app.logger.fatal('msg: %s, data: %s', error.message, request.json) # return BaseResponse('FAIlURE') client_ip = IpKit.get_remote_ip() if not CallbackYinSao.check_ip(client_ip): current_app.logger.fatal('ip not allow, client_ip: %s, data: %s', client_ip, request.args) return BaseResponse('FAIlURE') data = {k: v for k, v in request.form.items()} tx_amount = Decimal(data['transAmt']) / Decimal('100') sys_tx_id = data['orderNo'] signature = data.pop('signature') key_list = sorted(list(data.keys())) request_str = "&".join(["{}={}".format(field, data[field]) for field in key_list if field != "risk"]) sign = CallbackYinSao.generate_sign(request_str) flag = CallbackYinSao.check_sign(signature, sign) if not flag: current_app.logger.fatal('invalid sign, data: %s, sign: %s, signature: %s', client_ip, data, sign, signature) return BaseResponse('FAIlURE') order = WithdrawTransactionCtl.get_order(sys_tx_id) if not order: return BaseResponse('FAIlURE') if str(data['respCode']) == '0000': # 支付成功 if not WithdrawTransactionCtl.order_success(order, tx_amount): return BaseResponse('FAILURE') else: # 支付失败 if not WithdrawTransactionCtl.order_fail(order): return BaseResponse('FAIlURE') return BaseResponse('SUCCESS')
def __test_withdraw_fail(self): amount = Decimal("100.25") order = InitData.init_withdraw_order_deal(amount) rst = WithdrawTransactionCtl.order_fail(order) self.assertTrue(rst)
def post(self): if not EnvironEnum.is_local_evn(current_app.config['FLASK_ENV']): # 无论如何都记录一条log current_app.logger.info( 'onepay withdraw callback, ip: %s, headers: %s, json data: %s', IpKit.get_remote_ip(), request.headers, request.json) # form, error = YinSaoForm.request_validate() # if error: # current_app.logger.fatal('msg: %s, data: %s', error.message, request.json) # return BaseResponse('FAIlURE') current_app.logger.fatal( 'onepay withdraw callback, ip: %s, form data: %s, headers: %s, json data: %s', IpKit.get_remote_ip(), request.form, request.headers, request.json) client_ip = IpKit.get_remote_ip() if not CallbackOnePay.check_ip(client_ip): current_app.logger.fatal('ip not allow, client_ip: %s, data: %s', client_ip, request.args) return BaseResponse('FAIlURE') flag = request.json['flag'] if flag == 'FAILED': return BaseResponse('FAIlURE') data = {k: v for k, v in request.json['data'].items()} no_need_sign = ['totalFactorage', 'sign', 'signType', 'detailList'] signature = data.pop('sign') key_list = sorted(list(data.keys())) request_str = "&".join([ "{}={}".format(field, data[field]) for field in key_list if data.get(field, False) and field not in no_need_sign ]) flag = CallbackOnePay.check_sign(signature, request_str) if not flag: current_app.logger.fatal( 'invalid sign, data: %s, sign: %s, data: %s', client_ip, data, signature, request_str) return BaseResponse('FAIlURE') withdraw_order = request.json['data']['detailList'][0] tx_id = withdraw_order['serialNo'] tx_amount = withdraw_order['amount'] order = WithdrawTransactionCtl.get_order(tx_id) if not order: return BaseResponse('FAIlURE') if str(withdraw_order['tradeStatus']) == '1': # 支付成功 if not WithdrawTransactionCtl.order_success( order, decimal.Decimal(tx_amount)): return BaseResponse('FAILURE') elif str(withdraw_order['tradeStatus']) == '2': # 支付失败 if not WithdrawTransactionCtl.order_fail(order): return BaseResponse('FAIlURE') return BaseResponse('SUCCESS')
def post(self): """ 专一付代付回调 :return: """ if not EnvironEnum.is_local_evn(current_app.config['FLASK_ENV']): # 无论如何都记录一条log current_app.logger.info( 'zhuanyifu withdraw callback, ip: %s, data: %s, headers: %s', IpKit.get_remote_ip(), request.json, request.headers) event = request.headers.get('ChinaRailway-Event') signature = request.headers.get('ChinaRailway-Signature') form, error = ZhuanYeFuWithdrawForm().request_validate() if error: current_app.logger.fatal('msg: %s, data: %s', error.message, request.args) return BaseResponse('FAIlURE') pp = signature.split('.') if event != "Pay.Succeeded": return ResponseSuccess(code=500).as_response() # 交易ID tx_id = form.order.data fee = Decimal(form.fee.data) order = WithdrawTransactionCtl.get_order(tx_id) if not order: return ResponseSuccess( code=500, message='curr order no found').as_response() curr_status = order.state if curr_status != OrderStateEnum.DEALING: return ResponseSuccess( code=500, message='curr order status must be DEALING').as_response() print(order.channel_id, form.order.data, order.merchant, order.create_time, order.order_id, order.uid) channel_config = ProxyChannelConfig.query_by_channel_id( order.channel_id) channel_cost = FeeCalculator.calc_cost(order.amount, channel_config.fee_type, channel_config.fee) if fee != channel_cost: current_app.logger.error( "ZYF withdraw fee info order_id:{}, channel_fee: {}, channel_cost:{}" .format(order.order_id, fee, channel_cost)) try: flag = CryptoKit.rsa_verify( pp[1], pp[0], channel_config.channel_enum.conf['plat_public_key']) if flag != True: return ResponseSuccess(code=500, message='签名错误').as_response() except Exception as e: return ResponseSuccess(code=500).as_response() # 代付金额 tx_amount = Decimal(form.amount.data) # 代付费率 fee = Decimal(form.fee.data) # 通道订单号 transaction = form.transaction.data client_ip = form.client_ip.data status = form.status.data if str(status) == "1": """ 修改订单状态, 记录代付费率 """ if not WithdrawTransactionCtl.order_success(order, tx_amount): return ResponseSuccess(code=500).as_response() elif str(status) == "2": """ 代付订单失败, 1.给用户退款,给商户退款+手续费 2. 修改订单状态 """ # order = WithdrawTransactionCtl.get_order(merchant, order_id) if not WithdrawTransactionCtl.order_fail(order): return ResponseSuccess(code=500).as_response() return ResponseSuccess(code=204).as_response()