Skip to content

Commit 10465d5

Browse files
Merge pull request #1 from AuthorizeNet/master
getting latest sample code for python
2 parents 066e010 + 8080a06 commit 10465d5

File tree

57 files changed

+3403
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3403
-123
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: python
2+
sudo: false
3+
4+
python:
5+
- "2.7"
6+
- "3.4"
7+
- "3.5"
8+
# - "pypy" Disabling pypy until travis moves to newer version, known issue with lxml crashing pypy
9+
10+
install:
11+
- pip install authorizenet
12+
13+
script:
14+
python test-runner.py
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os, sys
2+
import imp
3+
4+
from authorizenet import apicontractsv1
5+
from authorizenet.apicontrollers import *
6+
constants = imp.load_source('modulename', 'constants.py')
7+
8+
def create_customer_payment_profile(customerProfileId):
9+
merchantAuth = apicontractsv1.merchantAuthenticationType()
10+
merchantAuth.name = constants.apiLoginId
11+
merchantAuth.transactionKey = constants.transactionKey
12+
13+
creditCard = apicontractsv1.creditCardType()
14+
creditCard.cardNumber = "4111111111111111"
15+
creditCard.expirationDate = "2020-12"
16+
17+
payment = apicontractsv1.paymentType()
18+
payment.creditCard = creditCard
19+
20+
billTo = apicontractsv1.customerAddressType()
21+
billTo.firstName = "John"
22+
billTo.lastName = "Snow"
23+
24+
profile = apicontractsv1.customerPaymentProfileType()
25+
profile.payment = payment
26+
profile.billTo = billTo
27+
28+
createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest()
29+
createCustomerPaymentProfile.merchantAuthentication = merchantAuth
30+
createCustomerPaymentProfile.paymentProfile = profile
31+
print("customerProfileId in create_customer_payment_profile. customerProfileId = %s" %customerProfileId)
32+
createCustomerPaymentProfile.customerProfileId = str(customerProfileId)
33+
34+
controller = createCustomerPaymentProfileController(createCustomerPaymentProfile)
35+
controller.execute()
36+
37+
response = controller.getresponse()
38+
39+
if (response.messages.resultCode=="Ok"):
40+
print("Successfully created a customer payment profile with id: %s" % response.customerPaymentProfileId)
41+
else:
42+
print("Failed to create customer payment profile %s" % response.messages.message[0]['text'].text)
43+
44+
return response
45+
46+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
47+
create_customer_payment_profile(constants.customerProfileId)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import os, sys
2+
import imp
3+
4+
from authorizenet import apicontractsv1
5+
from authorizenet.apicontrollers import *
6+
constants = imp.load_source('modulename', 'constants.py')
7+
8+
def create_customer_profile_from_transaction(transactionId):
9+
merchantAuth = apicontractsv1.merchantAuthenticationType()
10+
merchantAuth.name = constants.apiLoginId
11+
merchantAuth.transactionKey = constants.transactionKey
12+
13+
profile = apicontractsv1.customerProfileBaseType()
14+
profile.merchantCustomerId = "12332"
15+
profile.description = "This is a sample profile"
16+
profile.email = "john@castleblack.com"
17+
18+
createCustomerProfileFromTransaction = apicontractsv1.createCustomerProfileFromTransactionRequest()
19+
createCustomerProfileFromTransaction.merchantAuthentication = merchantAuth
20+
createCustomerProfileFromTransaction.transId = transactionId
21+
#You can either specify the customer information in form of customerProfileBaseType object
22+
createCustomerProfileFromTransaction.customer = profile
23+
# OR
24+
# You can just provide the customer Profile ID
25+
# createCustomerProfileFromTransaction.customerProfileId = "123343"
26+
27+
controller = createCustomerProfileFromTransactionController(createCustomerProfileFromTransaction)
28+
controller.execute()
29+
30+
response = controller.getresponse()
31+
32+
if (response.messages.resultCode=="Ok"):
33+
print("Successfully created a customer profile with id: %s from transaction id: %s" % (response.customerProfileId, createCustomerProfileFromTransaction.transId))
34+
else:
35+
print("Failed to create customer payment profile from transaction %s" % response.messages.message[0]['text'].text)
36+
37+
return response
38+
39+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
40+
create_customer_profile_from_transaction(constants.transactionId)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os, sys
2+
import imp
3+
4+
from authorizenet import apicontractsv1
5+
from authorizenet.apicontrollers import *
6+
constants = imp.load_source('modulename', 'constants.py')
7+
import random
8+
9+
def create_customer_profile():
10+
11+
merchantAuth = apicontractsv1.merchantAuthenticationType()
12+
merchantAuth.name = constants.apiLoginId
13+
merchantAuth.transactionKey = constants.transactionKey
14+
15+
16+
createCustomerProfile = apicontractsv1.createCustomerProfileRequest()
17+
createCustomerProfile.merchantAuthentication = merchantAuth
18+
createCustomerProfile.profile = apicontractsv1.customerProfileType('jdoe' + str(random.randint(0, 10000)), 'John2 Doe', 'jdoe@mail.com')
19+
20+
controller = createCustomerProfileController(createCustomerProfile)
21+
controller.execute()
22+
23+
response = controller.getresponse()
24+
25+
if (response.messages.resultCode=="Ok"):
26+
print("Successfully created a customer profile with id: %s" % response.customerProfileId)
27+
else:
28+
print("Failed to create customer payment profile %s" % response.messages.message[0]['text'].text)
29+
30+
return response
31+
32+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
33+
create_customer_profile()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os, sys
2+
import imp
3+
4+
# Gives error if an address is already present for the given customer Id
5+
from authorizenet import apicontractsv1
6+
from authorizenet.apicontrollers import *
7+
constants = imp.load_source('modulename', 'constants.py')
8+
9+
def create_customer_shipping_address(customerProfileId):
10+
# Give merchant details
11+
merchantAuth = apicontractsv1.merchantAuthenticationType()
12+
merchantAuth.name = constants.apiLoginId
13+
merchantAuth.transactionKey = constants.transactionKey
14+
15+
# Give address details
16+
officeAddress = apicontractsv1.customerAddressType();
17+
officeAddress.firstName = "John"
18+
officeAddress.lastName = "Doe"
19+
officeAddress.address = "123 Main St."
20+
officeAddress.city = "Bellevue"
21+
officeAddress.state = "WA"
22+
officeAddress.zip = "98004"
23+
officeAddress.country = "USA"
24+
officeAddress.phoneNumber = "000-000-0000"
25+
26+
# Create shipping address request
27+
shippingAddressRequest = apicontractsv1.createCustomerShippingAddressRequest();
28+
shippingAddressRequest.address = officeAddress
29+
shippingAddressRequest.customerProfileId = customerProfileId
30+
shippingAddressRequest.merchantAuthentication = merchantAuth
31+
32+
# Make an API call
33+
controller = createCustomerShippingAddressController(shippingAddressRequest)
34+
controller.execute()
35+
response = controller.getresponse();
36+
37+
if response.messages.resultCode == "Ok":
38+
print("SUCCESS")
39+
print("Transaction ID : %s " % response.messages.message[0]['text'].text)
40+
print("Customer address id : %s" % response.customerAddressId)
41+
else:
42+
print("ERROR")
43+
print("Message code : %s " % response.messages.message[0]['code'].text)
44+
print("Message text : %s " % response.messages.message[0]['text'].text)
45+
46+
return response
47+
48+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
49+
create_customer_shipping_address(constants.customerProfileId)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os, sys
2+
import imp
3+
4+
from authorizenet import apicontractsv1
5+
from authorizenet.apicontrollers import *
6+
constants = imp.load_source('modulename', 'constants.py')
7+
8+
def delete_customer_payment_profile(customerProfileId, customerPaymentProfileId):
9+
merchantAuth = apicontractsv1.merchantAuthenticationType()
10+
merchantAuth.name = constants.apiLoginId
11+
merchantAuth.transactionKey = constants.transactionKey
12+
13+
deleteCustomerPaymentProfile = apicontractsv1.deleteCustomerPaymentProfileRequest()
14+
deleteCustomerPaymentProfile.merchantAuthentication = merchantAuth
15+
deleteCustomerPaymentProfile.customerProfileId = customerProfileId
16+
deleteCustomerPaymentProfile.customerPaymentProfileId = customerPaymentProfileId
17+
18+
controller = deleteCustomerPaymentProfileController(deleteCustomerPaymentProfile)
19+
controller.execute()
20+
21+
response = controller.getresponse()
22+
23+
if (response.messages.resultCode=="Ok"):
24+
print("Successfully deleted customer payment profile with customer profile id %s" % deleteCustomerPaymentProfile.customerProfileId)
25+
else:
26+
print(response.messages.message[0]['text'].text)
27+
print("Failed to delete customer paymnet profile with customer profile id %s" % deleteCustomerPaymentProfile.customerProfileId)
28+
29+
return response
30+
31+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
32+
delete_customer_payment_profile(constants.customerProfileId, constants.customerPaymentProfileId)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os, sys
2+
import imp
3+
4+
from authorizenet import apicontractsv1
5+
from authorizenet.apicontrollers import *
6+
constants = imp.load_source('modulename', 'constants.py')
7+
8+
def delete_customer_profile(customerProfileId):
9+
merchantAuth = apicontractsv1.merchantAuthenticationType()
10+
merchantAuth.name = constants.apiLoginId
11+
merchantAuth.transactionKey = constants.transactionKey
12+
13+
deleteCustomerProfile = apicontractsv1.deleteCustomerProfileRequest()
14+
deleteCustomerProfile.merchantAuthentication = merchantAuth
15+
deleteCustomerProfile.customerProfileId = customerProfileId
16+
17+
controller = deleteCustomerProfileController(deleteCustomerProfile)
18+
controller.execute()
19+
20+
response = controller.getresponse()
21+
22+
if (response.messages.resultCode=="Ok"):
23+
print("Successfully deleted customer with customer profile id %s" % deleteCustomerProfile.customerProfileId)
24+
else:
25+
print(response.messages.message[0]['text'].text)
26+
print("Failed to delete customer profile with customer profile id %s" % deleteCustomerProfile.customerProfileId)
27+
28+
return response
29+
30+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
31+
delete_customer_profile(constants.customerProfileId)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os, sys
2+
import imp
3+
4+
from authorizenet import apicontractsv1
5+
from authorizenet.apicontrollers import *
6+
constants = imp.load_source('modulename', 'constants.py')
7+
8+
def delete_customer_shipping_address(customerProfileId, customerProfileShippingId):
9+
10+
# Give merchant details
11+
merchantAuth = apicontractsv1.merchantAuthenticationType()
12+
merchantAuth.name = constants.apiLoginId
13+
merchantAuth.transactionKey = constants.transactionKey
14+
15+
# create delete request
16+
deleteShippingAddress = apicontractsv1.deleteCustomerShippingAddressRequest()
17+
deleteShippingAddress.merchantAuthentication = merchantAuth
18+
deleteShippingAddress.customerProfileId = customerProfileId
19+
deleteShippingAddress.customerAddressId = customerProfileShippingId
20+
21+
# Make the API call
22+
deleteShippingAddressController = deleteCustomerShippingAddressController(deleteShippingAddress)
23+
deleteShippingAddressController.execute()
24+
response = deleteShippingAddressController.getresponse()
25+
26+
if response.messages.resultCode == "Ok":
27+
print("SUCCESS")
28+
print("Message code : %s " % response.messages.message[0]['code'].text)
29+
print("Message text : %s " % response.messages.message[0]['text'].text)
30+
else:
31+
print("ERROR")
32+
print("Message code : %s " % response.messages.message[0]['code'].text)
33+
print("Message text : %s " % response.messages.message[0]['text'].text)
34+
35+
return response
36+
37+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
38+
delete_customer_shipping_address(constants.customerProfileId, constants.customerProfileShippingId)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os, sys
2+
import imp
3+
4+
from authorizenet import apicontractsv1
5+
from authorizenet.apicontrollers import *
6+
constants = imp.load_source('modulename', 'constants.py')
7+
from decimal import *
8+
9+
def get_accept_customer_profile_page(customerProfileId):
10+
merchantAuth = apicontractsv1.merchantAuthenticationType()
11+
merchantAuth.name = constants.apiLoginId
12+
merchantAuth.transactionKey = constants.transactionKey
13+
14+
setting = apicontractsv1.settingType()
15+
setting.settingName = apicontractsv1.settingNameEnum.hostedProfileReturnUrl
16+
setting.settingValue = "https://returnurl.com/return/"
17+
18+
settings = apicontractsv1.ArrayOfSetting()
19+
settings.setting.append(setting)
20+
21+
profilePageRequest = apicontractsv1.getHostedProfilePageRequest()
22+
profilePageRequest.merchantAuthentication = merchantAuth
23+
profilePageRequest.customerProfileId = customerProfileId
24+
profilePageRequest.hostedProfileSettings = settings
25+
26+
profilePageController = getHostedProfilePageController(profilePageRequest)
27+
28+
profilePageController.execute()
29+
30+
profilePageResponse = profilePageController.getresponse()
31+
32+
if profilePageResponse is not None:
33+
if profilePageResponse.messages.resultCode == apicontractsv1.messageTypeEnum.Ok:
34+
print('Successfully got hosted profile page!')
35+
36+
print('Token : %s' % profilePageResponse.token)
37+
38+
if profilePageResponse.messages:
39+
print('Message Code : %s' % profilePageResponse.messages.message[0]['code'].text)
40+
print('Message Text : %s' % profilePageResponse.messages.message[0]['text'].text)
41+
else:
42+
if profilePageResponse.messages:
43+
print('Failed to get batch statistics.\nCode:%s \nText:%s' % (profilePageResponse.messages.message[0]['code'].text,profilePageResponse.messages.message[0]['text'].text))
44+
45+
return profilePageResponse
46+
47+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
48+
get_hosted_profile_page(constants.customerProfileId)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os, sys
2+
import imp
3+
4+
from authorizenet import apicontractsv1
5+
from authorizenet.apicontrollers import *
6+
constants = imp.load_source('modulename', 'constants.py')
7+
8+
def get_customer_payment_profile(customerProfileId, customerPaymentProfileId):
9+
10+
merchantAuth = apicontractsv1.merchantAuthenticationType()
11+
merchantAuth.name = constants.apiLoginId
12+
merchantAuth.transactionKey = constants.transactionKey
13+
14+
getCustomerPaymentProfile = apicontractsv1.getCustomerPaymentProfileRequest()
15+
getCustomerPaymentProfile.merchantAuthentication = merchantAuth
16+
getCustomerPaymentProfile.customerProfileId = customerProfileId
17+
getCustomerPaymentProfile.customerPaymentProfileId = customerPaymentProfileId
18+
19+
controller = getCustomerPaymentProfileController(getCustomerPaymentProfile)
20+
controller.execute()
21+
22+
response = controller.getresponse()
23+
24+
if (response.messages.resultCode=="Ok"):
25+
print("Successfully retrieved a payment profile with profile id %s and customer id %s" % (getCustomerPaymentProfile.customerProfileId, getCustomerPaymentProfile.customerProfileId))
26+
if hasattr(response, 'paymentProfile') == True:
27+
if hasattr(response.paymentProfile, 'subscriptionIds') == True:
28+
if hasattr(response.paymentProfile.subscriptionIds, 'subscriptionId') == True:
29+
print("list of subscriptionid:")
30+
for subscriptionid in response.paymentProfile.subscriptionIds.subscriptionId:
31+
print(subscriptionid)
32+
else:
33+
print("response code: %s" % response.messages.resultCode)
34+
print("Failed to get payment profile information with id %s" % getCustomerPaymentProfile.customerPaymentProfileId)
35+
36+
return response
37+
38+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
39+
get_customer_payment_profile(constants.customerProfileId, constants.customerPaymentProfileId)

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