Example #1
0
 def __request_spending_money(self):
     RequestInquiry.create(
         Amount(self.__SPENDING_MONEY_AMOUNT, self.__CURRENCY_EUR),
         Pointer(self._POINTER_EMAIL, self.__SPENDING_MONEY_RECIPIENT),
         self.__REQUEST_SPENDING_DESCRIPTION, False)
     RequestInquiry.create(
         Amount(self.__SPENDING_MONEY_AMOUNT, self.__CURRENCY_EUR),
         Pointer(self._POINTER_EMAIL, self.__SPENDING_MONEY_RECIPIENT),
         self.__REQUEST_SPENDING_DESCRIPTION, False,
         self._second_monetary_account.id_)
Example #2
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)
    def send_request(self):
        """
        :rtype: None
        """

        RequestInquiry.create(
            Amount(self._REQUEST_AMOUNT_EUR, self._REQUEST_CURRENCY),
            self._get_alias_second_account(), self._DESCRIPTION, False)
 def make_payment(self, PaymentInfo: object):
     recipient = Pointer('IBAN', PaymentInfo.to_iban, "bunq")
     endpoint.Payment.create(
         amount=Amount(PaymentInfo.amount_string, 'EUR'),
         counterparty_alias=recipient,
         description=PaymentInfo.description,
         monetary_account_id=self._get_monetary_account_id_from_iban(
             PaymentInfo.from_iban))
Example #5
0
    def make_payment(self, amount_string, description, counterparty_alias):
        BunqContext._api_context = self._api_context
        BunqContext._user_context = self._user_context

        endpoint.Payment.create(
            amount=Amount(amount_string, self._CURRENCY_EUR),
            counterparty_alias=counterparty_alias,
            description=description,
        )
Example #6
0
    def make_request(self, amount_string, description, recipient):
        BunqContext._api_context = self._api_context
        BunqContext._user_context = self._user_context

        endpoint.RequestInquiry.create(
            amount_inquired=Amount(amount_string, self._CURRENCY_EUR),
            counterparty_alias=Pointer(self._POINTER_TYPE_EMAIL, recipient),
            description=description,
            allow_bunqme=True,
        )
Example #7
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)
Example #8
0
def convert_to_amount(amount, currency: str) -> Amount:
    """Convert any datatype to a Amount object

    Args:
        amount (any): Amount to convert

    Returns:
        str: Amount in valid currency string
    """
    # Source: https://stackoverflow.com/a/6539677
    return Amount("{0:.2f}".format(amount), currency)
Example #9
0
 def __request_spending_money_if_needed(self):
     if self.__should_request_spending_money():
         endpoint.RequestInquiry.create(
             amount_inquired=Amount(self._REQUEST_SPENDING_MONEY_AMOUNT,
                                    self._CURRENCY_EUR),
             counterparty_alias=Pointer(
                 self._POINTER_TYPE_EMAIL,
                 self._REQUEST_SPENDING_MONEY_RECIPIENT),
             description=self._REQUEST_SPENDING_MONEY_DESCRIPTION,
             allow_bunqme=False)
         sleep(self._REQUEST_SPENDING_MONEY_WAIT_TIME_SECONDS)
Example #10
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)
Example #11
0
def make_request(amount_string, description, recipient):
    """
    :type amount_string: str
    :type description: str
    :type recipient: str
    """

    endpoint.RequestInquiry.create(
        amount_inquired=Amount(amount_string, "EUR"),
        counterparty_alias=Pointer("PHONE_NUMBER", recipient),
        description=description,
        allow_bunqme=True)
Example #12
0
    def make_request(self, amount_string, description, recipient):
        """
        :type amount_string: str
        :type description: str
        :type recipient: str
        """

        endpoint.RequestInquiry.create(
            amount_inquired=Amount(amount_string, self._CURRENCY_EURL),
            counterparty_alias=Pointer(self._POINTER_TYPE_EMAIL, recipient),
            description=description,
            allow_bunqme=True)
Example #13
0
    def make_payment(self, amount_string, description, recipient):
        """
        :type amount_string: str
        :type description: str
        :type recipient: str
        """

        endpoint.Payment.create(amount=Amount(amount_string,
                                              self._CURRENCY_EURL),
                                counterparty_alias=Pointer(
                                    self._POINTER_TYPE_EMAIL, recipient),
                                description=description)
