Skip to content

Commit 0bb8784

Browse files
authored
Merge pull request #70 from snavinch/master
June 2021 SDK Release
2 parents e17119f + 68f8f71 commit 0bb8784

File tree

130 files changed

+3491
-390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+3491
-390
lines changed

CyberSource/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
from __future__ import absolute_import
1515

1616
# import models into sdk package
17+
from .models.access_token_response import AccessTokenResponse
18+
from .models.bad_request_error import BadRequestError
19+
from .models.create_access_token_request import CreateAccessTokenRequest
20+
from .models.resource_not_found_error import ResourceNotFoundError
21+
from .models.unauthorized_client_error import UnauthorizedClientError
1722
from .models.add_negative_list_request import AddNegativeListRequest
1823
from .models.auth_reversal_request import AuthReversalRequest
1924
from .models.capture_payment_request import CapturePaymentRequest
@@ -170,6 +175,7 @@
170175
from .models.pts_v2_payments_post201_response_order_information import PtsV2PaymentsPost201ResponseOrderInformation
171176
from .models.pts_v2_payments_post201_response_order_information_amount_details import PtsV2PaymentsPost201ResponseOrderInformationAmountDetails
172177
from .models.pts_v2_payments_post201_response_order_information_invoice_details import PtsV2PaymentsPost201ResponseOrderInformationInvoiceDetails
178+
from .models.pts_v2_payments_post201_response_order_information_reward_points_details import PtsV2PaymentsPost201ResponseOrderInformationRewardPointsDetails
173179
from .models.pts_v2_payments_post201_response_payment_information import PtsV2PaymentsPost201ResponsePaymentInformation
174180
from .models.pts_v2_payments_post201_response_payment_information_account_features import PtsV2PaymentsPost201ResponsePaymentInformationAccountFeatures
175181
from .models.pts_v2_payments_post201_response_payment_information_account_features_balances import PtsV2PaymentsPost201ResponsePaymentInformationAccountFeaturesBalances
@@ -308,6 +314,7 @@
308314
from .models.ptsv2payments_recipient_information import Ptsv2paymentsRecipientInformation
309315
from .models.ptsv2payments_recurring_payment_information import Ptsv2paymentsRecurringPaymentInformation
310316
from .models.ptsv2payments_risk_information import Ptsv2paymentsRiskInformation
317+
from .models.ptsv2payments_risk_information_auxiliary_data import Ptsv2paymentsRiskInformationAuxiliaryData
311318
from .models.ptsv2payments_risk_information_buyer_history import Ptsv2paymentsRiskInformationBuyerHistory
312319
from .models.ptsv2payments_risk_information_buyer_history_account_history import Ptsv2paymentsRiskInformationBuyerHistoryAccountHistory
313320
from .models.ptsv2payments_risk_information_buyer_history_customer_account import Ptsv2paymentsRiskInformationBuyerHistoryCustomerAccount
@@ -520,6 +527,7 @@
520527
from .models.riskv1exportcomplianceinquiries_order_information_line_items import Riskv1exportcomplianceinquiriesOrderInformationLineItems
521528
from .models.riskv1exportcomplianceinquiries_order_information_ship_to import Riskv1exportcomplianceinquiriesOrderInformationShipTo
522529
from .models.riskv1liststypeentries_buyer_information import Riskv1liststypeentriesBuyerInformation
530+
from .models.riskv1liststypeentries_client_reference_information import Riskv1liststypeentriesClientReferenceInformation
523531
from .models.riskv1liststypeentries_device_information import Riskv1liststypeentriesDeviceInformation
524532
from .models.riskv1liststypeentries_order_information import Riskv1liststypeentriesOrderInformation
525533
from .models.riskv1liststypeentries_order_information_address import Riskv1liststypeentriesOrderInformationAddress
@@ -706,6 +714,7 @@
706714
from .models.void_tax_request import VoidTaxRequest
707715

708716
# import apis into sdk package
717+
from .apis.o_auth_api import OAuthApi
709718
from .apis.asymmetric_key_management_api import AsymmetricKeyManagementApi
710719
from .apis.capture_api import CaptureApi
711720
from .apis.conversion_details_api import ConversionDetailsApi

CyberSource/api_client.py

