Skip to content

Commit 016f4dd

Browse files
authored
match the sample in PaymentTransactions
1 parent 54d5457 commit 016f4dd

1 file changed

Lines changed: 60 additions & 17 deletions

File tree

MobileInappTransactions/create-an-accept-transaction.py

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,90 @@
66
constants = imp.load_source('modulename', 'constants.py')
77
from decimal import *
88

9-
def create_an_accept_transaction():
9+
def create_an_accept_transaction(amount):
1010

11+
# Create a merchantAuthenticationType object with authentication details
12+
# retrieved from the constants file
1113
merchantAuth = apicontractsv1.merchantAuthenticationType()
1214
merchantAuth.name = constants.apiLoginId
1315
merchantAuth.transactionKey = constants.transactionKey
1416

15-
opaquedata = apicontractsv1.opaqueDataType()
16-
opaquedata.dataDescriptor = "COMMON.ACCEPT.INAPP.PAYMENT"
17-
opaquedata.dataValue = "9471471570959063005001"
17+
# Create the payment object for a payment nonce
18+
opaqueData = apicontractsv1.opaqueDataType()
19+
opaqueData.dataDescriptor = "COMMON.ACCEPT.INAPP.PAYMENT"
20+
opaqueData.dataValue = "119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9"
1821

22+
# Add the payment data to a paymentType object
1923
paymentOne = apicontractsv1.paymentType()
20-
paymentOne.opaqueData = opaquedata
24+
paymentOne.opaqueData = opaqueData
25+
26+
# Create order information
27+
order = apicontractsv1.orderType()
28+
order.invoiceNumber = "10101"
29+
order.description = "Golf Shirts"
30+
31+
# Set the customer's Bill To address
32+
customerAddress = apicontractsv1.customerAddressType()
33+
customerAddress.firstName = "Ellen"
34+
customerAddress.lastName = "Johnson"
35+
customerAddress.company = "Souveniropolis"
36+
customerAddress.address = "14 Main Street"
37+
customerAddress.city = "Pecan Springs"
38+
customerAddress.state = "TX"
39+
customerAddress.zip = "44628"
40+
customerAddress.country = "USA"
41+
42+
# Set the customer's identifying information
43+
customerData = apicontractsv1.customerDataType()
44+
customerData.type = "individual"
45+
customerData.id = "99999456654"
46+
customerData.email = "[email protected]"
47+
48+
# Add values for transaction settings
49+
duplicateWindowSetting = apicontractsv1.settingType();
50+
duplicateWindowSetting.settingName = "duplicateWindow"
51+
duplicateWindowSetting.settingValue = "600"
52+
settings = apicontractsv1.ArrayOfSetting()
53+
settings.setting.append(duplicateWindowSetting)
2154

55+
# Create a transactionRequestType object and add the previous objects to it
2256
transactionrequest = apicontractsv1.transactionRequestType()
23-
transactionrequest.transactionType = apicontractsv1.transactionTypeEnum.authCaptureTransaction
24-
transactionrequest.amount = Decimal('151')
57+
transactionrequest.transactionType = "authCaptureTransaction"
58+
transactionrequest.amount = amount
59+
transactionrequest.order = order
2560
transactionrequest.payment = paymentOne
61+
transactionrequest.billTo = customerAddress
62+
transactionrequest.customer = customerData
63+
transactionrequest.transactionSettings = settings
2664

27-
request = apicontractsv1.createTransactionRequest()
28-
request.merchantAuthentication = merchantAuth
29-
request.refId = "Sample"
30-
request.transactionRequest = transactionrequest
65+
# Assemble the complete transaction request
66+
createtransactionrequest = apicontractsv1.createTransactionRequest()
67+
createtransactionrequest.merchantAuthentication = merchantAuth
68+
createtransactionrequest.refId = "MerchantID-0001"
69+
createtransactionrequest.transactionRequest = transactionrequest
70+
71+
# Create the controller and get response
72+
createtransactioncontroller = createTransactionController(createtransactionrequest)
73+
createtransactioncontroller.execute()
3174

32-
controller = createTransactionController(request)
33-
controller.execute()
34-
35-
response = controller.getresponse()
75+
response = createtransactioncontroller.getresponse()
3676

3777
if response is not None:
78+
# Check to see if the API request was successfully received and acted upon
3879
if response.messages.resultCode == "Ok":
80+
# Since the API request was successful, look for a transaction response
81+
# and parse it to display the results of authorizing the card
3982
if hasattr(response.transactionResponse, 'messages') == True:
4083
print ('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId);
4184
print ('Transaction Response Code: %s' % response.transactionResponse.responseCode);
4285
print ('Message Code: %s' % response.transactionResponse.messages.message[0].code);
4386
print ('Description: %s' % response.transactionResponse.messages.message[0].description);
44-
print ('AUTH Code : %s' % response.authCode)
4587
else:
4688
print ('Failed Transaction.');
4789
if hasattr(response.transactionResponse, 'errors') == True:
4890
print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode));
4991
print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText);
92+
# Or, print errors if the API request wasn't successful
5093
else:
5194
print ('Failed Transaction.');
5295
if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True:
@@ -61,4 +104,4 @@ def create_an_accept_transaction():
61104
return response
62105

63106
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
64-
create_an_accept_transaction()
107+
create_an_accept_transaction(constants.amount)

0 commit comments

Comments
 (0)