Example #14
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
Example #15
0
 def make_payment(self,
                  amount_string,
                  description,
                  recipient,
                  geolocation=None):
     """
     :type amount_string: str
     :type description: str
     :type recipient: str
     """
     if geolocation is None:
         endpoint.Payment.create(amount=Amount(amount_string,
                                               self._CURRENCY_EURL),
                                 counterparty_alias=Pointer(
                                     self._POINTER_TYPE_EMAIL, recipient),
                                 description=description)
     else:
         endpoint.Payment.create(
             amount=Amount(amount_string, self._CURRENCY_EURL),
             counterparty_alias=Pointer(self._POINTER_TYPE_EMAIL,
                                        recipient),
             description=description,
             custom_headers={"X-Bunq-Geolocation": geolocation})
Example #16
0
    def _add_item_to_tab(self, tab_uuid):
        """
        :param tab_uuid:
        :type tab_uuid: str
        """

        tab_item_map = {
            TabItemShop.FIELD_AMOUNT: Amount(self._AMOUNT_EUR,
                                             self._CURRENCY),
            TabItemShop.FIELD_DESCRIPTION: self._TAB_ITEM_FIELD_DESCRIPTION,
        }
        TabItemShop.create(self._API_CONTEXT, tab_item_map, self._USER_ID,
                           self._MONETARY_ACCOUNT_ID,
                           self._CASH_REGISTER_ID,
                           tab_uuid)
Example #17
0
    def test_create_and_update_tab(self):
        """
        Tests the creation of a Tab, adds a tab item to it and updates this tab

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

        if BunqContext.user_context().is_only_user_person_set():
            return unittest.skip(self._ERROR_ONLY_USER_COMPANY_CAN_CREATE_TAB)

        tab_uuid = TabUsageSingle.create(
            self._get_cash_register_id(), self._TAB_DESCRIPTION,
            self._STATUS_OPEN, Amount(self._AMOUNT_EUR, self._CURRENCY)).value

        self._add_item_to_tab(tab_uuid)
        self._update_tab(tab_uuid)
Example #18
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(OPTION_API_KEY)
    all_option = parser.parse_args()

    if all_option.api_key is None:
        raise BunqException(ERROR_OPTION_MISSING_API_KEY)

    api_context = ApiContext(ApiEnvironmentType.PRODUCTION, all_option.api_key, '*')
    BunqContext.load_api_context(api_context)
    end = 50
    for i in range(0, end):
        endpoint.Payment.create(amount=Amount('0.01', 'EUR'),
                                counterparty_alias=Pointer('IBAN', '', ''),
                                description=str(round(i / end * 100, 2)) + " Prozent von deinem Geld",
                                monetary_account_id=)
        time.sleep(0.33333)
Example #19
0
    def send_request(self):
        """
        :rtype: None
        """

        request_map = {
            RequestInquiry.FIELD_AMOUNT_INQUIRED:
            Amount(self._REQUEST_AMOUNT_EUR, self._REQUEST_CURRENCY),
            RequestInquiry.FIELD_DESCRIPTION:
            self._FIELD_DESCRIPTION,
            RequestInquiry.FIELD_COUNTERPARTY_ALIAS:
            self._COUNTER_PARTY_SAME_USER,
            RequestInquiry.FIELD_ALLOW_BUNQME:
            False,
        }

        RequestInquiry.create(self._API_CONTEXT, request_map, self._USER_ID,
                              self._MONETARY_ACCOUNT_ID)
Example #20
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)
Example #21
0
    def test_create_and_update_tab(self):
        """
        Tests the creation of a Tab, adds a tab item to it and updates this tab

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

        create_map = {
            TabUsageSingle.FIELD_STATUS: self._STATUS_OPEN,
            TabUsageSingle.FIELD_DESCRIPTION: self._TAB_FIELD_DESCRIPTION,
            TabUsageSingle.FIELD_AMOUNT_TOTAL: Amount(self._AMOUNT_EUR,
                                                      self._CURRENCY)
        }
        tab_uuid = TabUsageSingle.create(self._API_CONTEXT, create_map,
                                         self._USER_ID,
                                         self._MONETARY_ACCOUNT_ID,
                                         self._CASH_REGISTER_ID).value

        self._add_item_to_tab(tab_uuid)
        self._update_tab(tab_uuid)
