Ejemplo n.º 1
0
    def test_bind_once(self):
        remote_account = YixinAccount.get_by_local(self.local_account.id)
        assert remote_account is None

        YixinAccount.bind(self.local_account.id, *self.remote_user_info)
        remote_account = YixinAccount.get_by_local(self.local_account.id)
        assert remote_account is not None

        assert remote_account.account_id == self.local_account.id
        assert remote_account.p2p_account == self.remote_user_info[0]
        assert remote_account.p2p_token == self.remote_user_info[1]
Ejemplo n.º 2
0
    def test_bind_twice(self):
        remote_account = YixinAccount.get_by_local(self.local_account.id)
        assert remote_account is None

        YixinAccount.bind(self.local_account.id, *self.alternative_user_info)
        remote_account = YixinAccount.get_by_local(self.local_account.id)
        assert remote_account.p2p_account == self.alternative_user_info[0]
        assert remote_account.p2p_token == self.alternative_user_info[1]

        # the last bound information should be overrided
        YixinAccount.bind(self.local_account.id, *self.remote_user_info)
        remote_account = YixinAccount.get_by_local(self.local_account.id)
        assert remote_account.p2p_account == self.remote_user_info[0]
        assert remote_account.p2p_token == self.remote_user_info[1]
Ejemplo n.º 3
0
def token_dump(user_alias, workdir=None):
    """Dumps API token from database."""
    account = Account.get_by_alias(user_alias)
    if not account:
        return bcolors.fail('user %r not found' % user_alias)

    workdir = os.path.expanduser(workdir or '~/.guihua')
    if not os.path.exists(workdir):
        os.makedirs(workdir)

    yixin_account = YixinAccount.get_by_local(account.id_)
    if not yixin_account:
        return bcolors.fail('%r need to bind yixin account' % user_alias)

    jsonfile_location = os.path.join(workdir, 'solar-yixin-token.json')

    if os.path.exists(jsonfile_location):
        with open(jsonfile_location) as jsonfile:
            data = json.load(jsonfile)
        if not isinstance(data, dict):
            return bcolors.fail('unexpected data')
    else:
        data = {}

    data[user_alias] = {
        'user_alias': user_alias,
        'yixin_account': yixin_account.p2p_account,
        'yixin_token': yixin_account.p2p_token,
    }

    with open(jsonfile_location, 'w') as jsonfile:
        json.dump(data, jsonfile, indent=4)

    bcolors.success('success: %s %s' % (user_alias, yixin_account.p2p_account))
Ejemplo n.º 4
0
def hoard_yrd_withdrawing(order_id):
    """设置宜人贷提现银行卡."""
    from core.models.hoard import YixinAccount, HoardOrder

    order = HoardOrder.get(order_id)
    if order.fetch_status() != u'已转出':
        token = YixinAccount.get_by_local(order.user_id).p2p_token
        order.register_for_withdrawing(yixin.client, token)
Ejemplo n.º 5
0
def hoard_yrd_confirming(order_id):
    """确认宜人贷订单状态"""
    from core.models.hoard import YixinAccount, HoardOrder
    from core.models.hoard.order import RemoteStatus

    order = HoardOrder.get(order_id)
    token = YixinAccount.get_by_local(order.user_id).p2p_token
    response = yixin.query.order_status(token, order.order_id, max_retry=3)
    status = RemoteStatus(response.data.status)

    if status == RemoteStatus.success:
        order.mark_as_confirmed()
    elif status == RemoteStatus.unknown:
        raise WorkerTaskError(hoard_yrd_confirming.tube)  # let it fail
    elif status == RemoteStatus.failure:
        order.mark_as_failure()
        raise WorkerTaskError(hoard_yrd_confirming.tube)  # let it fail
    else:
        raise WorkerTaskError(hoard_yrd_confirming.tube)  # let it fail
Ejemplo n.º 6
0
def initialize_yixin():
    if hasattr(request, 'oauth'):
        g.yixin_account = YixinAccount.get_by_local(request.oauth.user.id_)
    else:
        g.yixin_account = None