Esempio n. 1
0
def find_user_with_transfer_account_from_identifiers(user_id, public_identifier, transfer_account_id):

    user = find_user_from_identifiers(user_id, public_identifier, transfer_account_id)

    if user and not user.transfer_accounts:
        raise NoTransferAccountError('User {} does not have a transfer account'.format(user))

    return user
Esempio n. 2
0
    def __init__(self,
                 amount,
                 sender=None,
                 recipient=None,
                 transfer_type=None,
                 uuid=None):

        if uuid is not None:
            self.uuid = uuid

        if sender is not None:
            self.sender_user = sender
            self.sender_transfer_account = sender.transfer_account

            if self.sender_transfer_account is None:
                raise NoTransferAccountError(
                    "No transfer account for user {}".format(sender))

        if recipient is not None:
            self.recipient_user = recipient
            self.recipient_transfer_account = recipient.transfer_account

            if self.recipient_transfer_account is None:
                raise NoTransferAccountError(
                    "No transfer account for user {}".format(recipient))

        if self.sender_transfer_account and self.recipient_transfer_account:
            self.transfer_type = TransferTypeEnum.PAYMENT
        elif self.recipient_transfer_account:
            self.transfer_type = TransferTypeEnum.DISBURSEMENT
        elif self.sender_transfer_account:
            self.transfer_type = TransferTypeEnum.WITHDRAWAL
        else:
            raise ValueError(
                "Neither sender nor recipient transfer accounts found")

        # Optional check to enforce correct transfer type
        if transfer_type and not self.check_has_correct_users_for_transfer_type(
                self.transfer_type, self.sender_user, self.recipient_user):
            raise InvalidTransferTypeException("Invalid transfer type")

        self.transfer_amount = amount
Esempio n. 3
0
def find_transfer_accounts_with_matching_token(account_holder, token):
    matching_transfer_accounts = []
    for transfer_account in account_holder.transfer_accounts:
        if transfer_account.token == token:
            matching_transfer_accounts.append(transfer_account)
    if len(matching_transfer_accounts) == 0:
        raise NoTransferAccountError(
            f"No transfer account for holder {account_holder} and token {token}"
        )
    if len(matching_transfer_accounts) > 1:
        raise Exception(
            f"User has multiple transfer accounts for token {token}")
    return matching_transfer_accounts[0]