SynapsePay & Django conflicting instances of User issue
Question:
My name is omar. I am working on a django project that is using the SynapsePay api for monetary transactions. I am getting an issue where I have two instances of the same object(User). Django uses the ‘User’ object when new users are created within the django application. Synapse uses the ‘User’ objects when a new user is created within their api. When i try to use the SYnapse api, I am starting to get conflicting uses of the same variable.
In the import statements, when I imported the user from the Synapse Api, I saved the instance of the user as SynapseUser and that is what I am using to interact with the application.
There are parts of the api that are not controllable by me that use the ‘User’ object within the Api and It is grabbing the wrong object or trying to grab a key that doesnt exist in the key that is being passed.
Here is the all the code I have and the error that I am trying to get…
THe following code is to grab the forms content and test the bank authroization with the api..
Here is a link to the api github samples.md file
Here is the views.py file:
import os
from synapse_pay_rest import Client
from synapse_pay_rest import User as SynapseUser
from synapse_pay_rest.models.nodes import AchUsNode
def linkBankLogin(request, form):
currentUser = loggedInUser(request)
cd = form.cleaned_data
bank_name = cd['bank']
username = cd['username']
password = cd['password']
required = {
'bank_name':'wellsfargo',
'username':'omarjandali',
'password':'123123asd'
}
ach_us = AchUsNode.create_via_bank_login(SynapseUser, **required)
ach_us.mfa_verified
Here is the error that I am getting when the user submits the linking account form:
AttributeError at /link_account/
type object 'User' has no attribute 'client'
Request Method: POST
Request URL: http://127.0.0.1:8000/link_account/
Django Version: 1.11.5
Exception Type: AttributeError
Exception Value:
type object 'User' has no attribute 'client'
Exception Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/synapse_pay_rest/models/nodes/ach_us_node.py in create_via_bank_login, line 39
create_via_bank_login is an internal method that is created within the api and not something I can change. How can i get it to grab the SynapseUser
** Update **
THe following code is what is used to look up a user by id:
user = User.by_id(client, '...4dc1')
so i can do something like this:
synapseUser = SynapseUser.by_id(client, '...4dc1')
because the code that I just added above worked in returning a created users information
and then instead of:
ach_us = AchUsNode.create_via_bank_login(SynapseUser, **required)
I can use:
ach_us = AchUsNode.create_via_bank_login(synapseUser, **required)
** Continued update **
I have the following code to perform what I wanted to integrate:
def searchUserSynapse(request):
currentUser = loggedInUser(request)
currentProfile = Profile.objects.get(user = currentUser)
synapse_id = currentProfile.synapse_id
user = SynapseUser.by_id(clients, str(synapse_id))
response = user.json
print(response)
return user
def linkBankLogin(request, form):
currentUser = loggedInUser(request)
cd = form.cleaned_data
bank_name = cd['bank']
username = cd['username']
password = cd['password']
required = {
'bank_name':'wellsfargo',
'username':'omarjandali',
'password':'123123asd'
}
response = searchUserSynapse(request)
ach_us = AchUsNode.create_via_bank_login(response, **required)
ach_us.mfa_verified
and the new error message is the following:
BadRequestError at /link_account/
No exception message supplied
Request Method: POST
Request URL: http://127.0.0.1:8000/link_account/
Django Version: 1.11.5
Exception Type: BadRequestError
Exception Location:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/synapse_pay_rest/http_client.py in parse_response, line 86
how can i find out where the request had the error??
Answers:
You need to pass an instance of the class SynapseUser
, not the class itself.
The line:
ach_us = AchUsNode.create_via_bank_login(SynapseUser, **required)
should be:
ach_us = AchUsNode.create_via_bank_login(user, **required)
where user
is of type SynapseUser
So you need to fetch the SynapseUser
for the django User
beforehand:
user = SynapseUser.by_id(client, synapse_user_id)
You will need to create a method to get the synapse_user_id
for a django user (in this case currentUser
)
I would recommend creating a UserProfile
class with a one-to-one relationship to User
where you can store this and other information.
See this post for example of how to set that up.
My name is omar. I am working on a django project that is using the SynapsePay api for monetary transactions. I am getting an issue where I have two instances of the same object(User). Django uses the ‘User’ object when new users are created within the django application. Synapse uses the ‘User’ objects when a new user is created within their api. When i try to use the SYnapse api, I am starting to get conflicting uses of the same variable.
In the import statements, when I imported the user from the Synapse Api, I saved the instance of the user as SynapseUser and that is what I am using to interact with the application.
There are parts of the api that are not controllable by me that use the ‘User’ object within the Api and It is grabbing the wrong object or trying to grab a key that doesnt exist in the key that is being passed.
Here is the all the code I have and the error that I am trying to get…
THe following code is to grab the forms content and test the bank authroization with the api..
Here is a link to the api github samples.md file
Here is the views.py file:
import os
from synapse_pay_rest import Client
from synapse_pay_rest import User as SynapseUser
from synapse_pay_rest.models.nodes import AchUsNode
def linkBankLogin(request, form):
currentUser = loggedInUser(request)
cd = form.cleaned_data
bank_name = cd['bank']
username = cd['username']
password = cd['password']
required = {
'bank_name':'wellsfargo',
'username':'omarjandali',
'password':'123123asd'
}
ach_us = AchUsNode.create_via_bank_login(SynapseUser, **required)
ach_us.mfa_verified
Here is the error that I am getting when the user submits the linking account form:
AttributeError at /link_account/
type object 'User' has no attribute 'client'
Request Method: POST
Request URL: http://127.0.0.1:8000/link_account/
Django Version: 1.11.5
Exception Type: AttributeError
Exception Value:
type object 'User' has no attribute 'client'
Exception Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/synapse_pay_rest/models/nodes/ach_us_node.py in create_via_bank_login, line 39
create_via_bank_login is an internal method that is created within the api and not something I can change. How can i get it to grab the SynapseUser
** Update **
THe following code is what is used to look up a user by id:
user = User.by_id(client, '...4dc1')
so i can do something like this:
synapseUser = SynapseUser.by_id(client, '...4dc1')
because the code that I just added above worked in returning a created users information
and then instead of:
ach_us = AchUsNode.create_via_bank_login(SynapseUser, **required)
I can use:
ach_us = AchUsNode.create_via_bank_login(synapseUser, **required)
** Continued update **
I have the following code to perform what I wanted to integrate:
def searchUserSynapse(request):
currentUser = loggedInUser(request)
currentProfile = Profile.objects.get(user = currentUser)
synapse_id = currentProfile.synapse_id
user = SynapseUser.by_id(clients, str(synapse_id))
response = user.json
print(response)
return user
def linkBankLogin(request, form):
currentUser = loggedInUser(request)
cd = form.cleaned_data
bank_name = cd['bank']
username = cd['username']
password = cd['password']
required = {
'bank_name':'wellsfargo',
'username':'omarjandali',
'password':'123123asd'
}
response = searchUserSynapse(request)
ach_us = AchUsNode.create_via_bank_login(response, **required)
ach_us.mfa_verified
and the new error message is the following:
BadRequestError at /link_account/
No exception message supplied
Request Method: POST
Request URL: http://127.0.0.1:8000/link_account/
Django Version: 1.11.5
Exception Type: BadRequestError
Exception Location:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/synapse_pay_rest/http_client.py in parse_response, line 86
how can i find out where the request had the error??
You need to pass an instance of the class SynapseUser
, not the class itself.
The line:
ach_us = AchUsNode.create_via_bank_login(SynapseUser, **required)
should be:
ach_us = AchUsNode.create_via_bank_login(user, **required)
where user
is of type SynapseUser
So you need to fetch the SynapseUser
for the django User
beforehand:
user = SynapseUser.by_id(client, synapse_user_id)
You will need to create a method to get the synapse_user_id
for a django user (in this case currentUser
)
I would recommend creating a UserProfile
class with a one-to-one relationship to User
where you can store this and other information.
See this post for example of how to set that up.