|
| 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) |
0 commit comments