1
|
|
|
''' |
2
|
|
|
Created on Nov 16, 2015 |
3
|
|
|
|
4
|
|
|
@author: krgupta |
5
|
|
|
''' |
6
|
|
|
from authorizenet import apicontractsv1 |
7
|
|
|
from authorizenet.constants import constants |
8
|
|
|
from authorizenet.apicontractsv1 import CTD_ANON |
9
|
|
|
from authorizenet.apicontrollers import * |
10
|
|
|
from decimal import * |
11
|
|
|
import random |
12
|
|
|
import datetime |
13
|
|
|
import unittest |
14
|
|
|
import sys |
15
|
|
|
from tests import apitestbase |
16
|
|
|
from authorizenet import utility |
17
|
|
|
|
18
|
|
|
class test_ReadProperty(apitestbase.ApiTestBase): |
19
|
|
|
def testPropertyFromFile(self): |
20
|
|
|
login= utility.helper.getproperty("api.login.id") |
21
|
|
|
transactionkey = utility.helper.getproperty("transaction.key") |
22
|
|
|
self.assertIsNotNone(login) |
23
|
|
|
self.assertIsNotNone(transactionkey) |
24
|
|
|
|
25
|
|
|
class test_TransactionReportingUnitTest(apitestbase.ApiTestBase): |
26
|
|
|
def testchargeCreditCard(self): |
27
|
|
|
creditCard = apicontractsv1.creditCardType() |
28
|
|
|
creditCard.cardNumber = "4111111111111111" |
29
|
|
|
creditCard.expirationDate = "2020-12" |
30
|
|
|
payment = apicontractsv1.paymentType() |
31
|
|
|
payment.creditCard = creditCard |
32
|
|
|
transactionrequest = apicontractsv1.transactionRequestType() |
33
|
|
|
transactionrequest.transactionType = "authCaptureTransaction" |
34
|
|
|
transactionrequest.amount = Decimal(str(round(random.random()*100, 2))) |
35
|
|
|
transactionrequest.payment = payment |
36
|
|
|
createtransactionrequest = apicontractsv1.createTransactionRequest() |
37
|
|
|
createtransactionrequest.merchantAuthentication = self.merchantAuthentication |
38
|
|
|
createtransactionrequest.refId = "MerchantID-0001" |
39
|
|
|
createtransactionrequest.transactionRequest = transactionrequest |
40
|
|
|
createtransactioncontroller = createTransactionController(createtransactionrequest) |
41
|
|
|
createtransactioncontroller.execute() |
42
|
|
|
response = createtransactioncontroller.getresponse() |
43
|
|
|
if hasattr(response, 'messages') == True: |
44
|
|
|
if hasattr(response.messages, 'resultCode') == True: |
45
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
46
|
|
|
if hasattr(response, 'transactionResponse') == True: |
47
|
|
|
if hasattr(response.transactionResponse, 'transId') == True: |
48
|
|
|
createdTransactionId = response.transactionResponse.transId |
49
|
|
|
return str(createdTransactionId) |
50
|
|
|
|
51
|
|
|
def testgetTransactionDetails(self): |
52
|
|
|
gettransactiondetailsrequest = apicontractsv1.getTransactionDetailsRequest() |
53
|
|
|
gettransactiondetailsrequest.merchantAuthentication = self.merchantAuthentication |
54
|
|
|
transactionID = self.testchargeCreditCard() |
55
|
|
|
gettransactiondetailsrequest.transId = transactionID #update valid transaction id |
56
|
|
|
gettransactiondetailscontroller = getTransactionDetailsController(gettransactiondetailsrequest) |
57
|
|
|
gettransactiondetailscontroller.execute() |
58
|
|
|
response = gettransactiondetailscontroller.getresponse() |
59
|
|
|
if hasattr(response, 'messages') == True: |
60
|
|
|
if hasattr(response.messages, 'resultCode') == True: |
61
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
62
|
|
|
|
63
|
|
|
class test_RecurringBillingTest(apitestbase.ApiTestBase): |
64
|
|
View Code Duplication |
def testCreateSubscription(self): |
|
|
|
|
65
|
|
|
createsubscriptionrequest = apicontractsv1.ARBCreateSubscriptionRequest() |
66
|
|
|
createsubscriptionrequest.merchantAuthentication = self.merchantAuthentication |
67
|
|
|
createsubscriptionrequest.refId = 'Sample' |
68
|
|
|
createsubscriptionrequest.subscription = self.subscriptionOne |
69
|
|
|
arbcreatesubscriptioncontroller = ARBCreateSubscriptionController(createsubscriptionrequest) |
70
|
|
|
arbcreatesubscriptioncontroller.execute() |
71
|
|
|
response = arbcreatesubscriptioncontroller.getresponse() |
72
|
|
|
if hasattr(response, 'messages') == True: |
73
|
|
|
if hasattr(response.messages, 'resultCode') == True: |
74
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
75
|
|
|
if hasattr(response, 'subscriptionId') == True: |
76
|
|
|
createdSubscriptionId = response.subscriptionId |
77
|
|
|
return str(createdSubscriptionId) |
78
|
|
|
|
79
|
|
View Code Duplication |
def testGetSubscription(self): |
|
|
|
|
80
|
|
|
getSubscription = apicontractsv1.ARBGetSubscriptionRequest() |
81
|
|
|
getSubscription.merchantAuthentication = self.merchantAuthentication |
82
|
|
|
subscriptionID = self.testCreateSubscription() |
83
|
|
|
getSubscription.subscriptionId = subscriptionID #update valid subscription id |
84
|
|
|
getSubscriptionController = ARBGetSubscriptionController(getSubscription) |
85
|
|
|
getSubscriptionController.execute() |
86
|
|
|
response = getSubscriptionController.getresponse() |
87
|
|
|
if hasattr(response, 'messages') == True: |
88
|
|
|
if hasattr(response.messages, 'resultCode') == True: |
89
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
90
|
|
|
|
91
|
|
View Code Duplication |
def testCancelSubscription(self): |
|
|
|
|
92
|
|
|
cancelsubscriptionrequest = apicontractsv1.ARBCancelSubscriptionRequest() |
93
|
|
|
cancelsubscriptionrequest.merchantAuthentication = self.merchantAuthentication |
94
|
|
|
cancelsubscriptionrequest.refId = 'Sample' |
95
|
|
|
subscriptionID = self.testCreateSubscription() |
96
|
|
|
cancelsubscriptionrequest.subscriptionId = subscriptionID #input valid subscriptionId |
97
|
|
|
cancelsubscriptioncontroller = ARBCancelSubscriptionController (cancelsubscriptionrequest) |
98
|
|
|
cancelsubscriptioncontroller.execute() |
99
|
|
|
response = cancelsubscriptioncontroller.getresponse() |
100
|
|
|
if hasattr(response, 'messages') == True: |
101
|
|
|
if hasattr(response.messages, 'resultCode') == True: |
102
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
103
|
|
|
|
104
|
|
|
class test_paymentTransactionUnitTest(apitestbase.ApiTestBase): |
105
|
|
View Code Duplication |
def testAuthCaptureTransaction(self): |
|
|
|
|
106
|
|
|
transactionrequesttype = apicontractsv1.transactionRequestType() |
107
|
|
|
transactionrequesttype.transactionType = "authCaptureTransaction" |
108
|
|
|
transactionrequesttype.amount = self.amount |
109
|
|
|
transactionrequesttype.payment = self.payment |
110
|
|
|
transactionrequesttype.order = self.order |
111
|
|
|
transactionrequesttype.customer = self.customerData |
112
|
|
|
transactionrequesttype.billTo = self.billTo |
113
|
|
|
createtransactionrequest = apicontractsv1.createTransactionRequest() |
114
|
|
|
createtransactionrequest.merchantAuthentication = self.merchantAuthentication |
115
|
|
|
createtransactionrequest.refId = self.ref_id |
116
|
|
|
createtransactionrequest.transactionRequest = transactionrequesttype |
117
|
|
|
createtransactioncontroller = createTransactionController(createtransactionrequest) |
118
|
|
|
createtransactioncontroller.execute() |
119
|
|
|
response = createtransactioncontroller.getresponse() |
120
|
|
|
if hasattr(response, 'messages') == True: |
121
|
|
|
if hasattr(response.messages, 'resultCode') == True: |
122
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
123
|
|
|
if hasattr(response, 'transactionResponse') == True: |
124
|
|
|
self.assertIsNotNone(response.transactionResponse) |
125
|
|
|
if hasattr(response.transactionResponse, 'transId') == True: |
126
|
|
|
self.assertIsNotNone(response.transactionResponse.transId) |
127
|
|
|
|
128
|
|
View Code Duplication |
def testAuthOnlyContinueTransaction(self): |
|
|
|
|
129
|
|
|
transactionrequesttype = apicontractsv1.transactionRequestType() |
130
|
|
|
transactionrequesttype.transactionType = "authCaptureTransaction" |
131
|
|
|
transactionrequesttype.amount = self.amount |
132
|
|
|
transactionrequesttype.payment = self.payment |
133
|
|
|
transactionrequesttype.order = self.order |
134
|
|
|
transactionrequesttype.customer = self.customerData |
135
|
|
|
transactionrequesttype.billTo = self.billTo |
136
|
|
|
createtransactionrequest = apicontractsv1.createTransactionRequest() |
137
|
|
|
createtransactionrequest.merchantAuthentication = self.merchantAuthentication |
138
|
|
|
createtransactionrequest.refId = self.ref_id |
139
|
|
|
createtransactionrequest.transactionRequest = transactionrequesttype |
140
|
|
|
createtransactioncontroller = createTransactionController(createtransactionrequest) |
141
|
|
|
createtransactioncontroller.execute() |
142
|
|
|
response = createtransactioncontroller.getresponse() |
143
|
|
|
if hasattr(response, 'messages') == True: |
144
|
|
|
if hasattr(response.messages, 'resultCode') == True: |
145
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
146
|
|
|
if hasattr(response, 'transactionResponse') == True: |
147
|
|
|
self.assertIsNotNone(response.transactionResponse) |
148
|
|
|
if hasattr(response.transactionResponse, 'transId') == True: |
149
|
|
|
self.assertIsNotNone(response.transactionResponse.transId) |
150
|
|
|
|
151
|
|
|
class test_CustomerProfile(apitestbase.ApiTestBase): |
152
|
|
|
def testCreateCustomerProfile(self): |
153
|
|
|
createdCustomerProfileID = None |
154
|
|
|
createCustomerProfile = apicontractsv1.createCustomerProfileRequest() |
155
|
|
|
createCustomerProfile.merchantAuthentication = self.merchantAuthentication |
156
|
|
|
randomInt = random.randint(0, 10000) |
157
|
|
|
createCustomerProfile.profile = apicontractsv1.customerProfileType() |
158
|
|
|
createCustomerProfile.profile.merchantCustomerId = 'jdoe%s' % randomInt |
159
|
|
|
createCustomerProfile.profile.description = 'John Doe%s' % randomInt |
160
|
|
|
createCustomerProfile.profile.email = 'jdoe%[email protected]' % randomInt |
161
|
|
|
controller = createCustomerProfileController(createCustomerProfile) |
162
|
|
|
controller.execute() |
163
|
|
|
response = controller.getresponse() |
164
|
|
|
if hasattr(response, 'messages') == True: |
165
|
|
|
if hasattr(response.messages, 'resultCode') == True: |
166
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
167
|
|
|
if hasattr(response, 'customerProfileId') == True: |
168
|
|
|
createdCustomerProfileID = response.customerProfileId |
169
|
|
|
return str(createdCustomerProfileID) |
170
|
|
|
|
171
|
|
|
def testGetCustomerProfile(self): |
172
|
|
|
getCustomerProfile = apicontractsv1.getCustomerProfileRequest() |
173
|
|
|
getCustomerProfile.merchantAuthentication = self.merchantAuthentication |
174
|
|
|
|
175
|
|
|
CustomerProfileID = self.testCreateCustomerProfile() |
176
|
|
|
getCustomerProfile.customerProfileId = CustomerProfileID |
177
|
|
|
controller = getCustomerProfileController(getCustomerProfile) |
178
|
|
|
controller.execute() |
179
|
|
|
response = controller.getresponse() |
180
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
181
|
|
|
if hasattr(response, 'messages') == True: |
182
|
|
|
if hasattr(response.messages, 'resultCode') == True: |
183
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
184
|
|
|
|
185
|
|
|
def testCreateAndGetCustomerShippingAddress(self): |
186
|
|
|
officeAddress = apicontractsv1.customerAddressType(); |
187
|
|
|
officeAddress.firstName = "John" |
188
|
|
|
officeAddress.lastName = "Doe" |
189
|
|
|
officeAddress.address = "123 Main St." |
190
|
|
|
officeAddress.city = "Bellevue" |
191
|
|
|
officeAddress.state = "WA" |
192
|
|
|
officeAddress.zip = "98004" |
193
|
|
|
officeAddress.country = "USA" |
194
|
|
|
officeAddress.phoneNumber = "000-000-0000" |
195
|
|
|
shippingAddressRequest = apicontractsv1.createCustomerShippingAddressRequest() |
196
|
|
|
shippingAddressRequest.address = officeAddress |
197
|
|
|
CustomerProfileID = self.testCreateCustomerProfile() |
198
|
|
|
shippingAddressRequest.customerProfileId = CustomerProfileID |
199
|
|
|
shippingAddressRequest.merchantAuthentication = self.merchantAuthentication |
200
|
|
|
controller = createCustomerShippingAddressController(shippingAddressRequest) |
201
|
|
|
controller.execute() |
202
|
|
|
response = controller.getresponse() |
203
|
|
|
if hasattr(response, 'messages') == True: |
204
|
|
|
if hasattr(response.messages, 'resultCode') == True: |
205
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
206
|
|
|
if hasattr(response, 'customerAddressId') == True: |
207
|
|
|
createdShippingAddressId = str(response.customerAddressId) |
208
|
|
|
#return str(createdShippingAddressId) |
209
|
|
|
|
210
|
|
|
#def testGetCustomerShippingAddress(self): |
211
|
|
|
getShippingAddress = apicontractsv1.getCustomerShippingAddressRequest() |
212
|
|
|
getShippingAddress.merchantAuthentication = self.merchantAuthentication |
213
|
|
|
|
214
|
|
|
|
215
|
|
|
getShippingAddress.customerProfileId = CustomerProfileID |
216
|
|
|
getShippingAddress.customerAddressId = createdShippingAddressId |
217
|
|
|
|
218
|
|
|
getShippingAddressController = getCustomerShippingAddressController(getShippingAddress) |
219
|
|
|
getShippingAddressController.execute() |
220
|
|
|
response = getShippingAddressController.getresponse() |
221
|
|
|
if hasattr(response, 'messages') == True: |
222
|
|
|
if hasattr(response.messages, 'resultCode') == True: |
223
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
224
|
|
|
|
225
|
|
|
''' |
226
|
|
|
class test_ProductionURL(apitestbase.ApiTestBase): |
227
|
|
|
#Tests will run only with production credentials |
228
|
|
|
|
229
|
|
|
|
230
|
|
|
def testGetSettledBatchList(self): |
231
|
|
|
settledBatchListRequest = apicontractsv1.getSettledBatchListRequest() |
232
|
|
|
settledBatchListRequest.merchantAuthentication = self.merchantAuthentication |
233
|
|
|
settledBatchListController = getSettledBatchListController(settledBatchListRequest) |
234
|
|
|
customEndpoint = constants.PRODUCTION |
235
|
|
|
apicontrollersbase.APIOperationBase.setenvironment(customEndpoint) |
236
|
|
|
settledBatchListController.execute() |
237
|
|
|
response = settledBatchListController.getresponse() |
238
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
239
|
|
|
|
240
|
|
|
def testGetListofSubscriptions(self): |
241
|
|
|
sorting = apicontractsv1.ARBGetSubscriptionListSorting() |
242
|
|
|
sorting.orderBy = apicontractsv1.ARBGetSubscriptionListOrderFieldEnum.id |
243
|
|
|
sorting.orderDescending = "false" |
244
|
|
|
paging = apicontractsv1.Paging() |
245
|
|
|
paging.limit = 1000 |
246
|
|
|
paging.offset = 1 |
247
|
|
|
GetListofSubscriptionRequest = apicontractsv1.ARBGetSubscriptionListRequest() |
248
|
|
|
GetListofSubscriptionRequest.merchantAuthentication = self.merchantAuthentication |
249
|
|
|
GetListofSubscriptionRequest.refId = "Sample" |
250
|
|
|
GetListofSubscriptionRequest.searchType = apicontractsv1.ARBGetSubscriptionListSearchTypeEnum.subscriptionInactive |
251
|
|
|
GetListofSubscriptionRequest.sorting = sorting |
252
|
|
|
GetListofSubscriptionRequest.paging = paging |
253
|
|
|
arbgetsubscriptionlistcontroller = ARBGetSubscriptionListController(GetListofSubscriptionRequest) |
254
|
|
|
customEndpoint = constants.PRODUCTION |
255
|
|
|
apicontrollersbase.APIOperationBase.setenvironment(customEndpoint) |
256
|
|
|
arbgetsubscriptionlistcontroller.execute() |
257
|
|
|
response = arbgetsubscriptionlistcontroller.getresponse() |
258
|
|
|
self.assertEquals('Ok', response.messages.resultCode) |
259
|
|
|
''' |
260
|
|
|
if __name__ =='__main__': |
261
|
|
|
unittest.main() |
262
|
|
|
|