Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

Create Transaction/Transfer #21

Closed
sirexeclp opened this issue Mar 26, 2019 · 7 comments
Closed

Create Transaction/Transfer #21

sirexeclp opened this issue Mar 26, 2019 · 7 comments
Labels

Comments

@sirexeclp
Copy link

Hi,
i forked your repo and im working on sending bank transactions.
So far im getting a 400 Client error.
Can someone help me with this one ?
Here my function and the modification on _do_request post json (not as url parameter).

def create_transaction(self,pin,bic,amount,iban,name,reference):
        return self._do_request(POST, BASE_URL + '/api/transactions',{
            "pin":pin
            ,"transaction":
            {
                "partnerBic": bic,
                "amount":     float(amount),
                "type":            "DT",
                "partnerIban": iban,
                "partnerName": name,
                "referenceText": reference
            }
        }
        ,json=True)
def _do_request(self, method=GET, url="/", params={},json=False):
        access_token = self._get_token()
        headers = {'Authorization': 'bearer' + str(access_token)}

        first_param = True
        if not json:
            for k, v in params.items():
                if not v:
                    # skip None values
                    continue

                if first_param:
                    url += '?'
                    first_param = False
                else:
                    url += '&'

                url += "%s=%s" % (k, v)

        if method is GET:
            response = requests.get(url, headers=headers)
        elif method is POST:
            if json:
                response = requests.post(url, headers=headers,json=params)
            else:
                response = requests.post(url, headers=headers)
        else:
            return None

        response.raise_for_status()
        return response.json()
@markusressel
Copy link
Collaborator

First thing would advise to do is to not use json as a boolean parameter to change the meaning of another parameter. This is confusing and unnecessary. Python supports named parameters so just add a json parameter that can be used in addition to the params parameter. The params parameter has a default for a reason (so you can omit it when calling the function). If you want to make it more clear you can rename the params parameter to query_params if you like. You would then call it like this:

self._do_request(POST, BASE_URL + '/api/transactions', json={
   "your": "json content"
})

If you use None as the default value for the json parameter you can then join those 4 lines:

  if json:
    response = requests.post(url, headers=headers,json=params)
  else:
    response = requests.post(url, headers=headers)

into a single one:

response = requests.post(url, headers=headers, json=json)

since in requests.post() the json parameter is None by default anyway (so passing in None explicitly won't break anything).

@markusressel
Copy link
Collaborator

As for the 400 error, where did you get the info on how to create a transaction using the REST api?

@sirexeclp
Copy link
Author

sirexeclp commented Mar 26, 2019

Regarding your first comment: It was just a quick hack to get things working for me. (I will refactor that. Thanks for the tip.)
Secondly: I found this discontinued? node.js wrapper https://github.com/PierrickP/n26/blob/develop/lib/api.js and basically tried to port the createTransfer function. I also took a look at the n26 website where I found this value of a hidden field, when sending a sepa transaction:

mutation sendSEPATransaction(
  $pin: String!
  $amount: Float!
  $type: TransactionType!
  $partnerBic: String
  $partnerIban: String!
  $partnerName: String!
  $referenceText: String
  $executionFrequency: FrequencyEnum
  $transferDate: String
  $stopDate: String
) {
  sendSEPATransaction(
    pin: $pin
    amount: $amount
    type: $type
    partnerBic: $partnerBic
    partnerIban: $partnerIban
    partnerName: $partnerName
    referenceText: $referenceText
    executionFrequency: $executionFrequency
    transferDate: $transferDate
    stopDate: $stopDate
  ) {
    status
    errors {
      translationKey
      message
    }
  }
}

! probably mark fields that are required.
I know that the Website does not directly interact with the api but instead uses a different endpoint.

@markusressel
Copy link
Collaborator

Interesting 🤔 I found this repo while googling for the one you might have used:
https://github.com/leuchte/number26
It uses the same (json) layout.
I'm afraid the API doesn't work like that anymore if this doesn't work. I did some testing on my machine too and was not successful. Sadly the API seems to always respond with a 400 no matter what is wrong with the request so debugging is almost impossible.

@stale
Copy link

stale bot commented Apr 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 29, 2019
@femueller
Copy link
Owner

Closing because there doesn't seem to be any activity anymore on this issue.

@markusressel
Copy link
Collaborator

Just wanted to mention that this is now implemented, thanks to #90

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants