-
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathPaymentProviderConfig.cs
More file actions
175 lines (147 loc) · 4.99 KB
/
Copy pathPaymentProviderConfig.cs
File metadata and controls
175 lines (147 loc) · 4.99 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
using System;
using System.Text.RegularExpressions;
namespace Resgrid.Config
{
public static class PaymentProviderConfig
{
private static readonly Regex PaddleClientTokenRegex = new Regex("^(test|live)_[a-zA-Z0-9]{27}$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
#if DEBUG
public static bool IsTestMode = true;
#else
public static bool IsTestMode = false;
#endif
public static string ProductionApiKey = "";
public static string TestApiKey = "";
public static string ProductionClientKey = "";
public static string TestClientKey = "";
public static string ProductionWebhookSigningKey = "";
public static string TestWebhookSigningKey = "";
public static string ProductionBillingWebhookSigningKey = "";
public static string TestBillingWebhookSigningKey = "";
public static string PTT10UserAddonPackage = "6f4c5f8b-584d-4291-8a7d-29bf97ae6aa9";
public static string PTT10UserAddonPackageTest = "6f4c5f8b-584d-4291-8a7d-29bf97ae6aa9";
public static string TenEntityPackage = "6f4c5f8b-584d-4291-8a7d-29bf97ae6aa9";
public static string TenEntityPackageTest = "6f4c5f8b-584d-4291-8a7d-29bf97ae6aa9";
public static string PaddleProductionApiKey = "";
public static string PaddleTestApiKey = "";
public static string PaddleProductionBillingWebhookSigningKey = "";
public static string PaddleTestBillingWebhookSigningKey = "";
public static string PaddlePTT10UserAddonPackage = "";
public static string PaddlePTT10UserAddonPackageTest = "";
public static string PaddleProductionEnvironment = "production";
public static string PaddleTestEnvironment = "sandbox";
public static string PaddleProductionClientToken = "";
public static string PaddleTestClientToken = "";
// Global toggle: 1 = Stripe (default), 7 = Paddle. Matches PaymentMethods enum values.
// Set per-instance via ResgridConfig.json: "PaymentProviderConfig.ActivePaymentProvider": "7"
public static int ActivePaymentProvider = 1;
public const int ProviderStripe = 1;
public const int ProviderPaddle = 7;
public static int GetActivePaymentProvider()
{
if (ActivePaymentProvider != ProviderStripe && ActivePaymentProvider != ProviderPaddle)
throw new InvalidOperationException(
$"Unsupported ActivePaymentProvider value '{ActivePaymentProvider}'. Expected {ProviderStripe} (Stripe) or {ProviderPaddle} (Paddle).");
return ActivePaymentProvider;
}
public static bool IsStripeActive()
{
return GetActivePaymentProvider() == ProviderStripe;
}
public static bool IsPaddleActive()
{
return GetActivePaymentProvider() == ProviderPaddle;
}
public static string GetStripeClientKey()
{
if (IsTestMode)
return TestClientKey;
else
return ProductionClientKey;
}
public static string GetStripeApiKey()
{
if (IsTestMode)
return TestApiKey;
else
return ProductionApiKey;
}
public static string GetStripeWebhookSigningKey()
{
if (IsTestMode)
return TestWebhookSigningKey;
else
return ProductionWebhookSigningKey;
}
public static string GetStripeBillingWebhookSigningKey()
{
if (IsTestMode)
return TestBillingWebhookSigningKey;
else
return ProductionBillingWebhookSigningKey;
}
public static string GetPTT10UserAddonPackageId()
{
if (IsTestMode)
return PTT10UserAddonPackageTest;
else
return PTT10UserAddonPackage;
}
public static string GetTenEntityPackageId()
{
if (IsTestMode)
return TenEntityPackageTest;
else
return TenEntityPackage;
}
public static string GetPaddleApiKey()
{
if (IsTestMode)
return PaddleTestApiKey;
else
return PaddleProductionApiKey;
}
public static string GetPaddleBillingWebhookSigningKey()
{
if (IsTestMode)
return PaddleTestBillingWebhookSigningKey;
else
return PaddleProductionBillingWebhookSigningKey;
}
public static string GetPaddlePTT10UserAddonPackageId()
{
if (IsTestMode)
return PaddlePTT10UserAddonPackageTest;
else
return PaddlePTT10UserAddonPackage;
}
public static string GetPaddleEnvironment()
{
if (IsTestMode)
return NormalizeConfigValue(PaddleTestEnvironment).ToLowerInvariant();
else
return NormalizeConfigValue(PaddleProductionEnvironment).ToLowerInvariant();
}
public static string GetPaddleClientToken()
{
if (IsTestMode)
return NormalizeConfigValue(PaddleTestClientToken);
else
return NormalizeConfigValue(PaddleProductionClientToken);
}
public static bool IsValidPaddleEnvironment(string environment)
{
var normalizedEnvironment = NormalizeConfigValue(environment).ToLowerInvariant();
return normalizedEnvironment == "sandbox" || normalizedEnvironment == "production";
}
public static bool IsValidPaddleClientToken(string token)
{
var normalizedToken = NormalizeConfigValue(token);
return !string.IsNullOrWhiteSpace(normalizedToken) && PaddleClientTokenRegex.IsMatch(normalizedToken);
}
private static string NormalizeConfigValue(string value)
{
return string.IsNullOrWhiteSpace(value) ? string.Empty : value.Trim();
}
}
}