Skip to content
Merged
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
70 changes: 70 additions & 0 deletions MobileInAppTransactions/create-google-pay-transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os, sys
import imp

from authorizenet import apicontractsv1
from authorizenet.apicontrollers import *
constants = imp.load_source('modulename', 'constants.py')
from decimal import *

def create_google_pay_transaction():

merchantAuth = apicontractsv1.merchantAuthenticationType()
merchantAuth.name = constants.apiLoginId
merchantAuth.transactionKey = constants.transactionKey

opaqueData = apicontractsv1.opaqueDataType()
opaqueData.dataDescriptor = "COMMON.GOOGLE.INAPP.PAYMENT"
opaqueData.dataValue = "1234567890ABCDEF1111AAAA2222BBBB3333CCCC4444DDDD5555EEEE6666FFFF7777888899990000"

paymentType = apicontractsv1.paymentType()
paymentType.opaqueData = opaqueData

tax = apicontractsv1.extendedAmountType()
tax.amount = Decimal('15.00')
tax.name = "level2 tax name"
tax.description = "level2 tax"

transactionrequest = apicontractsv1.transactionRequestType()
transactionrequest.transactionType = apicontractsv1.transactionTypeEnum.authCaptureTransaction
transactionrequest.amount = Decimal('151')
transactionrequest.payment = paymentType
transactionrequest.tax = tax

request = apicontractsv1.createTransactionRequest()
request.merchantAuthentication = merchantAuth
request.refId = "Sample"
request.transactionRequest = transactionrequest

controller = createTransactionController(request)
controller.execute()

response = controller.getresponse()

if response is not None:
if response.messages.resultCode == "Ok":
if hasattr(response.transactionResponse, 'messages') == True:
print('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId)
print('Transaction Response Code: %s' % response.transactionResponse.responseCode)
print('Message Code: %s' % response.transactionResponse.messages.message[0].code)
print('Description: %s' % response.transactionResponse.messages.message[0].description)
print('AUTH Code : %s' % response.authCode)
else:
print('Failed Transaction.')
if hasattr(response.transactionResponse, 'errors') == True:
print('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode))
print('Error message: %s' % response.transactionResponse.errors.error[0].errorText)
else:
print('Failed Transaction.')
if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True:
print('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode))
print('Error message: %s' % response.transactionResponse.errors.error[0].errorText)
else:
print('Error Code: %s' % response.messages.message[0]['code'].text)
print('Error message: %s' % response.messages.message[0]['text'].text)
else:
print('Null Response.')

return response

if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
create_google_pay_transaction()