Skip to content

Could you merge the python sdk please? #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# sdk-python
Python SDK for the Authorize.Net API

Python - demo version commit
06/25/2015
Empty file added src/contract/__init__.py
Empty file.
25,093 changes: 25,093 additions & 0 deletions src/contract/binding.py

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions src/controller/ARBCancelSubscriptionController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'''
Created on Jun 9, 2015

@author: egodolja
'''
from controller import ARBOperationBase
from contract import binding

class ARBCancelSubscriptionController(ARBOperationBase.ARBOperationBase):

def ARBCancelSubscriptionController(self, requestObject):
if not requestObject.subscriptionId:
return 'SubscriptionId Cannot be Null'

request = super(ARBCancelSubscriptionController, self).buildRequest('ARBCancelSubscriptionRequest', requestObject)

return request

def getResponseClass(self):
return binding.ARBCancelSubscriptionResponse()
21 changes: 21 additions & 0 deletions src/controller/ARBCreateSubscriptionController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'''
Created on Jun 9, 2015

@author: egodolja
'''
from controller import ARBOperationBase
from contract import binding

class ARBCreateSubscriptionController(ARBOperationBase.ARBOperationBase):

def ARBCreateSubscriptionController(self, requestObject):
if not requestObject.subscription:
return 'Subscription Cannot be Null'

request = super(ARBCreateSubscriptionController, self).buildRequest('ARBCreateSubscriptionRequest', requestObject)

return request

def getResponseClass(self):
return binding.ARBCreateSubscriptionResponse()

23 changes: 23 additions & 0 deletions src/controller/ARBGetSubscriptionListController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'''
Created on Jun 22, 2015

@author: egodolja
'''

from controller import ARBOperationBase
from contract import binding

class ARBGetSubscriptionListController(ARBOperationBase.ARBOperationBase):

def ARBGetSubscriptionListController(self, requestObject):
if not requestObject.searchType :
return "searchType Cannot be Null"
if not requestObject.paging :
return "paging Cannot be Null"

request = super(ARBGetSubscriptionListController, self).buildRequest('ARBGetSubscriptionListRequest', requestObject)

return request

def getResponseClass(self):
return binding.ARBGetSubscriptionListResponse()
20 changes: 20 additions & 0 deletions src/controller/ARBGetSubscriptionStatusController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'''
Created on Jun 9, 2015

@author: egodolja
'''
from controller import ARBOperationBase
from contract import binding

class ARBGetSubscriptionStatusController(ARBOperationBase.ARBOperationBase):

def ARBGetSubscriptionStatusController(self, requestObject):
if not requestObject.subscriptionId:
return 'SubscriptionId cannot be null'

request = super(ARBGetSubscriptionStatusController, self).buildRequest('ARBGetSubscriptionStatusRequest', requestObject)

return request

def getResponseClass(self):
return binding.ARBGetSubscriptionStatusResponse()
58 changes: 58 additions & 0 deletions src/controller/ARBOperationBase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'''
Created on Jun 1, 2015

@author: egodolja
'''
from contract import binding

from pip._vendor import requests
from constants import *

import logging
import xml.dom.minidom


class ARBOperationBase(object):
logging.basicConfig(filename='logFile.log', level=logging.DEBUG, format='%(asctime)s %(message)s')


def buildRequest(self, requestType, requestObject):
logging.debug('building request..')
request = requestObject.toxml(encoding=constants.xml_encoding, element_name=requestType)

#remove namespaces that toxml() generates
request = request.replace(constants.nsNamespace1, '')
request = request.replace(constants.nsNamespace2, '')

xml_str = xml.dom.minidom.parseString(request)
logging.debug('request is: %s' % xml_str.toprettyxml())
return request


def execute(self, request, responseClass):
logging.debug('fetching response...')
global response
response = requests.post(constants.SANDBOX_TESTMODE, data=request, headers=constants.headers, proxies=constants.proxyDictionary)

#encoding of response should be changed to retrieve text of response
response.encoding = constants.response_encoding
if response:

response = response.text[3:]
if constants.StatusStart in response:
response = response.replace(constants.note, '')
response = self.afterExecuteStatus(response)

order = binding.CreateFromDocument(response)

if type(order) == type(responseClass):
xml_str = xml.dom.minidom.parseString(response)
logging.debug('Received the following response: %s' % xml_str.toprettyxml())
else:
logging.debug('There was an error: %s' % request)

def afterExecuteStatus(self, response):
start = response.index(constants.StatusStart)
end = response.index(constants.StatusEnd)
response = response.replace(response[start:end+9], '')
return response
1 change: 1 addition & 0 deletions src/controller/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from controller import ARBCancelSubscriptionController
38 changes: 38 additions & 0 deletions src/controller/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'''
Created on Jun 8, 2015

@author: egodolja
'''
class constants(object):
CONST_API_LOGIN_ID = '7uSHkqw7k88'
CONST_TRANSACTION_KEY = '4k2vP25FC59zA8WG'
CONST_REFID = 'Sample'

'''Environments'''
SANDBOX_TESTMODE = 'https://apitest.authorize.net/xml/v1/request.api'
PRODUCTION = 'https://api.authorize.net/xml/v1/request.api'

