Skip to content

Commit 546461b

Browse files
Release V2.1.0 (#43)
* Automated commit message * Update CHANGELOG.md --------- Co-authored-by: PayPalServerSDKs <server-sdks@paypal.com>
1 parent 3fba0f2 commit 546461b

15 files changed

+447
-68
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.1.0
2+
- New Feature:
3+
- Configuration-Based Client Initialization
4+
- Bug Fixes:
5+
- Fix missing `OTHERS` value in `Shipment Carrier` enum model
6+
- Update Transaction Search API naming in docs
7+
18
## 2.0.0
29
- Breaking Changes:
310
- Several model renames for more precise mapping to controllers

PaypalServerSdk.Standard/Authentication/ClientCredentialsAuthManager.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,5 +326,20 @@ public ClientCredentialsAuthModel Build()
326326
};
327327
}
328328
}
329+
330+
internal static ClientCredentialsAuthModel FromOptions(ClientCredentialsAuthModelOptions options)
331+
{
332+
var builder = new Builder(options.OAuthClientId, options.OAuthClientSecret);
333+
if (options.OAuthClockSkew != null)
334+
builder.OAuthClockSkew(options.OAuthClockSkew);
335+
return builder.Build();
336+
}
337+
}
338+
339+
public class ClientCredentialsAuthModelOptions
340+
{
341+
public string OAuthClientId { get; set; }
342+
public string OAuthClientSecret { get; set; }
343+
public TimeSpan? OAuthClockSkew { get; set; }
329344
}
330345
}

PaypalServerSdk.Standard/Http/Client/HttpClientConfiguration.cs

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
//
44
// This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
55
// </copyright>
6+
using APIMatic.Core.Http.Configuration;
7+
using PaypalServerSdk.Standard.Http.Client.Proxy;
68
using System;
79
using System.Collections.Generic;
10+
using System.Linq;
811
using System.Net.Http;
9-
using APIMatic.Core.Http.Configuration;
10-
using APIMatic.Core.Proxy;
11-
using PaypalServerSdk.Standard.Http.Client.Proxy;
1212

