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