Skip to content

Commit f309cf2

Browse files
authored
Update create-an-accept-payment-transaction.py
standardize refId format clean up responses
1 parent 6256545 commit f309cf2

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

PaymentTransactions/create-an-accept-payment-transaction.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def create_an_accept_payment_transaction(amount):
1313
merchantAuth = apicontractsv1.merchantAuthenticationType()
1414
merchantAuth.name = constants.apiLoginId
1515
merchantAuth.transactionKey = constants.transactionKey
16+
17+
# Set the transaction's refId
18+
refId = "ref {}" format(time.time())
1619

1720
# Create the payment object for a payment nonce
1821
opaqueData = apicontractsv1.opaqueDataType()
@@ -46,7 +49,7 @@ def create_an_accept_payment_transaction(amount):
4649
customerData.email = "EllenJohnson@example.com"
4750

4851
# Add values for transaction settings
49-
duplicateWindowSetting = apicontractsv1.settingType();
52+
duplicateWindowSetting = apicontractsv1.settingType()
5053
duplicateWindowSetting.settingName = "duplicateWindow"
5154
duplicateWindowSetting.settingValue = "600"
5255
settings = apicontractsv1.ArrayOfSetting()
@@ -65,9 +68,9 @@ def create_an_accept_payment_transaction(amount):
6568
# Assemble the complete transaction request
6669
createtransactionrequest = apicontractsv1.createTransactionRequest()
6770
createtransactionrequest.merchantAuthentication = merchantAuth
68-
createtransactionrequest.refId = "MerchantID-0001"
71+
createtransactionrequest.refId = refId
6972
createtransactionrequest.transactionRequest = transactionrequest
70-
73+
7174
# Create the controller and get response
7275
createtransactioncontroller = createTransactionController(createtransactionrequest)
7376
createtransactioncontroller.execute()
@@ -80,26 +83,27 @@ def create_an_accept_payment_transaction(amount):
8083
# Since the API request was successful, look for a transaction response
8184
# and parse it to display the results of authorizing the card
8285
if hasattr(response.transactionResponse, 'messages') == True:
83-
print ('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId);
84-
print ('Transaction Response Code: %s' % response.transactionResponse.responseCode);
85-
print ('Message Code: %s' % response.transactionResponse.messages.message[0].code);
86-
print ('Description: %s' % response.transactionResponse.messages.message[0].description);
86+
print ('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId)
87+
print ('Transaction Response Code: %s' % response.transactionResponse.responseCode)
88+
print ('Message Code: %s' % response.transactionResponse.messages.message[0].code)
89+
print ('Auth Code: %s' % response.transactionResponse.authCode)
90+
print ('Description: %s' % response.transactionResponse.messages.message[0].description)
8791
else:
88-
print ('Failed Transaction.');
92+
print ('Failed Transaction.')
8993
if hasattr(response.transactionResponse, 'errors') == True:
90-
print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode));
91-
print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText);
94+
print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode))
95+
print ('Error Message: %s' % response.transactionResponse.errors.error[0].errorText)
9296
# Or, print errors if the API request wasn't successful
9397
else:
94-
print ('Failed Transaction.');
98+
print ('Failed Transaction.')
9599
if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True:
96-
print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode));
97-
print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText);
100+
print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode))
101+
print ('Error Message: %s' % response.transactionResponse.errors.error[0].errorText)
98102
else:
99-
print ('Error Code: %s' % response.messages.message[0]['code'].text);
100-
print ('Error message: %s' % response.messages.message[0]['text'].text);
103+
print ('Error Code: %s' % response.messages.message[0]['code'].text)
104+
print ('Error Message: %s' % response.messages.message[0]['text'].text)
101105
else:
102-
print ('Null Response.');
106+
print ('Null Response.')
103107

104108
return response
105109

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy