I'm not guru in python. I don't get why I can't assign an array of values to a key for this dictionnary with this def.
This is how I use the sdk definition.
order_obj = Order(None)
order_obj.customerIp("14.140.42.67")
order_obj.merchantRefNum(RandomTokenGenerator().generateToken())
order_obj.currencyCode("CAD")
order_obj.totalAmount("1125")
redirect = Redirect(None)
redirect.rel("on_success")
redirect.uri("http://outwander.ca:{}/redirect")
return_keys_list = []
return_keys_list.append('id')
return_keys_list.append('transaction.amount')
redirect.returnKeys(return_keys_list)
redirect_list = []
redirect_list.append(redirect.__dict__)
order_obj.redirect(redirect_list)
This is the specific definition in the sdk I use https://github.com/OptimalPayments/Python_SDK/blob/63e1ae662a4447bd65c907563eec9effc602dd74/src/PythonNetBanxSDK/HostedPayment/Redirect.py
'''
Property Return Keys
'''
def returnKeys(self, return_keys):
self.__dict__['returnKeys'] = return_keys
From what I could debug, the problems comes when converting the array into json to be sent.The loop finds the array and try to convert the elements inside (strings), but since by default the loop consider each given parameter as array, the returnKeys parameter is skipped...
'''
Serializing object
@param: Dictionary Object
@return: Serialized data
'''
def serialize(self, obj):
return (json.dumps(self.to_dictionary(obj)))
'''
Convert object to a dictionary
@param: POJO Object
@return: Dictionary Object
'''
def to_dictionary(self, obj):
obj_dict = dict()
for key in obj.__dict__.keys():
try:
if(type(obj.__dict__[key]) is list):
content = []
for count in range(0, obj.__dict__[key].__len__()):
content.append(
self.to_dictionary(obj.__dict__[key][count]))
obj_dict[key] = content
elif(isinstance(obj.__dict__[key], DomainObject)):
obj_dict[key] = self.to_dictionary(obj.__dict__[key])
else:
obj_dict[key] = obj.__dict__[key]
except KeyError:
pass
except AttributeError:
pass
return (obj_dict)
I have no problem assigning a key to one value, but when I try assigning an array to a key, it doesn't work and it just ignore this key from the json output.
SOLUTION (HACK)
order_obj = Order(None)
order_obj.customerIp("14.140.42.67")
order_obj.merchantRefNum(RandomTokenGenerator().generateToken())
order_obj.currencyCode("CAD")
order_obj.totalAmount("1125")
redirect = Redirect(None)
redirect.rel("on_success")
redirect.uri("http://outwander.ca:{}/redirect")
redirect.returnKeys(('id', 'transaction.amount'))
redirect_list = []
redirect_list.append(redirect.__dict__)
order_obj.redirect((redirect_list))