Skip to content

Commit a243a22

Browse files
author
Sunny Raj Rathod
authored
Merge pull request #63 from sunnyrajrathod/master
Q3 API Updates
2 parents 8941370 + e81fa73 commit a243a22

File tree

12 files changed

+9479
-6930
lines changed

12 files changed

+9479
-6930
lines changed

.coveragerc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[report]
2+
omit =
3+
*/python?.?/*
4+
*/site-packages/nose/*
5+
*/tests/*

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@ sudo: false
33

44
python:
55
- "2.7"
6+
- "3.4"
7+
- "3.5"
68
# - "pypy" Disabling pypy until travis moves to newer version, known issue with lxml crashing pypy
79

810
install:
911
- pip install unittest2
1012
- pip install nose
1113
- pip install pyxb
1214
- pip install lxml
15+
- pip install coveralls
1316

1417
before_script:
1518
- git submodule update --remote --recursive
1619

1720
script:
18-
- nosetests
21+
- nosetests --with-coverage -cover-package=authorizenet
22+
- coveralls
1923
- python setup.py install
2024
- cd sample-code-python
2125
- python ./test-runner.py

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
[![Travis](https://img.shields.io/travis/AuthorizeNet/sdk-python/master.svg)]
44
(https://travis-ci.org/AuthorizeNet/sdk-python)
5-
[![Coverage Status](https://coveralls.io/repos/github/AuthorizeNet/sdk-python/badge.svg?branch=master)]
6-
(https://coveralls.io/github/AuthorizeNet/sdk-python?branch=master)
5+
[![Coverage Status](https://coveralls.io/repos/github/AuthorizeNet/sdk-python/badge.svg?branch=master)](https://coveralls.io/github/AuthorizeNet/sdk-python?branch=master)
76
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/AuthorizeNet/sdk-python/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/AuthorizeNet/sdk-python/?branch=master)
87
[![PyPI](https://img.shields.io/pypi/v/authorizenet.svg)](https://badge.fury.io/py/authorizenet)
98

@@ -93,8 +92,9 @@ Requirements
9392

9493
Run the following to get pyxb and nosetests:
9594
- pip install pyxb
96-
- pip install nosetests
97-
- pip install Magicmock
95+
- pip install unittest2
96+
- pip install nose
97+
- pip install lxml
9898

9999
Testing
100100
--------------------------------------

authorizenet/apicontractsv1.py

Lines changed: 9360 additions & 6878 deletions
Large diffs are not rendered by default.

authorizenet/apicontrollersbase.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import sys
1010
import xml.dom.minidom
1111
from pip._vendor import requests
12-
from _pyio import __metaclass__
1312
from lxml import objectify
1413

1514
from authorizenet.constants import constants
@@ -87,8 +86,11 @@ def validate(self):
8786
self.validateandsetmerchantauthentication()
8887
self.validaterequest()
8988

90-
return
91-
89+
return
90+
91+
def setClientId(self): #protected method
92+
self._request.clientId = constants.clientId
93+
9294
def _getrequest(self): #protected method
9395
return self._request
9496

@@ -97,9 +99,9 @@ def buildrequest(self):
9799

98100
xmlRequest = self._request.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype())
99101
#remove namespaces that toxml() generates
100-
xmlRequest = xmlRequest.replace(constants.nsNamespace1, '')
101-
xmlRequest = xmlRequest.replace(constants.nsNamespace2, '')
102-
102+
xmlRequest = xmlRequest.replace(constants.nsNamespace1, b'')
103+
xmlRequest = xmlRequest.replace(constants.nsNamespace2, b'')
104+
103105
return xmlRequest
104106

105107
def getprettyxmlrequest(self):
@@ -123,6 +125,7 @@ def execute(self):
123125

124126
#requests is http request
125127
try:
128+
self.setClientId()
126129
xmlRequest = self.buildrequest()
127130
self._httpResponse = requests.post(self.endpoint, data=xmlRequest, headers=constants.headers, proxies=proxyDictionary)
128131
except Exception as httpException:
@@ -138,8 +141,8 @@ def execute(self):
138141
self._response = apicontractsv1.CreateFromDocument(self._httpResponse)
139142
#objectify code
140143
xmlResponse= self._response.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype())
141-
xmlResponse = xmlResponse.replace(constants.nsNamespace1, '')
142-
xmlResponse = xmlResponse.replace(constants.nsNamespace2, '')
144+
xmlResponse = xmlResponse.replace(constants.nsNamespace1, b'')
145+
xmlResponse = xmlResponse.replace(constants.nsNamespace2, b'')
143146
self._mainObject = objectify.fromstring(xmlResponse)
144147

145148
except Exception as objectifyexception:
@@ -148,21 +151,21 @@ def execute(self):
148151
self._response = apicontractsv1.CreateFromDocument(self._httpResponse)
149152
#objectify code
150153
xmlResponse= self._response.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype())
151-
xmlResponse = xmlResponse.replace(constants.nsNamespace1, '')
152-
xmlResponse = xmlResponse.replace(constants.nsNamespace2, '')
154+
xmlResponse = xmlResponse.replace(constants.nsNamespace1, b'')
155+
xmlResponse = xmlResponse.replace(constants.nsNamespace2, b'')
153156
self._mainObject = objectify.fromstring(xmlResponse)
154157
else:
155158
#if type(self.getresponseclass()) == type(self._response):
156159
if type(self.getresponseclass()) != type(self._mainObject):
157160
if self._response.messages.resultCode == "Error":
158-
print "Response error"
161+
logging.debug("Response error")
159162
domResponse = xml.dom.minidom.parseString(self._httpResponse)
160163
logging.debug('Received response: %s' % domResponse.toprettyxml())
161164
else:
162165
#Need to handle ErrorResponse
163166
logging.debug('Error retrieving response for request: %s' % self._request)
164167
else:
165-
print "Did not receive http response"
168+
logging.debug("Did not receive http response")
166169
return
167170

168171
def getresponse(self):

authorizenet/constants.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class constants(object):
1515
SANDBOX = 'https://apitest.authorize.net/xml/v1/request.api'
1616
PRODUCTION = 'https://api2.authorize.net/xml/v1/request.api'
1717

18+
'''clientId'''
19+
version = '1.0.12'
20+
clientId = 'sdk-python-' + version
21+
1822
'''xml encoding'''
1923
xml_encoding = 'utf-8'
2024

@@ -38,10 +42,10 @@ class constants(object):
3842
note = ' note="Status with a capital \'S\' is obsolete."'
3943

4044
'''ns namespace 1'''
41-
nsNamespace1 = 'ns1:'
45+
nsNamespace1 = b'ns1:'
4246

4347
'''ns namespace 2'''
44-
nsNamespace2 = ':ns1'
48+
nsNamespace2 = b':ns1'
4549

4650
'''default log file name'''
4751
defaultLogFileName = "anetsdk.log"

authorizenet/utility.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
@author: krgupta
55
'''
66

7-
from ConfigParser import SafeConfigParser
8-
from ConfigParser import NoSectionError
7+
try:
8+
from ConfigParser import SafeConfigParser
9+
from ConfigParser import NoSectionError
10+
except ImportError:
11+
from configparser import SafeConfigParser
12+
from configparser import NoSectionError
13+
914
import os
1015
import sys
16+
import logging
1117
#from __future__ import print_function
1218

19+
logger = logging.getLogger(__name__)
20+
1321
class helper():
1422
__parser = "null"
1523
__propertyfilename = "null"
@@ -45,20 +53,20 @@ def getproperty(propertyname):
4553
try:
4654
helper.__parser = SafeConfigParser({"http":"","https":"","ftp":""})
4755
except:
48-
print ("Parser could not be initialized")
56+
logger.debug("Parser could not be initialized")
4957

5058
if ('null' != helper.getparser()):
5159
try:
5260
helper.getparser().read(helper.__propertyfilename)
5361
helper.__initialized = True
5462
except:
55-
print ("Unable to load the property file")
63+
logger.debug("Unable to load the property file")
5664

5765
if (True == helper.__classinitialized()):
5866
try:
5967
stringvalue = helper.getparser().get("properties", propertyname)
6068
except:
61-
sys.stderr.write("'%s' not found\n" %propertyname )
69+
logger.debug("'%s' not found\n" %propertyname )
6270

6371
if ( "null" == stringvalue):
6472
stringvalue = os.getenv(propertyname)

script/addany.pl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#Modifying XSD to add wildcard character
66
#Adding paymentScheduleTypeInterval type to overcome pyxb's anonymous complex type issue
77

8-
$input_file = "AnetApiSchema.xsd";
9-
$intermediate_file = "IntermediateAnetOut.xsd";
10-
$output_file = "AnetApiSchemaOut.xsd";
8+
$input_file = $ARGV[0];
9+
$intermediate_file = $ARGV[1];
10+
$output_file = $ARGV[2];
1111
$inp_cmd = "dos2unix $input_file\n";
1212

1313
open(INP,"<$input_file") or die "Cannot open $input_file for reading:$!\n";
@@ -25,7 +25,7 @@
2525
}
2626
close(OUP);
2727
close(INP);
28-
print "$intermediate_file created from AnetApiSchema.xsd\n";
28+
#print "$intermediate_file created from AnetApiSchema.xsd\n"; #uncomment for debugging
2929

3030
# Using intermediate file as input
3131
open(INPUT,"<$intermediate_file") or die "Cannot open $intermediate_file for reading:$!\n";

script/generateobjectsfromxsd.sh

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
# Requires pyxb module to be installed and available in path
55

66
dt=`date '+%m/%d/%Y %H:%M:%S'`
7+
8+
AnetURL=https://apitest.authorize.net/xml/v1/schema/AnetApiSchema.xsd
9+
AnetURLPERL='https:\/\/apitest.authorize.net\/xml\/v1\/schema\/AnetApiSchema.xsd'
10+
LOCALXSDWITHANY=./script/AnetOut.xsd
11+
CONTRACTSDIR=authorizenet
12+
CONTRACTSFILE=apicontractsv1
13+
PYXBGENPATH=`which pyxbgen`
14+
TEMPFILE=binding
15+
TEMPDIRECTORY=./script/temp
16+
717
echo Starting pyxbgen on ${dt}
818
which python > /dev/null
919
if [ $? -eq 0 ]
@@ -32,32 +42,60 @@ else
3242
exit 1
3343
fi
3444

35-
LOCALXSDWITHANY=./script/AnetApiSchemaOut.xsd
36-
CONTRACTSDIR=authorizenet
37-
CONTRACTSFILE=apicontractsv1
38-
PYXBGENPATH=`which pyxbgen`
39-
TEMPFILE=binding
40-
41-
echo Downloading AnetAPISchema file under Script directory
42-
wget -O AnetApiSchema.xsd https://apitest.authorize.net/xml/v1/schema/AnetApiSchema.xsd
45+
which wget > /dev/null
4346
if [ $? -eq 0 ]
4447
then
45-
echo AnetAPISchema.xsd downloaded
48+
echo Found wget. Downloading AnetAPISchema file under Script directory.
49+
wget -O ./script/AnetApiSchema.xsd ${AnetURL}
50+
if [ $? -eq 0 ]
51+
then
52+
echo AnetAPISchema.xsd downloaded.
53+
else
54+
echo Unable to download AnetAPISchema.
55+
exit 1
56+
fi
4657
else
47-
echo Unable to download AnetAPISchema.
48-
exit 1
58+
echo Wget not found. Looking for Curl
59+
which curl > /dev/null
60+
if [ $? -eq 0 ]
61+
then
62+
echo Found curl. Downloading AnetAPISchema file under Script directory.
63+
curl --noproxy '*' ${AnetURL} > ./script/AnetApiSchema.xsd
64+
if [ $? -eq 0 ]
65+
then
66+
echo AnetAPISchema.xsd downloaded.
67+
else
68+
curl ${AnetURL} > ./script/AnetApiSchema.xsd
69+
if [ $? -eq 0 ]
70+
then
71+
echo AnetAPISchema.xsd downloaded.
72+
else
73+
echo Unable to download AnetAPISchema.
74+
exit 1
75+
fi
76+
fi
77+
else
78+
echo Unable to find wget and curl. Make sure either one is installed
79+
exit 1
80+
fi
4981
fi
5082

51-
echo modifying XSD using perl to support backward compatibility
52-
perl addany.pl
83+
echo Modifying XSD using perl to support backward compatibility
84+
echo Creating temporary directory
85+
mkdir -p "$TEMPDIRECTORY"
86+
87+
perl script/addany.pl script/AnetApiSchema.xsd ${TEMPDIRECTORY}/IntermediateAnetOut.xsd ${LOCALXSDWITHANY}
5388
if [ $? -eq 0 ]
5489
then
55-
echo AnetOut.xsd generated
90+
: #echo AnetOut.xsd generated #Uncomment for debugging
5691
else
5792
echo Unable to generate AnetOut.xsd
5893
exit 1
5994
fi
6095

96+
echo Deleting temporary directory
97+
rm -rf "$TEMPDIRECTORY"
98+
6199
echo Using pyxb from "${PYXBGENPATH}"
62100
if [ -e "${TEMPFILE}.py" ]; then
63101
rm ${TEMPFILE}.py
@@ -75,12 +113,13 @@ then
75113
rm "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
76114
fi
77115
mv "${TEMPFILE}.py" "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
78-
echo Bindings have been successfully generated from XSD in the file "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
116+
echo Bindings have been successfully generated from XSD in the file "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
79117
echo Old contracts have been moved to .old
80118
else
81119
echo Error generating bindings from XSD. Review the errors and rerun the script.
82120
exit 1
83121
fi
84122

85-
exit 0
123+
perl -i -pe "s/.Location\(\'.*xsd\'/.Location\(\'$AnetURLPERL\'/g" ${CONTRACTSDIR}/${CONTRACTSFILE}.py
86124

125+
exit 0

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Versions should comply with PEP440. For a discussion on single-sourcing
1818
# the version across setup.py and the project code, see
1919
# https://packaging.python.org/en/latest/single_source_version.html
20-
version='1.0.11',
20+
version='1.0.12',
2121

2222
description='Authorize.Net Python SDK',
2323

@@ -48,7 +48,7 @@
4848

4949
# Specify the Python versions you support here. In particular, ensure
5050
# that you indicate whether you support Python 2, Python 3 or both.
51-
'Programming Language :: Python :: 2.7'
51+
'Programming Language :: Python :: 3.5'
5252
],
5353

5454
# What does your project relate to?

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy