|
| 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_transaction_details(transId): |
| 10 | + merchantAuth = apicontractsv1.merchantAuthenticationType() |
| 11 | + merchantAuth.name = constants.apiLoginId |
| 12 | + merchantAuth.transactionKey = constants.transactionKey |
| 13 | + |
| 14 | + transactionDetailsRequest = apicontractsv1.getTransactionDetailsRequest() |
| 15 | + transactionDetailsRequest.merchantAuthentication = merchantAuth |
| 16 | + transactionDetailsRequest.transId = "40000276420" |
| 17 | + |
| 18 | + transactionDetailsController = getTransactionDetailsController(transactionDetailsRequest) |
| 19 | + |
| 20 | + transactionDetailsController.execute() |
| 21 | + |
| 22 | + transactionDetailsResponse = transactionDetailsController.getresponse() |
| 23 | + |
| 24 | + if transactionDetailsResponse is not None: |
| 25 | + if transactionDetailsResponse.messages.resultCode == apicontractsv1.messageTypeEnum.Ok: |
| 26 | + print('Successfully got transaction details!') |
| 27 | + |
| 28 | + print('Transaction Id : %s' % transactionDetailsResponse.transaction.transId) |
| 29 | + print('Transaction Type : %s' % transactionDetailsResponse.transaction.transactionType) |
| 30 | + print('Transaction Status : %s' % transactionDetailsResponse.transaction.transactionStatus) |
| 31 | + print('Auth Amount : %s' % transactionDetailsResponse.transaction.authAmount) |
| 32 | + print('Settle Amount : %s' % transactionDetailsResponse.transaction.settleAmount) |
| 33 | + if hasattr(transactionDetailsResponse.transaction, 'tax') == True: |
| 34 | + print('Tax : %s' % transactionDetailsResponse.transaction.tax.amount) |
| 35 | + if hasattr(transactionDetailsResponse.transaction, 'profile'): |
| 36 | + print('Customer Profile Id : %s' % transactionDetailsResponse.transaction.profile.customerProfileId) |
| 37 | + |
| 38 | + if transactionDetailsResponse.messages is not None: |
| 39 | + print('Message Code : %s' % transactionDetailsResponse.messages.message[0]['code'].text) |
| 40 | + print('Message Text : %s' % transactionDetailsResponse.messages.message[0]['text'].text) |
| 41 | + else: |
| 42 | + if transactionDetailsResponse.messages is not None: |
| 43 | + print('Failed to get transaction details.\nCode:%s \nText:%s' % (transactionDetailsResponse.messages.message[0]['code'].text,transactionDetailsResponse.messages.message[0]['text'].text)) |
| 44 | + |
| 45 | + return transactionDetailsResponse |
| 46 | + |
| 47 | +if(os.path.basename(__file__) == os.path.basename(sys.argv[0])): |
| 48 | + get_transaction_details(constants.transactionId) |
0 commit comments