Exemplo n.º 1
0
def vas_payment_is_enabled(payment_entity, vas_name):
    from api_x.zyt.vas import NAME
    if NAME == vas_name:
        channel = get_channel_by_name(payment_entity.channel_name)
        # 只支持支付
        return channel.zyt_pay_enabled and payment_entity.source in [
            TransactionType.PAYMENT
        ]
    return True
Exemplo n.º 2
0
        def wrapper(channel_name, *args, **kwargs):
            logger.info("[{0}]: [{1}]".format(entry_path, channel_name))

            channel = get_channel_by_name(channel_name)
            if channel is None:
                msg = 'channel not exits: [{0}]'.format(channel_name)
                raise EntryAuthError(msg=msg)

            _verify_channel_perm(channel, entry_path)

            logger.info("[{0}] verify done.".format(entry_path))
            return f(channel_name, *args, **kwargs)
Exemplo n.º 3
0
Arquivo: manager.py Projeto: webee/pay
def test_transfer(channel_name, from_user_domain_name, from_user_id,
                  to_user_domain_name, to_user_id, amount, info):
    from api_x.zyt.user_mapping import get_channel_by_name
    from api_x.zyt.biz import transfer

    channel = get_channel_by_name(channel_name)
    if channel is None:
        print("channel [{0}] not exists.".format(channel_name))
        return

    tx = transfer.apply_to_transfer(channel, '', from_user_domain_name,
                                    from_user_id, to_user_domain_name,
                                    to_user_id, amount, info.decode('utf-8'))

    print('sn: %s' % tx.sn)
Exemplo n.º 4
0
def prepay_channel_order(order_channel, order_id):
    """超级支付接口"""
    channel = get_channel_by_name(order_channel)
    if channel is None:
        return response.refused('bad channel: [{0}]'.format(order_channel))

    try:
        payment_record = pay.find_payment(channel, order_id)
        return payment_record.tx
    except AlreadyPaidError as e:
        logger.exception(e)
        return response.fail(msg=e.message)
    except Exception as e:
        logger.exception(e)
        return response.fail(code=1, msg=e.message)
Exemplo n.º 5
0
        def wrapper(*args, **kwargs):
            try:
                params = {}
                params.update(request.values.items())
                params.update(request.view_args)

                logger.info("[{0}] {1}: {2}".format(entry_path, request.url, params))
                # check perm
                channel_name = params.get('channel_name')
                if channel_name is None:
                    return response.fail(msg='channel_name is needed.')

                channel = get_channel_by_name(channel_name)
                if channel is None:
                    msg = 'channel not exits: [{0}]'.format(channel_name)
                    return response.fail(msg=msg)

                try:
                    _verify_channel_perm(channel, entry_path)
                except EntryAuthError as e:
                    return response.refused(msg=e.message)

                # verify sign
                sign_type = params['sign_type']
                # 这里的主要作用是验签, 只需要channel_pub_key或md5_key
                try:
                    signer = Signer('key', 'sign', channel.md5_key, None, channel.public_key)
                    if not signer.verify(params, sign_type):
                        logger.warn('sign verify error: [{0}]'.format(params))
                        msg = 'sign error.'
                        return response.refused(msg=msg)
                except Exception as e:
                    logger.exception(e)
                    msg = 'sign error.'
                    return response.refused(msg=msg)
            except Exception as e:
                logger.exception(e)
                return response.bad_request(msg=e.message)

            logger.info("[{0}] verify done.".format(entry_path))
            request.__dict__['channel'] = channel
            request.__dict__['params'] = params
            return f(*args, **kwargs)
Exemplo n.º 6
0
def add_sign_for_params(channel_name, params, sign_type=SignType.RSA):
    if params is None:
        return params

    channel = get_channel_by_name(channel_name)

    # 这里的主要作用是签名,只需要lvye_pri_key或md5_key
    signer = Signer('key', 'sign', channel.md5_key, config.LVYE_PRI_KEY, None)
    # 用来加密lvye_pub_key
    channel_pub_key = public_key.loads_b64encoded_key(channel.public_key)
    params['channel_name'] = channel_name
    params['sign_type'] = sign_type
    params['sign'] = signer.sign(params, sign_type)
    # 每次动态生成此密码
    lvye_aes_key = gen_rand_str(16)
    params['_lvye_pub_key'] = aes.encrypt_to_base64(config.LVYE_PUB_KEY,
                                                    lvye_aes_key)
    params['_lvye_aes_key'] = channel_pub_key.encrypt_to_base64(lvye_aes_key)

    return params
Exemplo n.º 7
0
Arquivo: models.py Projeto: webee/pay
 def channel(self):
     from api_x.zyt.user_mapping import get_channel_by_name
     return get_channel_by_name(self.channel_name)