bunq / sdk_python

Python SDK for bunq API
MIT License
106 stars 25 forks source link

Name field for pointer counterparty #29

Closed y0sh1 closed 6 years ago

y0sh1 commented 6 years ago

Hey Guys!

Awesome work on the API. Been playing around with it for a while now and thought now was the time to get into automated payments.

When doing this I ran into to the problem of transfering money to myself. The only way I found that would work, is to transfer it to the iban of the account I wanted it in.

So i started with the payment requestmap, like the example:

request_map = {
    generated.Payment.FIELD_AMOUNT: object_.Amount(
        str(pin_saving_amount),
        'EUR'
    ),
    generated.Payment.FIELD_COUNTERPARTY_ALIAS: object_.Pointer(
        'IBAN',
        'NL13BUNQ3713371337'
    ),
    generated.Payment.FIELD_DESCRIPTION: 'Pinsparen {}'.format(yesterday),
}

This bounded when creating the payment, because the name field was not set. Now i thought this was an error on my end, but looking in the SDK code I came across the reason didn't see it coming in the first place. Note that the api docs state this is needed, so I could have used my eyes to start with šŸ˜‡ .

class Pointer(model.BunqModel):
    """
    :type type_: str
    :type value: str
    :type name: str
    """

    def __init__(self, type_, value):
        """
        :type type_: str
        :type value: str
        """

        self.type_ = type_
        self.value = value
        self.name = None

This is a piece of code from: https://github.com/bunq/sdk_python/blob/b905e97cde4acd5fa4c0e356c04af82b867481ca/bunq/sdk/model/generated/object_.py#L143

As can be seen the name object is None by default and not set-able on init, which would make sense to do if you'd like to enforce people to use it in some cases.

Since this code is in the "generated" directory i didn't start creating a PR already, because i would like to verify if that would be a 'good move' or this is something that had to be done on bunq's side for generating the code.

Anyway, the following code would make a good replacement:

class Pointer(model.BunqModel):
    """
    :type type_: str
    :type value: str
    :type name: str
    """

    def __init__(self, type_, value, name=None):
        """
        :type type_: str
        :type value: str
        :type name: str
        """

        self.type_ = type_
        self.value = value
        self.name = name

This way name will be None by default, but at least set-able at creation šŸ™‚

dnl-blkv commented 6 years ago

@y0sh1 thanks for the suggestion!

The code is indeed generated and should be changed on our side :)

The reason we did not do it this way initially is that in Java it would require a lot of extra code to be generated. However, since this issue was raised already more than once, now we don't have any options but look into it šŸ‘

I'll post updates to this issue!

OGKevin commented 6 years ago

This is related to bunq/sdk_python#55 and will be closed once the referenced issue is closed.

duplicate #55

OGKevin commented 6 years ago

Closing in favour of #55