def get_transactions(self, account): pagination = Pagination() pagination.count = 100 payments_response = endpoint.Payment.list( account.id_, params=pagination.url_params_count_only) print("Translating payments...") transactions = [] first_day = None last_day = None unsorted_payments = payments_response.value payments = sorted(unsorted_payments, key=lambda payment: payment.created) for payment in payments: if payment.amount.currency != "EUR": raise Exception("Non-euro payment: " + payment.amount.currency) date = payment.created[:10] if not first_day or date < first_day: first_day = date if not last_day or last_day < date: last_day = date transactions.append({ "amount": payment.amount.value, "date": date, "payee": payment.counterparty_alias.pointer.name, "description": payment.description }) # For correct duplicate calculation, return only complete days return [ t for t in transactions if first_day < t["date"] or t["date"] == last_day ]
def get_monetary_account( value_type: str, value: str ) -> Union[MonetaryAccountBank, MonetaryAccountJoint, MonetaryAccountLight]: """Get account with api types Args: type (str): Possible values: IBAN, EMAIL, PHONE_NUMBER value (str): Value of defined type Returns: int: monetary account id Raises: ValueError: If match is not found """ pagination = Pagination() pagination.count = 25 # maximum of accounts monetaryaccount_list = MonetaryAccount.list( params=pagination.url_params_count_only).value for monetaryaccount in monetaryaccount_list: account = monetaryaccount.MonetaryAccountBank or \ monetaryaccount.MonetaryAccountJoint or \ monetaryaccount.MonetaryAccountLight or \ monetaryaccount.MonetaryAccountSavings for alias in account.alias: if alias.type_ == value_type and alias.value == value: return account raise ValueError
def _payments_required(self): """ :rtype: list[endpoint.Payment] """ pagination = Pagination() pagination.count = self._PAYMENT_REQUIRED_COUNT_MINIMUM return self._list_payments(pagination.url_params_count_only).value
def get_all_card(self, count=_DEFAULT_COUNT): """ :type count: int :rtype: list(endpoint.Card) """ pagination = Pagination() pagination.count = count return endpoint.Card.list(pagination.url_params_count_only).value
def get_all_request(self, count=_DEFAULT_COUNT): """ :type count: int :rtype: list[endpoint.RequestInquiry] """ pagination = Pagination() pagination.count = count return endpoint.RequestInquiry.list( params=pagination.url_params_count_only).value
def get_all_payment(self, count=_DEFAULT_COUNT): """ :type count: int :rtype: list[Payment] """ pagination = Pagination() pagination.count = count return endpoint.Payment.list( params=pagination.url_params_count_only).value
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
def deserialize(cls, target_class: Type[Pagination], pagination_response: Dict) -> Pagination: pagination = Pagination() pagination.__dict__.update( cls.parse_pagination_dict(pagination_response)) return pagination
def get_all_monetary_account_active(self, count=_DEFAULT_COUNT): """ :type count: int :rtype: list[endpoint.MonetaryAccountBank] """ pagination = Pagination() pagination.count = count all_monetary_account_bank = endpoint.MonetaryAccountBank.list( pagination.url_params_count_only).value all_monetary_account_bank_active = [] for monetary_account_bank in all_monetary_account_bank: if monetary_account_bank.status == \ self._MONETARY_ACCOUNT_STATUS_ACTIVE: all_monetary_account_bank_active.append(monetary_account_bank) return all_monetary_account_bank_active
def _create_pagination_with_all_properties_set(self) -> Pagination: pagination = Pagination() pagination.older_id = self._PAGINATION_OLDER_ID_CUSTOM pagination.newer_id = self._PAGINATION_NEWER_ID_CUSTOM pagination.future_id = self._PAGINATION_FUTURE_ID_CUSTOM pagination.count = self._PAGINATION_COUNT_CUSTOM return pagination
def test_api_scenario_payment_listing_with_pagination(self): self._ensure_enough_payments() payments_expected = self._payments_required() pagination = Pagination() pagination.count = self._PAYMENT_LISTING_PAGE_SIZE response_latest = self._list_payments(pagination.url_params_count_only) pagination_latest = response_latest.pagination response_previous = self._list_payments( pagination_latest.url_params_previous_page ) pagination_previous = response_previous.pagination response_previous_next = self._list_payments( pagination_previous.url_params_next_page ) payments_previous = response_previous.value payments_previous_next = response_previous_next.value payments_actual = payments_previous_next + payments_previous payments_expected_serialized = converter.serialize(payments_expected) payments_actual_serialized = converter.serialize(payments_actual) self.assertEqual(payments_expected_serialized, payments_actual_serialized)