예제 #1
0
def create_payment(monetary_account_id: int, amount: Amount,
                   counterparty_alias: Pointer, description: str):
    Payment.create(
        monetary_account_id=monetary_account_id,
        amount=amount,
        counterparty_alias=counterparty_alias,
        description=description,
    )
예제 #2
0
    def test_payment_to_other_account(self):
        """
        Tests making a payment to another monetary account of the same user

        This test has no assertion as of its testing to see if the code runs
        without errors
        """

        Payment.create(
            Amount(self._PAYMENT_AMOUNT_EUR, self._PAYMENT_CURRENCY),
            self._get_alias_second_account(), self._PAYMENT_DESCRIPTION)
예제 #3
0
    def test_payment_to_other_user(self):
        """
        Tests making a payment to another sandbox user

        This test has no assertion as of its testing to see if the code runs
        without errors
        """

        Payment.create(
            Amount(self._PAYMENT_AMOUNT_EUR, self._PAYMENT_CURRENCY),
            self._get_pointer_bravo(), self._PAYMENT_DESCRIPTION)
예제 #4
0
    def test_payment_chat(self):
        """
        Tests sending a chat message in a newly created payment

        This test has no assertion as of its testing to see if the code runs
        without errors
        """

        request_map = {
            Payment.FIELD_COUNTERPARTY_ALIAS:
            self._COUNTER_PARTY_OTHER_USER,
            Payment.FIELD_AMOUNT:
            Amount(self._PAYMENT_AMOUNT_EUR, self._PAYMENT_CURRENCY),
            Payment.FIELD_DESCRIPTION:
            self._PAYMENT_DESCRIPTION,
        }
        payment_id = Payment.create(self._API_CONTEXT, request_map,
                                    self._USER_ID,
                                    self._MONETARY_ACCOUNT_ID).value

        chat_map = {}
        chat_id = PaymentChat.create(self._API_CONTEXT, chat_map,
                                     self._USER_ID, self._MONETARY_ACCOUNT_ID,
                                     payment_id).value

        message_map = {
            ChatMessageText.FIELD_TEXT: self._PAYMENT_CHAT_TEXT_MESSAGE,
        }
        ChatMessageText.create(self._API_CONTEXT, message_map, self._USER_ID,
                               chat_id)
예제 #5
0
    def test_payment_to_other_account(self):
        """
        Tests making a payment to another monetary account of the same user

        This test has no assertion as of its testing to see if the code runs
        without errors
        """

        request_map = {
            Payment.FIELD_COUNTERPARTY_ALIAS:
            self._COUNTER_PARTY_SAME_USER,
            Payment.FIELD_DESCRIPTION:
            self._PAYMENT_DESCRIPTION,
            Payment.FIELD_AMOUNT:
            Amount(self._PAYMENT_AMOUNT_EUR, self._PAYMENT_CURRENCY),
        }
        Payment.create(self._API_CONTEXT, request_map, self._USER_ID,
                       self._MONETARY_ACCOUNT_ID)
예제 #6
0
def get_payments(monetary_account_id: int, includes: Optional[List[str]],
                 excludes: Optional[List[str]],
                 start_date: Optional[datetime.datetime],
                 end_date: Optional[datetime.datetime]) -> List[Payment]:
    """Get events for a certain account

    Args:
        monetary_account_id (int): Monetary account id
        includes (List[str]): IBAN number to include
        excludes (List[str]): IBAN numbers to exclude
        start_date (datetime.datetime): Date to start looking for payments
        end_date (datetime.datetime): Date to stop looking for payments

    Returns:
        List[Event]: List of events
    """

    events: List[Payment] = []
    result: List[Payment] = []

    try:
        # Loop until we raise or return
        while True:
            # Check if first iteration (unsplit_payments empty)
            if not events:
                # We will loop over the payments in batches of 200
                pagination = Pagination()
                pagination.count = 200
                params = pagination.url_params_count_only
            else:
                # TODO: Fix this, this does not seem to work
                # BunqException('Could not generate previous page URL params: there is no previous page.',)

                # When there is already a paged request, you can get the next page from it, no need to create it ourselfs:
                try:
                    params = pagination.url_params_previous_page
                except BunqException:
                    # Break the loop, there is no more to process
                    raise StopIteration

            # Get events
            payments = Payment.list(
                params=params, monetary_account_id=monetary_account_id).value

            # Filter out all non relevant events
            payments = _filter_created_date(events=payments,
                                            start_date=start_date,
                                            end_date=end_date)
            return _filter_excluded_payments(payments=payments,
                                             includes=includes,
                                             excludes=excludes)

    except StopIteration:
        return result
예제 #7
0
    def __create_payment_list(self) -> List[Payment]:
        all_payment = []

        while len(all_payment) < self._MAXIMUM_PAYMENT_IN_BATCH:
            all_payment.append(
                Payment(
                    Amount(self._PAYMENT_AMOUNT_EUR, self._PAYMENT_CURRENCY),
                    Pointer(self._POINTER_EMAIL, self._EMAIL_BRAVO),
                    self._PAYMENT_DESCRIPTION))
        self.assertIsInstance(all_payment, List)
        self.assertIsInstance(all_payment[0], Payment)

        return all_payment