6
6
constants = imp .load_source ('modulename' , 'constants.py' )
7
7
from decimal import *
8
8
9
- def create_an_accept_transaction ():
9
+ def create_an_accept_transaction (amount ):
10
10
11
+ # Create a merchantAuthenticationType object with authentication details
12
+ # retrieved from the constants file
11
13
merchantAuth = apicontractsv1 .merchantAuthenticationType ()
12
14
merchantAuth .name = constants .apiLoginId
13
15
merchantAuth .transactionKey = constants .transactionKey
14
16
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"
18
21
22
+ # Add the payment data to a paymentType object
19
23
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 = "EllenJohnson@example.com"
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 )
21
54
55
+ # Create a transactionRequestType object and add the previous objects to it
22
56
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
25
60
transactionrequest .payment = paymentOne
61
+ transactionrequest .billTo = customerAddress
62
+ transactionrequest .customer = customerData
63
+ transactionrequest .transactionSettings = settings
26
64
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 ()
31
74
32
- controller = createTransactionController (request )
33
- controller .execute ()
34
-
35
- response = controller .getresponse ()
75
+ response = createtransactioncontroller .getresponse ()
36
76
37
77
if response is not None :
78
+ # Check to see if the API request was successfully received and acted upon
38
79
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
39
82
if hasattr (response .transactionResponse , 'messages' ) == True :
40
83
print ('Successfully created transaction with Transaction ID: %s' % response .transactionResponse .transId );
41
84
print ('Transaction Response Code: %s' % response .transactionResponse .responseCode );
42
85
print ('Message Code: %s' % response .transactionResponse .messages .message [0 ].code );
43
86
print ('Description: %s' % response .transactionResponse .messages .message [0 ].description );
44
- print ('AUTH Code : %s' % response .authCode )
45
87
else :
46
88
print ('Failed Transaction.' );
47
89
if hasattr (response .transactionResponse , 'errors' ) == True :
48
90
print ('Error Code: %s' % str (response .transactionResponse .errors .error [0 ].errorCode ));
49
91
print ('Error message: %s' % response .transactionResponse .errors .error [0 ].errorText );
92
+ # Or, print errors if the API request wasn't successful
50
93
else :
51
94
print ('Failed Transaction.' );
52
95
if hasattr (response , 'transactionResponse' ) == True and hasattr (response .transactionResponse , 'errors' ) == True :
@@ -61,4 +104,4 @@ def create_an_accept_transaction():
61
104
return response
62
105
63
106
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