'''xml headers'''
headers = {'Content-Type' : 'application/xml', 'version' : '1.0', 'encoding' : 'utf-8'}

'''proxy configuration'''
proxyDictionary = {'http' : 'internet.visa.com', 'https' : 'internet.visa.com', 'ftp' : 'internet.visa.com'}

'''ARBGetSubscriptionStatus <Status> tag'''
StatusStart = '<Status>'
StatusEnd = '</Status>'

'''xml encoding'''
xml_encoding = 'utf-8'

'''response encoding'''
response_encoding = 'ISO-8859-1'

'''note section of subscription status response'''
note = ' note="Status with a capital \'S\' is obsolete."'

'''ns namespace 1'''
nsNamespace1 = 'ns1:'

'''ns namespace 2'''
nsNamespace2 = ':ns1'
Empty file added src/script/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions src/script/generateObjectsFromXSD.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off
rem first script
echo current folder..
dir
echo going into pyxb folder..
cd PyxB-1.2.4
echo running pyxbgen on %DATE%-%TIME%
echo what is %TEMP%
set xsd=https://apitest.authorize.net/xml/v1/schema/AnetApiSchema.xsd
rem !!Must have python already installed!!
python pyxbgen -u %xsd% -m bind
echo file is generated
Pause
22 changes: 22 additions & 0 deletions src/tests/ARBCancelSubscriptionTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'''
Created on Jun 15, 2015

@author: egodolja
'''
from contract import binding
from controller.constants import *
from controller.ARBCancelSubscriptionController import ARBCancelSubscriptionController


class ARBCancelSubscriptionTest(object):
merchantAuthentication = binding.merchantAuthenticationType()
merchantAuthentication.name = constants.CONST_API_LOGIN_ID
merchantAuthentication.transactionKey = constants.CONST_TRANSACTION_KEY
cancelSubscriptionRequest = binding.ARBCancelSubscriptionRequest()
cancelSubscriptionRequest.merchantAuthentication = merchantAuthentication
cancelSubscriptionRequest.refId = 'Sample'
cancelSubscriptionRequest.subscriptionId = '2582968'

ARBCancelSubscriptionController = ARBCancelSubscriptionController()
request = ARBCancelSubscriptionController.ARBCancelSubscriptionController(cancelSubscriptionRequest)
ARBCancelSubscriptionController.execute(request, ARBCancelSubscriptionController.getResponseClass())
39 changes: 39 additions & 0 deletions src/tests/ARBCreateSubscriptionTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'''
Created on Jun 16, 2015

@author: egodolja
'''
from contract import binding
from controller.constants import *
from controller.ARBCreateSubscriptionController import ARBCreateSubscriptionController
from contract.binding import CTD_ANON
import datetime

class ARBCreateSubscriptionTest(object):
merchantAuthentication = binding.merchantAuthenticationType()
merchantAuthentication.name = constants.CONST_API_LOGIN_ID
merchantAuthentication.transactionKey = constants.CONST_TRANSACTION_KEY

dateOne = datetime.date(2020, 8, 30)
interval = CTD_ANON()
interval.length = 1
interval.unit = 'months'
paymentSchedule = binding.paymentScheduleType()
paymentSchedule.interval = interval
paymentSchedule.startDate = dateOne
paymentSchedule.totalOccurrences = 12
paymentSchedule.trialOccurrences = 1

subscription = binding.ARBSubscriptionType()
subscription.paymentSchedule = paymentSchedule

createSubscriptionRequest = binding.ARBCreateSubscriptionRequest()
createSubscriptionRequest.merchantAuthentication = merchantAuthentication
createSubscriptionRequest.refId = constants.CONST_REFID
createSubscriptionRequest.subscription = subscription

ARBCreateSubscriptionController = ARBCreateSubscriptionController()
request = ARBCreateSubscriptionController.ARBCreateSubscriptionController(createSubscriptionRequest)
ARBCreateSubscriptionController.execute(request, ARBCreateSubscriptionController.getResponseClass())


24 changes: 24 additions & 0 deletions src/tests/ARBGetSubscriptionStatusTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'''
Created on Jun 15, 2015

@author: egodolja
'''
from contract import binding
from controller.constants import *
from controller.ARBGetSubscriptionStatusController import ARBGetSubscriptionStatusController

class ARBGetSubscriptionStatusTest(object):
merchantAuthentication = binding.merchantAuthenticationType()
merchantAuthentication.name = constants.CONST_API_LOGIN_ID
merchantAuthentication.transactionKey = constants.CONST_TRANSACTION_KEY

getSubscriptionStatusRequest = binding.ARBGetSubscriptionStatusRequest()
getSubscriptionStatusRequest.merchantAuthentication = merchantAuthentication
getSubscriptionStatusRequest.refId = 'Sample'
getSubscriptionStatusRequest.subscriptionId = '2580111'


ARBGetSubscriptionStatusController = ARBGetSubscriptionStatusController()
request = ARBGetSubscriptionStatusController.ARBGetSubscriptionStatusController(getSubscriptionStatusRequest)
ARBGetSubscriptionStatusController.execute(request, binding.ARBGetSubscriptionStatusResponse())

Empty file added src/tests/__init__.py
Empty file.
Loading