1313
namespace PaypalServerSdk.Standard.Http.Client
1414
{
@@ -18,17 +18,11 @@ namespace PaypalServerSdk.Standard.Http.Client
1818
public class HttpClientConfiguration : IHttpClientConfiguration
1919
{
2020
private readonly CoreHttpClientConfiguration coreHttpClientConfiguration;
21-
/// <summary>
22-
/// Initializes a new instance of the <see cref="HttpClientConfiguration"/>
23-
/// class.
24-
/// </summary>
25-
private readonly CoreProxyConfiguration coreProxyConfiguration;
21+
2622
private HttpClientConfiguration(
27-
CoreHttpClientConfiguration.Builder coreHttpClientConfigurationBuilder,
28-
CoreProxyConfiguration coreProxyConfiguration)
23+
CoreHttpClientConfiguration.Builder coreHttpClientConfigurationBuilder)
2924
{
3025
coreHttpClientConfiguration = coreHttpClientConfigurationBuilder.Build();
31-
this.coreProxyConfiguration = coreProxyConfiguration;
3226
}
3327

3428
/// <summary>
@@ -98,8 +92,7 @@ public override string ToString()
9892
public Builder ToBuilder()
9993
=> new Builder()
10094
{
101-
CoreHttpClientConfigurationBuilder = coreHttpClientConfiguration.ToBuilder(),
102-
CoreProxyConfiguration = this.coreProxyConfiguration
95+
CoreHttpClientConfigurationBuilder = coreHttpClientConfiguration.ToBuilder()
10396
};
10497

10598
/// <summary>
@@ -108,7 +101,6 @@ public Builder ToBuilder()
108101
public class Builder
109102
{
110103
internal CoreHttpClientConfiguration.Builder CoreHttpClientConfigurationBuilder { private get; set; } = new CoreHttpClientConfiguration.Builder();
111-
internal CoreProxyConfiguration CoreProxyConfiguration { private get; set; }
112104

113105
/// <summary>
114106
/// Sets the Timeout.
@@ -199,15 +191,19 @@ public Builder HttpClientInstance(HttpClient httpClientInstance, bool overrideHt
199191
return this;
200192
}
201193

202-
/// <summary>
194+
internal Builder RequestMethodsToRetry(IList<string> requestMethodsToRetry)
195+
{
196+
CoreHttpClientConfigurationBuilder =
197+
CoreHttpClientConfigurationBuilder.RequestMethodsToRetry(requestMethodsToRetry.ToHttpMethods());
198+
return this;
199+
} /// <summary>
203200
/// Sets the Proxy.
204201
/// </summary>
205202
/// <param name="proxyConfigurationBuilder"> ProxyConfigurationBuilder. </param>
206203
/// <returns>Builder.</returns>
207204
public Builder Proxy(ProxyConfigurationBuilder proxyConfigurationBuilder)
208205
{
209206
var proxyConfiguration = proxyConfigurationBuilder?.Build();
210-
CoreProxyConfiguration = proxyConfiguration;
211207
CoreHttpClientConfigurationBuilder.ProxyConfiguration(proxyConfiguration);
212208
return this;
213209
}
@@ -218,8 +214,70 @@ public Builder Proxy(ProxyConfigurationBuilder proxyConfigurationBuilder)
218214
/// <returns>HttpClientConfiguration.</returns>
219215
public HttpClientConfiguration Build()
220216
{
221-
return new HttpClientConfiguration(CoreHttpClientConfigurationBuilder, CoreProxyConfiguration);
217+
return new HttpClientConfiguration(CoreHttpClientConfigurationBuilder);
222218
}
223219
}
220+
221+
internal static Builder FromOptions(HttpClientConfigurationOptions options)
222+
{
223+
var builder = new Builder();
224+
if (options.Timeout != null)
225+
builder.Timeout(options.Timeout.Value);
226+
if (options.NumberOfRetries != null)
227+
builder.NumberOfRetries(options.NumberOfRetries.Value);
228+
if (options.BackoffFactor != null)
229+
builder.BackoffFactor(options.BackoffFactor.Value);
230+
if (options.RetryInterval != null)
231+
builder.RetryInterval(options.RetryInterval.Value);
232+
if (options.MaximumRetryWaitTime != null)
233+
builder.MaximumRetryWaitTime(options.MaximumRetryWaitTime.Value);
234+
if (options.StatusCodesToRetry != null)
235+
builder.StatusCodesToRetry(options.StatusCodesToRetry);
236+
if (options.RequestMethodsToRetry != null)
237+
builder.RequestMethodsToRetry(options.RequestMethodsToRetry);
238+
if (options.Proxy != null)
239+
builder.Proxy(ProxyConfigurationBuilder.FromOptions(options.Proxy));
240+
return builder;
241+
}
242+
}
243+
244+
public class HttpClientConfigurationOptions
245+
{
246+
public TimeSpan? Timeout { get; set; }
247+
public int? NumberOfRetries { get; set; }
248+
public int? BackoffFactor { get; set; }
249+
public double? RetryInterval { get; set; }
250+
public TimeSpan? MaximumRetryWaitTime { get; set; }
251+
public IList<int> StatusCodesToRetry { get; set; }
252+
public IList<string> RequestMethodsToRetry { get; set; }
253+
public ProxyOptions Proxy { get; set; }
254+
}
255+
256+
internal static class HttpClientConfigurationExtensions
257+
{
258+
public static IList<HttpMethod> ToHttpMethods(this IList<string> methodStrings)
259+
{
260+
return methodStrings == null
261+
? new List<HttpMethod>()
262+
: methodStrings
263+
.Select(m =>
264+
{
265+
var method = m.ToUpperInvariant();
266+
switch (method)
267+
{
268+
case "GET": return HttpMethod.Get;
269+
case "POST": return HttpMethod.Post;
270+
case "PUT": return HttpMethod.Put;
271+
case "DELETE": return HttpMethod.Delete;
272+
case "HEAD": return HttpMethod.Head;
273+
case "OPTIONS": return HttpMethod.Options;
274+
case "TRACE": return HttpMethod.Trace;
275+
case "PATCH": return new HttpMethod("PATCH");
276+
default: return null; // Return null for unknown methods
277+
}
278+
})
279+
.Where(m => m != null) // Filter out nulls
280+
.ToList();
281+
}
224282
}
225283
}

