Ejemplo n.º 1
0
    def init_withdraw_order_deal(cls, amount):
        """
        初始化一个提款订单
        :param amount:
        :return:
        """
        client_ip = '127.0.0.1'
        user = cls.get_user()
        bank_card = cls.get_bank_card()
        admin_user = cls.get_admin_user()

        order, error = WithdrawTransactionCtl.order_create(
            user=user,
            amount=amount,
            client_ip=client_ip,
            user_bank_id=bank_card.card_id,
        )
        assert error is None

        rst = WithdrawTransactionCtl.order_alloc(admin_user.account,
                                                 order.order_id, cls.merchant)
        assert isinstance(rst, (ResponseSuccess, ))

        channel = cls.get_withdraw_channel()
        rst = WithdrawTransactionCtl.order_deal(admin_user.account,
                                                order.order_id,
                                                order.merchant,
                                                channel.channel_id,
                                                test=True)
        assert isinstance(rst, (ResponseSuccess, ))

        return WithdrawTransactionCtl.get_order(order.sys_tx_id)
Ejemplo n.º 2
0
    def create_one_withdraw_order(cls, amount=None):
        client_ip = '127.0.0.1'
        amount = amount or Decimal("300")
        user = cls.get_user()
        bank_card = cls.get_bank_card()

        order, error = WithdrawTransactionCtl.order_create(
            user=user,
            amount=amount,
            client_ip=client_ip,
            user_bank_id=bank_card.card_id,
        )
        assert error is None

        return cls.get_user_latest_order(user.uid, PayTypeEnum.WITHDRAW)
Ejemplo n.º 3
0
    def init_withdraw_order_alloc(cls, amount):
        client_ip = '127.0.0.1'
        user = cls.get_user()
        bank_card = cls.get_bank_card()
        admin_user = cls.get_admin_user()

        order, error = WithdrawTransactionCtl.order_create(
            user=user,
            amount=amount,
            client_ip=client_ip,
            user_bank_id=bank_card.card_id,
        )
        assert error is None

        rst = WithdrawTransactionCtl.order_alloc(admin_user.account,
                                                 order.order_id, cls.merchant)
        assert isinstance(rst, (ResponseSuccess, ))

        return WithdrawTransactionCtl.get_order(order.sys_tx_id)
Ejemplo n.º 4
0
    def post(self):
        """
        提现接口: 检查支付密码是否正确,如果密码正确则创建用户提现订单
        """
        form, error = CreateWithdrawOrderForm().request_validate()
        if error:
            return error.as_response()

        uid = g.user.uid
        merchant = g.user.merchant

        if not g.user.has_permission(UserPermissionEnum.WITHDRAW):
            return UserPermissionDeniedError().as_response()

        amount = BalanceKit.round_4down_5up(Decimal(form.amount.data))
        user_bank_id = form.user_bank.data
        client_ip = form.client_ip.data
        trade_password = form.trade_password.data

        # 判断 支付密码是否正确
        if not User.verify_payment_password(
                merchant=merchant, uid=uid, password=trade_password):
            cache = UserPaymentPasswordLimitCache(uid=uid)
            cache.incr_times()
            times = cache.get_left_times()
            return PaymentPasswordError(message=PaymentPasswordError.message.
                                        format(times)).as_response()

        order, error = WithdrawTransactionCtl.order_create(
            user=g.user,
            amount=amount,
            client_ip=client_ip,
            user_bank_id=user_bank_id,
        )
        if error:
            return error.as_response()

        return ResponseSuccess().as_response()
Ejemplo n.º 5
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_withdraw_request"),
                                    IpKit.get_remote_ip(), request.args,
                                    request.json)

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

        checker = GatewayFormChecker(form.merchant_id.data)

        # 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. 获取用户对象
        user = checker.get_fake_user(form.user_id.data)

        # 银行卡信息
        bank_info = BankCard.generate_model(
            bank_name=form.bank_type.data.desc,
            bank_code=form.bank_type.data.bank_code,
            card_no=form.card_no.data,
            account_name=form.account_name.data,
            branch=form.branch.data or '',
            province=form.province.data or '',
            city=form.city.data or '',
        )

        # 4. 创建订单
        order, error = WithdrawTransactionCtl.order_create(
            user=user,
            amount=form.amount.data,
            client_ip=form.user_ip.data,
            notify_url=form.notify_url.data,
            mch_tx_id=form.mch_tx_id.data,
            bank_info=bank_info.bank_info_dict,
            extra=form.extra.data,
        )
        if error:
            return error.as_response()

        return GatewayResponseWithdraw(bs_data=dict(
            sys_tx_id=order.sys_tx_id,
            mch_tx_id=order.mch_tx_id,
        )).as_response()