+32-5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ def set_default_header(self, header_name, header_value):
106106
def get_client_id(self):
107107
version = pkg_resources.require("cybersource-rest-client-python")[0].version
108108
return "cybs-rest-sdk-python-" + version
109+
110+
def remove_first_underscore(self, dict_obj):
111+
converted_dict_obj = {}
112+
dict_obj = json.loads(dict_obj)
113+
for i in dict_obj:
114+
new_key = str(i)[1:]
115+
val = dict_obj[i]
116+
converted_dict_obj[new_key] = val
117+
return converted_dict_obj
109118

110119
# replace the underscore
111120
def replace_underscore(self, dict_obj, deep=True):
@@ -141,10 +150,14 @@ def set_configuration(self,config):
141150
global mconfig
142151
mconfig = MerchantConfiguration()
143152
mconfig.set_merchantconfig(config)
153+
rconfig = Configuration()
144154

145-
# The below two lines are to set proxy details and if present reinitialize the REST object as a proxy manager
146-
if Configuration().set_merchantproxyconfig(config):
147-
self.rest_client = RESTClientObject() # Reinitialising REST object as a proxy manager instead of pool manager
155+
set_client_cert = rconfig.set_merchantclientcert(config)
156+
set_proxy = rconfig.set_merchantproxyconfig(config)
157+
158+
# The below two lines are to set proxy details, client cert details and if present reinitialize the REST object as a proxy manager
159+
if set_client_cert or set_proxy:
160+
self.rest_client = RESTClientObject(rconfig) # Reinitialising REST object as a proxy manager instead of pool manager
148161

149162
# This implements the fall back logic for JWT parameters key alias,key password,json file path
150163
mconfig.validate_merchant_details(config, mconfig)
@@ -190,6 +203,10 @@ def call_authentication_header(self, method, header_params, body):
190203

191204
token = "Bearer " + token
192205
header_params['Authorization'] = str(token)
206+
elif mconfig.authentication_type.upper() == GlobalLabelParameters.OAUTH:
207+
208+
token = "Bearer " + token
209+
header_params['Authorization'] = str(token)
193210

194211