PaypalServerSdk.Standard/Http/Client/Proxy/ProxyConfigurationBuilder.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace PaypalServerSdk.Standard.Http.Client.Proxy
1212
/// </summary>
1313
public class ProxyConfigurationBuilder
1414
{
15-
private string _address;
15+
private readonly string _address;
1616
private int _port = 8080;
1717
private string _user;
1818
private string _pass;
@@ -27,6 +27,22 @@ public ProxyConfigurationBuilder(string address)
2727
_address = address;
2828
}
2929

30+
internal static ProxyConfigurationBuilder FromOptions(ProxyOptions options)
31+
{
32+
if (options == null || string.IsNullOrEmpty(options.Address))
33+
return null;
34+
35+
var builder = new ProxyConfigurationBuilder(options.Address);
36+
if (options.Port != null)
37+
builder.Port(options.Port.Value);
38+
if (!string.IsNullOrEmpty(options.User) && !string.IsNullOrEmpty(options.Pass))
39+
builder.Auth(options.User, options.Pass);
40+
41+
builder.Tunnel(options.Tunnel);
42+
43+
return builder;
44+
}
45+
3046
/// <summary>
3147
/// Sets the Port.
3248
/// </summary>
@@ -67,4 +83,13 @@ internal CoreProxyConfiguration Build()
6783
return new CoreProxyConfiguration(_address, _port, _user, _pass, _tunnel);
6884
}
6985
}
70-
}
86+
87+
public class ProxyOptions
88+
{
89+
public string Address { get; set; }
90+
public int? Port { get; set; }
91+
public bool Tunnel { get; set; }
92+
public string User { get; set; }
93+
public string Pass { get; set; }
94+
}
95+
}

PaypalServerSdk.Standard/Logging/LogBuilder.cs

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
//
44
// This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
55
// </copyright>
6-
using System;
7-
using System.Collections.Generic;
86
using APIMatic.Core.Utilities.Logger;
97
using APIMatic.Core.Utilities.Logger.Configuration;
108
using Microsoft.Extensions.Logging;
11-
using Microsoft.Extensions.Logging.Abstractions;
9+
using System;
10+
using System.Collections.Generic;
1211

1312
namespace PaypalServerSdk.Standard.Logging
1413
{
@@ -48,6 +47,25 @@ public static LogBuilder CreateFromConfig(SdkLoggingConfiguration loggingConfigu
4847
loggingConfiguration.RequestLoggingConfiguration,
4948
loggingConfiguration.ResponseLoggingConfiguration);
5049
}
50+
51+
internal static SdkLoggingConfiguration FromOptions(LoggingConfigOptions options)
52+
{
53+
var requestLoggingConfiguration = options.RequestLoggingConfiguration != null
54+
? LogRequestBuilder.FromOptions(options.RequestLoggingConfiguration)
55+
: null;
56+
57+
var responseLoggingConfiguration = options.ResponseLoggingConfiguration != null
58+
? LogResponseBuilder.FromOptions(options.ResponseLoggingConfiguration)
59+
: null;
60+
61+
return SdkLoggingConfiguration.Builder(
62+
ConsoleLogger.Instance,
63+
options.LogLevel,
64+
options.MaskSensitiveHeaders,
65+
requestLoggingConfiguration,
66+
responseLoggingConfiguration
67+
);
68+
}
5169

5270
/// <summary>
5371
/// Sets the logger for the logging configuration.
@@ -153,6 +171,16 @@ internal static LogRequestBuilder FromRequestConfig(RequestLoggingConfiguration
153171
requestLoggingConfiguration.HeadersToExclude,
154172
requestLoggingConfiguration.HeadersToUnmask);
155173

174+
internal static RequestLoggingConfiguration FromOptions(RequestLoggingConfigurationOptions options) =>
175+
RequestLoggingConfiguration.Builder(
176+
options.Body,
177+
options.Headers,
178+
options.IncludeQueryInPath,
179+
options.HeadersToInclude,
180+
options.HeadersToExclude,
181+
options.HeadersToUnmask
182+
);
183+
156184
/// <summary>
157185
/// Sets whether to include the request body in the logging configuration.
158186
/// </summary>
@@ -257,6 +285,15 @@ internal static LogResponseBuilder FromRequestConfig(ResponseLoggingConfiguratio
257285
responseLoggingConfiguration.HeadersToExclude,
258286
responseLoggingConfiguration.HeadersToUnmask);
259287

