Skip to content

Commit 1b7eeb3

Browse files
committed
Added CreateGooglePayTransaction
1 parent 0d0d176 commit 1b7eeb3

File tree

1 file changed

+40
-45
lines changed

1 file changed

+40
-45
lines changed

MobileInAppTransactions/create-google-pay-transaction.py

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,52 @@ def create_google_pay_transaction():
1919
paymentType = apicontractsv1.paymentType()
2020
paymentType.opaqueData = opaqueData
2121

22-
lineItem = apicontractsv1.lineItemType()
23-
lineItem.itemId = "1"
24-
lineItem.name = "vase"
25-
lineItem.description = "Cannes logo"
26-
lineItem.quantity = 18
27-
lineItem.unitPrice = 45.00
22+
tax = apicontractsv1.extendedAmountType()
23+
tax.amount = Decimal('15.00')
24+
tax.name = "level2 tax name"
25+
tax.description = "level2 tax"
2826

29-
lineItemsArray = apicontractsv1.ArrayOfLineItem()
30-
print(lineItemsArray)
31-
# lineItemArray.lineItem
27+
transactionrequest = apicontractsv1.transactionRequestType()
28+
transactionrequest.transactionType = apicontractsv1.transactionTypeEnum.authCaptureTransaction
29+
transactionrequest.amount = Decimal('151')
30+
transactionrequest.payment = paymentType
31+
transactionrequest.tax = tax
3232

33-
# transactionrequest = apicontractsv1.transactionRequestType()
34-
# transactionrequest.transactionType = apicontractsv1.transactionTypeEnum.authCaptureTransaction
35-
# transactionrequest.amount = Decimal('151')
36-
# transactionrequest.payment = paymentType
33+
request = apicontractsv1.createTransactionRequest()
34+
request.merchantAuthentication = merchantAuth
35+
request.refId = "Sample"
36+
request.transactionRequest = transactionrequest
3737

38-
# request = apicontractsv1.createTransactionRequest()
39-
# request.merchantAuthentication = merchantAuth
40-
# request.refId = "Sample"
41-
# request.transactionRequest = transactionrequest
38+
controller = createTransactionController(request)
39+
controller.execute()
4240

43-
# controller = createTransactionController(request)
44-
# controller.execute()
41+
response = controller.getresponse()
4542

46-
# response = controller.getresponse()
43+
if response is not None:
44+
if response.messages.resultCode == "Ok":
45+
if hasattr(response.transactionResponse, 'messages') == True:
46+
print('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId)
47+
print('Transaction Response Code: %s' % response.transactionResponse.responseCode)
48+
print('Message Code: %s' % response.transactionResponse.messages.message[0].code)
49+
print('Description: %s' % response.transactionResponse.messages.message[0].description)
50+
print('AUTH Code : %s' % response.authCode)
51+
else:
52+
print('Failed Transaction.')
53+
if hasattr(response.transactionResponse, 'errors') == True:
54+
print('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode))
55+
print('Error message: %s' % response.transactionResponse.errors.error[0].errorText)
56+
else:
57+
print('Failed Transaction.')
58+
if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True:
59+
print('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode))
60+
print('Error message: %s' % response.transactionResponse.errors.error[0].errorText)
61+
else:
62+
print('Error Code: %s' % response.messages.message[0]['code'].text)
63+
print('Error message: %s' % response.messages.message[0]['text'].text)
64+
else:
65+
print('Null Response.')
4766

48-
# if response is not None:
49-
# if response.messages.resultCode == "Ok":
50-
# if hasattr(response.transactionResponse, 'messages') == True:
51-
# print ('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId)
52-
# print ('Transaction Response Code: %s' % response.transactionResponse.responseCode)
53-
# print ('Message Code: %s' % response.transactionResponse.messages.message[0].code)
54-
# print ('Description: %s' % response.transactionResponse.messages.message[0].description)
55-
# print ('AUTH Code : %s' % response.authCode)
56-
# else:
57-
# print ('Failed Transaction.')
58-
# if hasattr(response.transactionResponse, 'errors') == True:
59-
# print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode))
60-
# print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText)
61-
# else:
62-
# print ('Failed Transaction.')
63-
# if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True:
64-
# print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode))
65-
# print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText)
66-
# else:
67-
# print ('Error Code: %s' % response.messages.message[0]['code'].text)
68-
# print ('Error message: %s' % response.messages.message[0]['text'].text)
69-
# else:
70-
# print ('Null Response.')
71-
72-
# return response
67+
return response
7368

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

0 commit comments

Comments
 (0)