195212
# Set the digest
@@ -252,6 +269,7 @@ def __call_api(self, resource_path, method,
252269

253270
# post parameters
254271
if post_params or files:
272+
post_params = self.remove_first_underscore(post_params)
255273
post_params = self.prepare_post_parameters(post_params, files)
256274
post_params = self.sanitize_for_serialization(post_params)
257275
post_params = self.parameters_to_tuples(post_params,
@@ -268,7 +286,7 @@ def __call_api(self, resource_path, method,
268286
url = GlobalLabelParameters.HTTP_URL_PREFIX+self.host + resource_path
269287

270288
if self.download_file_path is not None:
271-
_preload_content = False
289+
_preload_content = False
272290
_request_timeout = 3000
273291

274292
# perform request and return response
@@ -423,6 +441,10 @@ def call_api(self, resource_path, method,
423441
response_type=None, auth_settings=None, callback=None,
424442
_return_http_data_only=None, collection_formats=None, _preload_content=True,
425443
_request_timeout=None):
444+
445+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded':
446+
post_params = body
447+
426448
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT or method.upper() == GlobalLabelParameters.PATCH:
427449
temp_body = body.replace("\"_", "\"")
428450
request_body = self.replace_underscore(json.loads(temp_body))
@@ -435,7 +457,10 @@ def call_api(self, resource_path, method,
435457
mconfig.request_target = query_param_path
436458
else:
437459
mconfig.request_target = resource_path
438-
self.call_authentication_header(method, header_params, body)
460+
461+
if mconfig.authentication_type.upper() != GlobalLabelParameters.MUTUAL_AUTH.upper():
462+
self.call_authentication_header(method, header_params, body)
463+
439464
"""
440465
Makes the HTTP request (synchronous) and return the deserialized data.
441466
To make an async request, define a function for callback.
@@ -561,6 +586,8 @@ def parameters_to_tuples(self, params, collection_formats):
561586
new_params = []
562587
if collection_formats is None:
563588
collection_formats = {}
589+
if isinstance(params, str):
590+
params = json.loads(params)
564591
for k, v in iteritems(params) if isinstance(params, dict) else params:
565592
if k in collection_formats:
566593
collection_format = collection_formats[k]

CyberSource/apis/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22

33
# import apis into api package
4+
from .o_auth_api import OAuthApi
45
from .asymmetric_key_management_api import AsymmetricKeyManagementApi
56
from .capture_api import CaptureApi
67
from .conversion_details_api import ConversionDetailsApi

CyberSource/apis/o_auth_api.py

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# coding: utf-8
2+
3+
"""
4+
OAuth2 API
5+
6+
OAuth2 Token Service (OAuth2)
7+
8+
OpenAPI spec version: v3
9+
10+
Generated by: https://github.com/swagger-api/swagger-codegen.git
11+
"""
12+
13+
14+
from __future__ import absolute_import
15+
16+
import sys
17+
import os
18+
import re
19+
20+
# python 2 and python 3 compatibility library
21+
from six import iteritems
22+
23+
from ..configuration import Configuration
24+
from ..api_client import ApiClient
25+
26+
27+
class OAuthApi(object):
28+
"""
29+
NOTE: This class is auto generated by the swagger code generator program.
30+
Do not edit the class manually.
31+
Ref: https://github.com/swagger-api/swagger-codegen
32+
"""
33+
34+
def __init__(self, merchant_config, api_client=None):
35+
config = Configuration()
36+
if api_client:
37+
self.api_client = api_client
38+
else:
39+
if not config.api_client:
40+
config.api_client = ApiClient()
41+
self.api_client = config.api_client
42+
self.api_client.set_configuration(merchant_config)
43+
44+
45+
def create_access_token(self, create_access_token_request, **kwargs):
46+
"""
47+
Create access token and refresh token
48+
This request is used by technology partners to obtain an access token and a refresh token, which are contained in the response. The partner can then use the access token for authentication when submitting API requests to CyberSource on behalf of the merchant. The request must include the authorization code that was included in the URL redirect response from CyberSource (see [full documentation](https://developer.cybersource.com/api/developer-guides/OAuth/cybs_extend_intro.html)). Access tokens expire after 15 minutes. The refresh token is used to create a new access token, it expires after one year.
49+
This method makes a synchronous HTTP request by default. To make an
50+
asynchronous HTTP request, please define a `callback` function
51+
to be invoked when receiving the response.
52+
>>> def callback_function(response):
53+
>>> pprint(response)
54+
>>>
55+
>>> thread = api.create_access_token(create_access_token_request, callback=callback_function)
56+
57+
:param callback function: The callback function
58+
for asynchronous request. (optional)
59+
:param CreateAccessTokenRequest create_access_token_request: Request payload (required)
60+
:param str v_c_client_correlation_id: We recommended that you submit this header with a unique value in every client request to this endpoint. It is sent back in the response header and logged both in the request log and response log.
61+
:return: AccessTokenResponse
62+
If the method is called asynchronously,
63+
returns the request thread.
64+
"""
65+
kwargs['_return_http_data_only'] = True
66+
if kwargs.get('callback'):
67+
return self.create_access_token_with_http_info(create_access_token_request, **kwargs)
68+
else:
69+
(data) = self.create_access_token_with_http_info(create_access_token_request, **kwargs)
70+
return data
71+
72+
def create_access_token_with_http_info(self, create_access_token_request, **kwargs):
73+
"""
74+
Create access token and refresh token
75+
This request is used by technology partners to obtain an access token and a refresh token, which are contained in the response. The partner can then use the access token for authentication when submitting API requests to CyberSource on behalf of the merchant. The request must include the authorization code that was included in the URL redirect response from CyberSource (see [full documentation](https://developer.cybersource.com/api/developer-guides/OAuth/cybs_extend_intro.html)). Access tokens expire after 15 minutes. The refresh token is used to create a new access token, it expires after one year.
76+
This method makes a synchronous HTTP request by default. To make an
77+
asynchronous HTTP request, please define a `callback` function
78+
to be invoked when receiving the response.
79+
>>> def callback_function(response):
80+
>>> pprint(response)
81+
>>>
82+
>>> thread = api.create_access_token_with_http_info(create_access_token_request, callback=callback_function)
83+
84+
:param callback function: The callback function
85+
for asynchronous request. (optional)
86+
:param CreateAccessTokenRequest create_access_token_request: Request payload (required)
87+
:param str v_c_client_correlation_id: We recommended that you submit this header with a unique value in every client request to this endpoint. It is sent back in the response header and logged both in the request log and response log.
88+
:return: AccessTokenResponse
89+
If the method is called asynchronously,
90+
returns the request thread.
91+
"""
92+
93+
all_params = ['create_access_token_request', 'v_c_client_correlation_id']
94+
all_params.append('callback')
95+
all_params.append('_return_http_data_only')
96+
all_params.append('_preload_content')
97+
all_params.append('_request_timeout')
98+
99+
params = locals()
100+
for key, val in iteritems(params['kwargs']):
101+
if key not in all_params:
102+
raise TypeError(
103+
"Got an unexpected keyword argument '%s'"
104+
" to method create_access_token" % key
105+
)
106+
params[key] = val
107+
del params['kwargs']
108+
# verify the required parameter 'create_access_token_request' is set
109+
if ('create_access_token_request' not in params) or (params['create_access_token_request'] is None):
110+
raise ValueError("Missing the required parameter `create_access_token_request` when calling `create_access_token`")
111+
112+
if 'v_c_client_correlation_id' in params and len(params['v_c_client_correlation_id']) > 36:
113+
raise ValueError("Invalid value for parameter `v_c_client_correlation_id` when calling `create_access_token`, length must be less than or equal to `36`")
114+
if 'v_c_client_correlation_id' in params and len(params['v_c_client_correlation_id']) < 36:
115+
raise ValueError("Invalid value for parameter `v_c_client_correlation_id` when calling `create_access_token`, length must be greater than or equal to `36`")
116+
if 'v_c_client_correlation_id' in params and not re.search('^[A-Za-z0-9\\.\\-_:]+$', params['v_c_client_correlation_id']):
117+
raise ValueError("Invalid value for parameter `v_c_client_correlation_id` when calling `create_access_token`, must conform to the pattern `/^[A-Za-z0-9\\.\\-_:]+$/`")
118+
119+
collection_formats = {}
120+
121+
path_params = {}
122+
123+
query_params = []
124+
125+
header_params = {}
126+
if 'v_c_client_correlation_id' in params:
127+
header_params['v-c-client-correlation-id'] = params['v_c_client_correlation_id']
128+
129+
form_params = []
130+
local_var_files = {}
131+
132+
body_params = None
133+
if 'create_access_token_request' in params:
134+
body_params = params['create_access_token_request']
135+
# HTTP header `Accept`
136+
header_params['Accept'] = self.api_client.\
137+
select_header_accept(['application/json;charset=utf-8'])
138+
139+
# HTTP header `Content-Type`
140+
header_params['Content-Type'] = self.api_client.\
141+
select_header_content_type(['application/x-www-form-urlencoded'])
142+
143+
# Authentication setting
144+
auth_settings = []
145+
146+
return self.api_client.call_api(f'/oauth2/v3/token', 'POST',
147+
path_params,
148+
query_params,
149+
header_params,
150+
body=body_params,
151+
post_params=form_params,
152+
files=local_var_files,
153+
response_type='AccessTokenResponse',
154+
auth_settings=auth_settings,
155+
callback=params.get('callback'),
156+
_return_http_data_only=params.get('_return_http_data_only'),
157+
_preload_content=params.get('_preload_content', True),
158+
_request_timeout=params.get('_request_timeout'),
159+
collection_formats=collection_formats)

CyberSource/configuration.py

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import sys
1919
import logging
20+
import os
2021

2122
from six import iteritems
2223
from six.moves import http_client as httplib
@@ -85,6 +86,8 @@ def __init__(self):
8586
self.cert_file = None
8687
# client key file
8788
self.key_file = None
89+
# client key file password
90+
self.key_password = None
8891

8992
# Proxy URL
9093
self.proxy = None
@@ -234,6 +237,15 @@ def set_merchantproxyconfig(self, val):
234237
else:
235238
return False
236239
return True
240+
241+
def set_merchantclientcert(self, val):
242+
if val.get('enable_client_cert'):
243+
self.cert_file = os.path.join(val.get('client_cert_dir'), val.get('ssl_client_cert'))
244+
self.key_file = os.path.join(val.get('client_cert_dir'), val.get('private_key'))
245+
self.key_password = val.get('ssl_key_password')
246+
return True
247+
else:
248+
return False
237249

238250
def set_proxy(self, value):
239251
if not (value.get('proxy_address') is None or value.get('proxy_address') == '' or value.get('proxy_port') is None or value.get('proxy_port') == ''):

0 commit comments

Comments
 (0)