def top_up(conf=None, amount=1000.):
    """Top up a sandbox bunq account by the specified amount"""
    CTX = service.config.Context

    if conf:
        CTX._reload_bunq_ctx(conf)

    acct = service.bunq.list_accounts()[0]

    acct_id = acct['id']
    balance = float(acct['balance'])
    click.echo(f'Current balance: {balance:.2f}')
    time.sleep(1.5)

    amount_to_add = amount
    max_request_amount = 500

    while amount_to_add > 0:
        if amount_to_add > max_request_amount:
            request_amount = max_request_amount
        else:
            request_amount = amount_to_add

        amount_to_add -= request_amount

        endpoint.RequestInquiry.create(
            amount_inquired=Amount(str(request_amount), 'EUR'),
            counterparty_alias=Pointer('EMAIL', '*****@*****.**'),
            description='Requesting some spending money.',
            allow_bunqme=False,
            monetary_account_id=acct_id)

        click.echo(f'\rTotal added: {amount-amount_to_add:.2f}')
        time.sleep(1.5)

    acct = service.bunq.list_accounts()[0]
    balance = float(acct['balance'])
    click.echo(f'New balance: {balance:.2f}')
Example #23
0
 def test_send_pay_request(self):
     RequestInquiry.create(amount_inquired=Amount('400', currency='EUR'),
                           counterparty_alias=Pointer(
                               'EMAIL', '*****@*****.**'),
                           description='Gimme tha monnies',
                           allow_bunqme=True)
Example #24
0
def main():

    all_option = ShareLib.parse_all_option()
    environment_type = ShareLib.determine_environment_type_from_all_option(all_option)

    bunq = BunqLib(environment_type)

    account_a = None
    account_b = None

    account_a_id = "17952"
    account_b_id = "17958"

    if all_option.topdown_from_account:
        try:
            # Try usingbunq account id
            account_a = MonetaryAccountBank.get(all_option.topdown_from_account)
            account_a = account_a.value
            account_a_id = account_a.id_
            print(" Watching (bunq_id): %s" % all_option.topdown_from_account)
        except Exception as e:
            # Check for iban / phone /whatever alias
            for account in bunq.get_all_monetary_account_active():
                for alias in account.alias:
                    if alias.value == all_option.topdown_from_account:
                        account_a = account
                        account_a_id = account_a.id_
                        print(" Watching: %s" % all_option.topdown_from_account)
    else:
        return

    if all_option.topdown_to_account:
        try:
            # Try using bunq account id
            account_b = MonetaryAccountBank.get(all_option.topdown_to_account)
            account_b = account_b.value
            account_b_id = account_b.id_
            print(" Sending extra Money to (bunq_id): %s" % all_option.topdown_to_account)
        except Exception as e:
            # Check for iban / phone / whatever alias
            for account in bunq.get_all_monetary_account_active():
                for alias in account.alias:
                    if alias.value == all_option.topdown_to_account:
                        account_b = account
                        account_b_id = account_b.id_
                        print(" Sending extra Money To: %s" % all_option.topdown_to_account)
    else:
        return

    max_value = Decimal(125)
    if all_option.amount:
        max_value = Decimal(all_option.amount)
        print("Maximum Money to keep: %s" % max_value)
    else:
        return

    if environment_type is ApiEnvironmentType.SANDBOX:
        # In Sandbox use Fallback

        if account_b is None:
            print("Using Sandbox fallback")
            account_b_id = "17958"

        if account_a is None:
            account_a_id = "17952"
            print("Using Sandbox fallback")
            try:
                account_a = MonetaryAccountBank.get(account_a_id)
                account_a = account_a.value
            except:
                pass
            finally:
                if account_a is None:
                    return

    if account_a is not None and account_b_id is not None:
        a_balance = Decimal(account_a.balance.value)
        print("Balance (%s): %s of Max %s" % (account_a.id_, a_balance, max_value))
        if account_a.balance.currency != account_b.balance.currency:
            print("Auto Top-Down not Possible, currencies don't match!")
            return
        if a_balance > max_value:
            delta = a_balance - max_value
            # send delta amount to b
            print(" Moving %s to %s" % (delta, account_b_id))
            description = "Auto Down"
            amount_string = str(delta)
            Payment.create(
                amount=Amount(amount_string, account_a.balance.currency),
                monetary_account_id=account_a_id,
                counterparty_alias=ShareLib.get_first_pointer_iban(account_b),
                description=description
            )
        else:
            print(" Balance OK")

    bunq.update_context()
Example #25
0
 def _make_savings_payment(cls, amount, from_id):
     endpoint.Payment.create(Amount(str(amount), 'EUR'),
                             cls._get_savings_account(),
                             description='Saving with Pinsparen',
                             monetary_account_id=int(from_id))
Example #26
0
 def draftPaymentEntryByValue(input_account: MonetaryAccountBank,
                              output_account: Pointer, value: Decimal,
                              description: str) -> DraftPaymentEntry:
     return DraftPaymentEntry(Amount(str(value), input_account.currency),
                              output_account, description)