288+
internal static ResponseLoggingConfiguration FromOptions(ResponseLoggingConfigurationOptions options) =>
289+
ResponseLoggingConfiguration.Builder(
290+
options.Body,
291+
options.Headers,
292+
options.HeadersToInclude,
293+
options.HeadersToExclude,
294+
options.HeadersToUnmask
295+
);
296+
260297
/// <summary>
261298
/// Sets whether to include the response body in the logging configuration.
262299
/// </summary>
@@ -320,4 +357,31 @@ internal ResponseLoggingConfiguration Build() =>
320357
ResponseLoggingConfiguration.Builder(_logBody, _logHeaders,
321358
_headersToInclude, _headersToExclude, _headersToUnmask);
322359
}
323-
}
360+
361+
public class LoggingConfigOptions
362+
{
363+
public LogLevel? LogLevel { get; set; }
364+
public bool MaskSensitiveHeaders { get; set; } = true;
365+
public RequestLoggingConfigurationOptions RequestLoggingConfiguration { get; set; }
366+
public ResponseLoggingConfigurationOptions ResponseLoggingConfiguration { get; set; }
367+
}
368+
369+
public class RequestLoggingConfigurationOptions
370+
{
371+
public bool Body { get; set; }
372+
public bool Headers { get; set; }
373+
public bool IncludeQueryInPath { get; set; }
374+
public IReadOnlyCollection<string> HeadersToInclude { get; set; }
375+
public IReadOnlyCollection<string> HeadersToExclude { get; set; }
376+
public IReadOnlyCollection<string> HeadersToUnmask { get; set; }
377+
}
378+
379+
public class ResponseLoggingConfigurationOptions
380+
{
381+
public bool Body { get; set; }
382+
public bool Headers { get; set; }
383+
public IReadOnlyCollection<string> HeadersToInclude { get; set; }
384+
public IReadOnlyCollection<string> HeadersToExclude { get; set; }
385+
public IReadOnlyCollection<string> HeadersToUnmask { get; set; }
386+
}
387+
}

PaypalServerSdk.Standard/Models/ShipmentCarrier.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9905,6 +9905,13 @@ public enum ShipmentCarrier
99059905
[EnumMember(Value = "TOPTRANS")]
99069906
Toptrans,
99079907

9908+
/// <summary>
9909+
///Other.
9910+
/// Other.
9911+
/// </summary>
9912+
[EnumMember(Value = "OTHER")]
9913+
Other,
9914+
99089915
/// <summary>
99099916
/// Unknown values will be mapped by this enum member.
99109917
/// </summary>

PaypalServerSdk.Standard/PaypalServerSdk.Standard.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
<PropertyGroup>
1010
<TargetFramework>netstandard2.0</TargetFramework>
1111
<AssemblyName>PayPalServerSDK</AssemblyName>
12-
<Version>2.0.0.0</Version>
12+
<Version>2.1.0.0</Version>
1313

1414
<Owners></Owners>
1515
<Product>PaypalServerSdk.Standard</Product>
1616
<Copyright>Copyright © 2019</Copyright>
17-
<AssemblyVersion>2.0.0.0</AssemblyVersion>
18-
<FileVersion>2.0.0.0</FileVersion>
17+
<AssemblyVersion>2.1.0.0</AssemblyVersion>
18+
<FileVersion>2.1.0.0</FileVersion>
1919
<Description>PayPal's SDK for interacting with the REST APIs</Description>
2020
<LangVersion>7.3</LangVersion>
2121
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
@@ -26,12 +26,14 @@
2626
<PackageLicenseFile>LICENSE</PackageLicenseFile>
2727

2828
<GenerateDocumentationFile>true</GenerateDocumentationFile>
29+
<NoWarn>$(NoWarn);1591</NoWarn>
2930
</PropertyGroup>
3031

3132
<ItemGroup>
3233
<None Include="..\README.md" Link="README.md" />
3334
<PackageReference Include="APIMatic.Core" Version= "[0.4.*, 0.5.0)" />
3435
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
36+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
3537
<None Include="..\README.md" Pack="true" PackagePath="\"/>
3638
<None Include="..\LICENSE" Pack="true" PackagePath="\"/>
3739
</ItemGroup>

0 commit comments

Comments
 (0)