generated from Yortw/OssLibTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LaybuyClientConfiguration.cs
110 lines (96 loc) · 3 KB
/
LaybuyClientConfiguration.cs
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
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net.Http;
using System.Text;
using Ladon;
namespace Yort.Laybuy.InStore
{
/// <summary>
/// Provides configuration settings for <see cref="ILaybuyClient"/> and default values for some requests..
/// </summary>
public class LaybuyClientConfiguration
{
private LaybuyEnvironment _Environment;
private Uri? _RootUri;
/// <summary>
/// Default constructor.
/// </summary>
public LaybuyClientConfiguration(LaybuyCredentials credentials)
{
this.Credentials = credentials.GuardNull(nameof(credentials));
Environment = LaybuyEnvironment.Sandbox;
}
/// <summary>
/// Gets or sets a value from the <see cref="LaybuyEnvironment"/> enum specifying whether this client connects to the production or sandboxed (test) Laybuy API.
/// </summary>
/// <remarks>
/// <para>The default value is <see cref="LaybuyEnvironment.Sandbox"/> to prevent accidental live transactions. Production systems must specify <see cref="LaybuyEnvironment.Production"/> for real payments to occur.</para>
/// </remarks>
[ExcludeFromCodeCoverage]
public LaybuyEnvironment Environment
{
get { return _Environment; }
set
{
if (_Environment != value)
{
_Environment = value;
_RootUri = GetRootUri();
}
}
}
/// <summary>
/// Gets or sets a <see cref="LaybuyCredentials"/> instance used to authenticate to the Laybuy API.
/// </summary>
public LaybuyCredentials Credentials { get; private set; }
/// <summary>
/// Gets or sets a function that create an <see cref="HttpClient"/> to be used to communicate with Laybuy. Can be null, in which case the system will create it's own instance.
/// </summary>
[ExcludeFromCodeCoverage]
public Func<HttpClient>? HttpClientFactory { get; set; }
/// <summary>
/// Gets or sets the default <see cref="CreateOrderRequest.Origin"/> value.
/// </summary>
/// <value>
/// The default origin.
/// </value>
/// <remarks>
/// <para>The default value is "POS".</para>
/// </remarks>
[ExcludeFromCodeCoverage]
public string? DefaultOrigin { get; set; }
/// <summary>
/// Gets or sets the default value for <see cref="StandardOriginData.Branch"/> which is applied if no origin data is specified on a <see cref="CreateOrderRequest"/>.
/// </summary>
/// <value>
/// The default branch identifier (usually name).
/// </value>
[ExcludeFromCodeCoverage]
public string? DefaultBranch { get; set; }
internal Uri RootUri
{
get { return _RootUri ?? GetRootUri(); }
}
private Uri GetRootUri()
{
if (_Environment == LaybuyEnvironment.Production)
return new Uri("https://api.laybuy.com/");
return new Uri("https://sandbox-api.laybuy.com/");
}
}
/// <summary>
/// Represents the possible environments for Laybuy.
/// </summary>
public enum LaybuyEnvironment
{
/// <summary>
/// Test environment.
/// </summary>
Sandbox = 0,
/// <summary>
/// Live/production environment.
/// </summary>
Production
}
}