@@ -13,6 +13,9 @@ def create_an_accept_payment_transaction(amount):
13
13
merchantAuth = apicontractsv1 .merchantAuthenticationType ()
14
14
merchantAuth .name = constants .apiLoginId
15
15
merchantAuth .transactionKey = constants .transactionKey
16
+
17
+ # Set the transaction's refId
18
+ refId = "ref {}" format (time .time ())
16
19
17
20
# Create the payment object for a payment nonce
18
21
opaqueData = apicontractsv1 .opaqueDataType ()
@@ -46,7 +49,7 @@ def create_an_accept_payment_transaction(amount):
46
49
customerData .email = "EllenJohnson@example.com"
47
50
48
51
# Add values for transaction settings
49
- duplicateWindowSetting = apicontractsv1 .settingType ();
52
+ duplicateWindowSetting = apicontractsv1 .settingType ()
50
53
duplicateWindowSetting .settingName = "duplicateWindow"
51
54
duplicateWindowSetting .settingValue = "600"
52
55
settings = apicontractsv1 .ArrayOfSetting ()
@@ -65,9 +68,9 @@ def create_an_accept_payment_transaction(amount):
65
68
# Assemble the complete transaction request
66
69
createtransactionrequest = apicontractsv1 .createTransactionRequest ()
67
70
createtransactionrequest .merchantAuthentication = merchantAuth
68
- createtransactionrequest .refId = "MerchantID-0001"
71
+ createtransactionrequest .refId = refId
69
72
createtransactionrequest .transactionRequest = transactionrequest
70
-
73
+
71
74
# Create the controller and get response
72
75
createtransactioncontroller = createTransactionController (createtransactionrequest )
73
76
createtransactioncontroller .execute ()
@@ -80,26 +83,27 @@ def create_an_accept_payment_transaction(amount):
80
83
# Since the API request was successful, look for a transaction response
81
84
# and parse it to display the results of authorizing the card
82
85
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 )
87
91
else :
88
- print ('Failed Transaction.' );
92
+ print ('Failed Transaction.' )
89
93
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 )
92
96
# Or, print errors if the API request wasn't successful
93
97
else :
94
- print ('Failed Transaction.' );
98
+ print ('Failed Transaction.' )
95
99
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 )
98
102
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 )
101
105
else :
102
- print ('Null Response.' );
106
+ print ('Null Response.' )
103
107
104
108
return response
105
109
0 commit comments