vcatalano / py-authorize

A full-featured Python API for the Authorize.net payment gateway.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error

cappy123abc opened this issue · comments

line 12 in batch.py missing params argument for Configuration.api.batch.list(). When I added this and ran

result = authorize.Batch.list({
'start': '2013-10-01',
'end': '2013-10-31',
})

I got the following error:

Traceback (most recent call last):
File "C:\Users\caleb\AppData\Local\Aptana Studio 3\plugins\org.python.pydev_2.7.0.2013032300\pysrc\pydevd.py", line 1397, in
debugger.run(setup['file'], None, None)
File "C:\Users\caleb\AppData\Local\Aptana Studio 3\plugins\org.python.pydev_2.7.0.2013032300\pysrc\pydevd.py", line 1090, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "C:\Users\caleb\AppData\Local\Aptana Studio 3\plugins\org.python.pydev_2.7.0.2013032300\pysrc_pydev_execfile.py", line 38, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc) #execute the script
File "C:\Users\caleb\Documents\Aptana Studio 3 Workspace\ln\Main App\CreditCardPayments.py", line 22, in
'end': '2013-10-31',
File "C:\Python33\lib\site-packages\py_authorize-1.0.1.3-py3.3.egg\authorize\batch.py", line 12, in list
return Configuration.api.batch.list(params)
File "C:\Python33\lib\site-packages\py_authorize-1.0.1.3-py3.3.egg\authorize\apis\batch_api.py", line 15, in list
return self.api._make_call(self._list_request(batch))
File "C:\Python33\lib\site-packages\py_authorize-1.0.1.3-py3.3.egg\authorize\apis\authorize_api.py", line 53, in _make_call
request = urllib.request.Request(self.config.environment, E.tostring(call))
File "C:\Python33\lib\xml\etree\ElementTree.py", line 1171, in tostring
ElementTree(element).write(stream, encoding, method=method)
File "C:\Python33\lib\xml\etree\ElementTree.py", line 828, in write
serialize(write, self._root, qnames, namespaces)
File "C:\Python33\lib\xml\etree\ElementTree.py", line 990, in _serialize_xml
_serialize_xml(write, e, qnames, None)
File "C:\Python33\lib\xml\etree\ElementTree.py", line 988, in _serialize_xml
write(_escape_cdata(text))
File "C:\Python33\lib\xml\etree\ElementTree.py", line 1122, in _escape_cdata
_raise_serialization_error(text)
File "C:\Python33\lib\xml\etree\ElementTree.py", line 1105, in _raise_serialization_error
"cannot serialize %r (type %s)" % (text, type(text).name)
TypeError: cannot serialize datetime.date(2013, 10, 1) (type date)

That's as far as I went.

This was fixed by changing lines 28 and 30 in batch_api.py to read:

def _list_request(self, params={}):
    request = self.api._base_request('getSettledBatchListRequest')
    E.SubElement(request, 'includeStatistics').text = 'true'
    if 'start' in params:
        E.SubElement(request, 'firstSettlementDate').text = params['start'].strftime("%Y-%m-%dT%H:%M:%S")
    if 'end' in params:
        E.SubElement(request, 'lastSettlementDate').text = params['end'].strftime("%Y-%m-%dT%H:%M:%S")
    return request

Sorry, I didn't check this project out. This probably isn't the correct way to solve the problem, but it gets the job done.

Hey @cappy123abc, thanks for finding that! There seems to be an issue with how I handle serializing the date parameters. I will take a look at this tonight.

Your date formatting looks good to me, and it passes the unit tests. I've added the changes to the code base.