Skip to content

Commit 49b46ad

Browse files
committed
Merge pull request #1 from egodolja/master
Could you merge the python sdk please?
2 parents 8d55649 + cf19f5c commit 49b46ad

17 files changed

+25493
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# sdk-python
22
Python SDK for the Authorize.Net API
3+
4+
Python - demo version commit
5+
06/25/2015

src/contract/__init__.py

Whitespace-only changes.

src/contract/binding.py

Lines changed: 25093 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
Created on Jun 9, 2015
3+
4+
@author: egodolja
5+
'''
6+
from controller import ARBOperationBase
7+
from contract import binding
8+
9+
class ARBCancelSubscriptionController(ARBOperationBase.ARBOperationBase):
10+
11+
def ARBCancelSubscriptionController(self, requestObject):
12+
if not requestObject.subscriptionId:
13+
return 'SubscriptionId Cannot be Null'
14+
15+
request = super(ARBCancelSubscriptionController, self).buildRequest('ARBCancelSubscriptionRequest', requestObject)
16+
17+
return request
18+
19+
def getResponseClass(self):
20+
return binding.ARBCancelSubscriptionResponse()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'''
2+
Created on Jun 9, 2015
3+
4+
@author: egodolja
5+
'''
6+
from controller import ARBOperationBase
7+
from contract import binding
8+
9+
class ARBCreateSubscriptionController(ARBOperationBase.ARBOperationBase):
10+
11+
def ARBCreateSubscriptionController(self, requestObject):
12+
if not requestObject.subscription:
13+
return 'Subscription Cannot be Null'
14+
15+
request = super(ARBCreateSubscriptionController, self).buildRequest('ARBCreateSubscriptionRequest', requestObject)
16+
17+
return request
18+
19+
def getResponseClass(self):
20+
return binding.ARBCreateSubscriptionResponse()
21+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'''
2+
Created on Jun 22, 2015
3+
4+
@author: egodolja
5+
'''
6+
7+
from controller import ARBOperationBase
8+
from contract import binding
9+
10+
class ARBGetSubscriptionListController(ARBOperationBase.ARBOperationBase):
11+
12+
def ARBGetSubscriptionListController(self, requestObject):
13+
if not requestObject.searchType :
14+
return "searchType Cannot be Null"
15+
if not requestObject.paging :
16+
return "paging Cannot be Null"
17+
18+
request = super(ARBGetSubscriptionListController, self).buildRequest('ARBGetSubscriptionListRequest', requestObject)
19+
20+
return request
21+
22+
def getResponseClass(self):
23+
return binding.ARBGetSubscriptionListResponse()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
Created on Jun 9, 2015
3+
4+
@author: egodolja
5+
'''
6+
from controller import ARBOperationBase
7+
from contract import binding
8+
9+
class ARBGetSubscriptionStatusController(ARBOperationBase.ARBOperationBase):
10+
11+
def ARBGetSubscriptionStatusController(self, requestObject):
12+
if not requestObject.subscriptionId:
13+
return 'SubscriptionId cannot be null'
14+
15+
request = super(ARBGetSubscriptionStatusController, self).buildRequest('ARBGetSubscriptionStatusRequest', requestObject)
16+
17+
return request
18+
19+
def getResponseClass(self):
20+
return binding.ARBGetSubscriptionStatusResponse()

src/controller/ARBOperationBase.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'''
2+
Created on Jun 1, 2015
3+
4+
@author: egodolja
5+
'''
6+
from contract import binding
7+
8+
from pip._vendor import requests
9+
from constants import *
10+
11+
import logging
12+
import xml.dom.minidom
13+
14+
15+
class ARBOperationBase(object):
16+
logging.basicConfig(filename='logFile.log', level=logging.DEBUG, format='%(asctime)s %(message)s')
17+
18+
19+
def buildRequest(self, requestType, requestObject):
20+
logging.debug('building request..')
21+
request = requestObject.toxml(encoding=constants.xml_encoding, element_name=requestType)
22+
23+
#remove namespaces that toxml() generates
24+
request = request.replace(constants.nsNamespace1, '')
25+
request = request.replace(constants.nsNamespace2, '')
26+
27+
xml_str = xml.dom.minidom.parseString(request)
28+
logging.debug('request is: %s' % xml_str.toprettyxml())
29+
return request
30+
31+
32+
def execute(self, request, responseClass):
33+
logging.debug('fetching response...')
34+
global response
35+
response = requests.post(constants.SANDBOX_TESTMODE, data=request, headers=constants.headers, proxies=constants.proxyDictionary)
36+
37+
#encoding of response should be changed to retrieve text of response
38+
response.encoding = constants.response_encoding
39+
if response:
40+
41+
response = response.text[3:]
42+
if constants.StatusStart in response:
43+
response = response.replace(constants.note, '')
44+
response = self.afterExecuteStatus(response)
45+
46+
order = binding.CreateFromDocument(response)
47+
48+
if type(order) == type(responseClass):
49+
xml_str = xml.dom.minidom.parseString(response)
50+
logging.debug('Received the following response: %s' % xml_str.toprettyxml())
51+
else:
52+
logging.debug('There was an error: %s' % request)
53+
54+
def afterExecuteStatus(self, response):
55+
start = response.index(constants.StatusStart)
56+
end = response.index(constants.StatusEnd)
57+
response = response.replace(response[start:end+9], '')
58+
return response

src/controller/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from controller import ARBCancelSubscriptionController

src/controller/constants.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'''
2+
Created on Jun 8, 2015
3+
4+
@author: egodolja
5+
'''
6+
class constants(object):
7+
CONST_API_LOGIN_ID = '7uSHkqw7k88'
8+
CONST_TRANSACTION_KEY = '4k2vP25FC59zA8WG'
9+
CONST_REFID = 'Sample'
10+
11+
'''Environments'''
12+
SANDBOX_TESTMODE = 'https://apitest.authorize.net/xml/v1/request.api'
13+
PRODUCTION = 'https://api.authorize.net/xml/v1/request.api'
14+
15+
'''xml headers'''
16+
headers = {'Content-Type' : 'application/xml', 'version' : '1.0', 'encoding' : 'utf-8'}
17+
18+
'''proxy configuration'''
19+
proxyDictionary = {'http' : 'internet.visa.com', 'https' : 'internet.visa.com', 'ftp' : 'internet.visa.com'}
20+
21+
'''ARBGetSubscriptionStatus <Status> tag'''
22+
StatusStart = '<Status>'
23+
StatusEnd = '</Status>'
24+
25+
'''xml encoding'''
26+
xml_encoding = 'utf-8'
27+
28+
'''response encoding'''
29+
response_encoding = 'ISO-8859-1'
30+
31+
'''note section of subscription status response'''
32+
note = ' note="Status with a capital \'S\' is obsolete."'
33+
34+
'''ns namespace 1'''
35+
nsNamespace1 = 'ns1:'
36+
37+
'''ns namespace 2'''
38+
nsNamespace2 = ':ns1'

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