-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathMLEConfiguration.py
More file actions
238 lines (213 loc) · 14.4 KB
/
MLEConfiguration.py
File metadata and controls
238 lines (213 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import os
from CyberSource.logging.log_configuration import LogConfiguration
class MLEConfiguration:
def __init__(self):
self.authentication_type ="JWT" #for MLE feature auth type should be JWT
self.merchantid = "testrest"
self.run_environment = "apitest.cybersource.com"
# JWT PARAMETERS
self.key_alias = "testrest"
self.key_pass = "testrest"
self.key_file_name = "testrest"
self.keys_directory = os.path.join(os.getcwd(), "resources")
# META KEY PARAMETERS
self.use_metakey = False
self.portfolio_id = ''
# CONNECTION TIMEOUT PARAMETER
self.timeout = 1000
# LOG PARAMETERS
self.enable_log = True
self.log_file_name = "cybs"
self.log_maximum_size = 10487560
self.log_directory = os.path.join(os.getcwd(), "Logs")
self.log_level = "Debug"
self.enable_masking = True
self.log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
self.log_date_format = "%Y-%m-%d %H:%M:%S"
# PROXY PARAMETERS
#self.proxy_address = "userproxy.com"
#self.proxy_port = ""
# PEM Key file path for decoding JWE Response Enter the folder path where the .pem file is located.
# It is optional property, require adding only during JWE decryption.
self.JWEPemFIleDirectory = os.path.join(os.getcwd(), "resources", "NetworkTokenCert.pem")
# RESPONSE MLE PARAMETERS
self.enableResponseMleGlobally = False
self.responseMlePrivateKeyFilePath = ""
self.responseMlePrivateKeyFilePassword = ""
self.responseMleKID = ""
# MLEConfiguration1
def get_configuration_with_mle_Type1(self):
configuration_dictionary = ({})
configuration_dictionary["authentication_type"] = self.authentication_type
configuration_dictionary["merchantid"] = self.merchantid
configuration_dictionary["run_environment"] = self.run_environment
configuration_dictionary["key_alias"] = self.key_alias
configuration_dictionary["key_password"] = self.key_pass
configuration_dictionary["key_file_name"] = self.key_file_name
configuration_dictionary["keys_directory"] = self.keys_directory
configuration_dictionary["use_metakey"] = self.use_metakey
configuration_dictionary["portfolio_id"] = self.portfolio_id
configuration_dictionary["timeout"] = self.timeout
configuration_dictionary['jwePEMFileDirectory'] = self.JWEPemFIleDirectory
# MLE Config Use Type 1
configuration_dictionary['useMLEGlobally'] = True #globally MLE will be enabled for all the MLE supported APIs by Cybs in SDK
configuration_dictionary['mleKeyAlias'] = "CyberSource_SJC_US" #this is optional paramter, not required to set the parameter if custom value is not required for MLE key alias. Default value is "CyberSource_SJC_US".
#Log Config
log_config = LogConfiguration()
log_config.set_enable_log(self.enable_log)
log_config.set_log_directory(self.log_directory)
log_config.set_log_file_name(self.log_file_name)
log_config.set_log_maximum_size(self.log_maximum_size)
log_config.set_log_level(self.log_level)
log_config.set_enable_masking(self.enable_masking)
log_config.set_log_format(self.log_format)
log_config.set_log_date_format(self.log_date_format)
configuration_dictionary["log_config"] = log_config
#configuration_dictionary["proxy_address"] = self.proxy_address
#configuration_dictionary["proxy_port"] = self.proxy_port
return configuration_dictionary
# MLEConfigurationWithRequestAndResponseMLE2
def get_configuration_with_request_and_response_mle_Type2(self):
configuration_dictionary = ({})
configuration_dictionary["authentication_type"] = self.authentication_type
configuration_dictionary["merchantid"] = "agentic_mid_091225001"
configuration_dictionary["run_environment"] = self.run_environment
configuration_dictionary["key_alias"] = "agentic_mid_091225001"
configuration_dictionary["key_password"] = "Changeit@123"
configuration_dictionary["key_file_name"] = "agentic_mid_091225001"
configuration_dictionary["keys_directory"] = self.keys_directory
configuration_dictionary["timeout"] = self.timeout
# Set Request MLE Settings in Merchant Configuration
configuration_dictionary['enableRequestMLEForOptionalApisGlobally'] = False #Disable request MLE globally for all APIs that have optional MLE support
# APIs that has MLE Request mandatory is default has MLE support in SDK without any configuration but support with JWT auth type.
# Set Response MLE Settings in Merchant Configuration
configuration_dictionary['enableResponseMleGlobally'] = False #Disable response MLE globally for all APIs that support MLE responses
# Set Request & Response MLE Settings in Merchant Configuration through MAP for API control level
configuration_dictionary['mapToControlMLEonAPI'] = {
"create_payment": "true::false", #only create_payment function will have Request MLE=true and Response MLE=false i.e. (/pts/v2/payments POST API)
"enroll_card": "true::true" #only enroll_card function will have Request MLE=true & Response MLE=true i.e. (/acp/v1/tokens POST API)
}
# Since one of the API has Response MLE true, below fields are required for Response MLE
configuration_dictionary['responseMlePrivateKeyFilePath'] = os.path.join(os.getcwd(), "resources", "agentic_mid_091225001_new_generated_mle.p12") #Path to the Response MLE private key file. Supported formats: .p12, .pfx, .pem, .key, .p8
configuration_dictionary['responseMlePrivateKeyFilePassword'] = "Changeit@123" #Password for the private key file (required for .p12/.pfx files or encrypted private keys)
configuration_dictionary['responseMleKID'] = "1764104507829324018353" #Optional since p12 is Cybs Generated
# This parameter is optional when responseMlePrivateKeyFilePath points to a CyberSource-generated P12 file.
# If not provided, the SDK will automatically fetch the Key ID from the P12 file.
# Required when using PEM format files (.pem, .key, .p8) or when providing responseMlePrivateKey object directly.
#Log Config
log_config = LogConfiguration()
log_config.set_enable_log(self.enable_log)
log_config.set_log_directory(self.log_directory)
log_config.set_log_file_name(self.log_file_name)
log_config.set_log_maximum_size(self.log_maximum_size)
log_config.set_log_level(self.log_level)
log_config.set_enable_masking(self.enable_masking)
log_config.set_log_format(self.log_format)
log_config.set_log_date_format(self.log_date_format)
configuration_dictionary["log_config"] = log_config
return configuration_dictionary
# MLEConfigurationWithRequestAndResponseMLE1
def get_configuration_with_request_and_response_mle_Type1(self):
configuration_dictionary = ({})
configuration_dictionary["authentication_type"] = self.authentication_type
configuration_dictionary["merchantid"] = "agentic_mid_091225001"
configuration_dictionary["run_environment"] = self.run_environment
configuration_dictionary["key_alias"] = "agentic_mid_091225001"
configuration_dictionary["key_password"] = "Changeit@123"
configuration_dictionary["key_file_name"] = "agentic_mid_091225001"
configuration_dictionary["keys_directory"] = self.keys_directory
configuration_dictionary["timeout"] = self.timeout
# Set Request MLE Settings in Merchant Configuration
# configuration_dictionary['enableRequestMLEForOptionalApisGlobally'] = True #Enables request MLE globally for all APIs that have optional MLE support
# APIs that has MLE Request mandatory is default has MLE support in SDK without any configuration but support with JWT auth type.
configuration_dictionary['useMLEGlobally'] = False #deprecated variable, use 'enableRequestMLEForOptionalApisGlobally' instead
# Set Response MLE Settings in Merchant Configuration
configuration_dictionary['enableResponseMleGlobally'] = True #Enables response MLE globally for all APIs that support MLE responses
configuration_dictionary['responseMlePrivateKeyFilePath'] = os.path.join(os.getcwd(), "resources", "agentic_mid_091225001_mle.p12") #Path to the Response MLE private key file. Supported formats: .p12, .pfx, .pem, .key, .p8
configuration_dictionary['responseMlePrivateKeyFilePassword'] = "Changeit@123" #Password for the private key file (required for .p12/.pfx files or encrypted private keys)
configuration_dictionary['responseMleKID'] = "1757970970891045729358" #Optional since p12 is Cybs Generated
# This parameter is optional when responseMlePrivateKeyFilePath points to a CyberSource-generated P12 file.
# If not provided, the SDK will automatically fetch the Key ID from the P12 file.
# Required when using PEM format files (.pem, .key, .p8) or when providing responseMlePrivateKey object directly.
#Log Config
log_config = LogConfiguration()
log_config.set_enable_log(self.enable_log)
log_config.set_log_directory(self.log_directory)
log_config.set_log_file_name(self.log_file_name)
log_config.set_log_maximum_size(self.log_maximum_size)
log_config.set_log_level(self.log_level)
log_config.set_enable_masking(self.enable_masking)
log_config.set_log_format(self.log_format)
log_config.set_log_date_format(self.log_date_format)
configuration_dictionary["log_config"] = log_config
return configuration_dictionary
# MLEConfiguration2
def get_configuration_with_mle_Type2(self):
configuration_dictionary = ({})
configuration_dictionary["authentication_type"] = self.authentication_type
configuration_dictionary["merchantid"] = self.merchantid
configuration_dictionary["run_environment"] = self.run_environment
configuration_dictionary["key_alias"] = self.key_alias
configuration_dictionary["key_password"] = self.key_pass
configuration_dictionary["key_file_name"] = self.key_file_name
configuration_dictionary["keys_directory"] = self.keys_directory
configuration_dictionary["use_metakey"] = self.use_metakey
configuration_dictionary["portfolio_id"] = self.portfolio_id
configuration_dictionary["timeout"] = self.timeout
configuration_dictionary['jwePEMFileDirectory'] = self.JWEPemFIleDirectory
# MLE Config Use Type 2
configuration_dictionary['useMLEGlobally'] = True #globally MLE will be enabled for all the MLE supported APIs by Cybs in SDK
configuration_dictionary['mapToControlMLEonAPI'] = {
"create_payment":False, #only create_payment function will have MLE=false i.e. (/pts/v2/payments POST API) out of all MLE supported APIs
"capture_payment":True #capture_payment function will have MLE=true i.e. (/pts/v2/payments/{id}/captures POST API), if it not in list of MLE supportedAPIs else it will already have MLE=true by global MLE parameter.
}
configuration_dictionary['mleKeyAlias'] = "CyberSource_SJC_US" #this is optional paramter, not required to set the parameter if custom value is not required for MLE key alias. Default value is "CyberSource_SJC_US".
#Log Config
log_config = LogConfiguration()
log_config.set_enable_log(self.enable_log)
log_config.set_log_directory(self.log_directory)
log_config.set_log_file_name(self.log_file_name)
log_config.set_log_maximum_size(self.log_maximum_size)
log_config.set_log_level(self.log_level)
log_config.set_enable_masking(self.enable_masking)
log_config.set_log_format(self.log_format)
log_config.set_log_date_format(self.log_date_format)
configuration_dictionary["log_config"] = log_config
#configuration_dictionary["proxy_address"] = self.proxy_address
#configuration_dictionary["proxy_port"] = self.proxy_port
return configuration_dictionary
# MLEConfiguration3
def get_configuration_with_mle_Type3(self):
configuration_dictionary = ({})
configuration_dictionary["authentication_type"] = self.authentication_type
configuration_dictionary["merchantid"] = self.merchantid
configuration_dictionary["run_environment"] = self.run_environment
configuration_dictionary["key_alias"] = self.key_alias
configuration_dictionary["key_password"] = self.key_pass
configuration_dictionary["key_file_name"] = self.key_file_name
configuration_dictionary["keys_directory"] = self.keys_directory
configuration_dictionary["use_metakey"] = self.use_metakey
configuration_dictionary["portfolio_id"] = self.portfolio_id
configuration_dictionary["timeout"] = self.timeout
configuration_dictionary['jwePEMFileDirectory'] = self.JWEPemFIleDirectory
# MLE Config Use Type 3
configuration_dictionary['useMLEGlobally'] = False #globally MLE will be disabled for all the APIs in SDK
configuration_dictionary['mapToControlMLEonAPI'] ={
"create_payment":True, #only create_payment function will have MLE=true i.e. (/pts/v2/payments POST API)
"capture_payment":True #only capture_payment function will have MLE=true i.e. (/pts/v2/payments/{id}/captures POST API)
}
configuration_dictionary['mleKeyAlias'] = "CyberSource_SJC_US" #this is optional paramter, not required to set the parameter if custom value is not required for MLE key alias. Default value is "CyberSource_SJC_US".
#Log Config
log_config = LogConfiguration()
log_config.set_enable_log(self.enable_log)
log_config.set_log_directory(self.log_directory)
log_config.set_log_file_name(self.log_file_name)
log_config.set_log_maximum_size(self.log_maximum_size)
log_config.set_log_level(self.log_level)
log_config.set_enable_masking(self.enable_masking)
log_config.set_log_format(self.log_format)
log_config.set_log_date_format(self.log_date_format)
configuration_dictionary["log_config"] = log_config
#configuration_dictionary["proxy_address"] = self.proxy_address
#configuration_dictionary["proxy_port"] = self.proxy_port
return configuration_dictionary