2using System.Collections.Generic;
4using System.Threading.Tasks;
18 private static readonly Dictionary<string, KeyValuePair<IBuyEDalerService[], DateTime>> buyEDalerServices =
19 new Dictionary<string, KeyValuePair<IBuyEDalerService[], DateTime>>();
20 private static readonly Dictionary<string, KeyValuePair<ISellEDalerService[], DateTime>> sellEDalerServices =
21 new Dictionary<string, KeyValuePair<ISellEDalerService[], DateTime>>();
50 return Task.CompletedTask;
58 return Task.CompletedTask;
69 new ConfigurablePage(
"Paiwise",
"/Settings/Paiwise.md",
"Admin.Payments.Paiwise")
76 public string Id =>
"paiwise";
81 public string Name =>
"Paiwise";
106 string Key = Currency.
Value.ToUpper() +
" " + Country.
Value.ToUpper();
108 lock (buyEDalerServices)
110 if (buyEDalerServices.TryGetValue(Key, out KeyValuePair<
IBuyEDalerService[], DateTime> P) &&
111 P.Value.Subtract(DateTime.UtcNow).TotalHours < 1)
118 if (
string.IsNullOrEmpty(Host))
122 if (
string.IsNullOrEmpty(Token))
125 StringBuilder Url =
new StringBuilder();
127 Url.Append(
"https://");
129 Url.Append(
"/payment/available-buy-payment-method");
131 Dictionary<string, object> Request =
new Dictionary<string, object>()
133 {
"currency", Currency.Value },
134 {
"country", Country.Value }
138 new KeyValuePair<string, string>(
"Authorization",
"Bearer " + Token),
141 if (!(Obj is Array Services))
144 List<IBuyEDalerService> Result =
new List<IBuyEDalerService>();
146 foreach (
object Obj2
in Services)
148 if (!(Obj2 is Dictionary<string, object> Service &&
149 Service.TryGetValue(
"id", out Obj) && Obj is
string Id &&
150 Service.TryGetValue(
"displayName", out Obj) && Obj is
string DisplayName &&
151 Service.TryGetValue(
"logo", out Obj) && Obj is Dictionary<string, object> Logo &&
152 Logo.TryGetValue(
"url", out Obj) && Obj is
string LogoUrl &&
153 Logo.TryGetValue(
"width", out Obj) && Obj is
int LogoWidth &&
154 Logo.TryGetValue(
"height", out Obj) && Obj is
int LogoHeight &&
155 Service.TryGetValue(
"contractId", out
object ContractId) &&
156 Service.TryGetValue(
"fields", out Obj) && Obj is Array Fields &&
157 Service.TryGetValue(
"endpoint", out Obj) && Obj is Dictionary<string, object> Endpoint &&
158 Endpoint.TryGetValue(
"method", out Obj) && Obj is
string Method &&
159 string.Compare(Method,
"POST",
true) == 0 &&
160 Endpoint.TryGetValue(
"url", out Obj) && Obj is
string ServiceUrl))
165 if (!Endpoint.TryGetValue(
"optionsUrl", out Obj) || !(Obj is
string OptionsUrl))
168 List<ServiceField> ServiceFields =
new List<ServiceField>();
170 foreach (
object Obj3
in Fields)
172 if (!(Obj3 is Dictionary<string, object> Field &&
173 Field.TryGetValue(
"field", out Obj) && Obj is
string FieldId &&
174 Field.TryGetValue(
"dataType", out Obj) && Obj is
string DataType &&
175 Field.TryGetValue(
"required", out Obj) && Obj is
bool Required))
180 ServiceFields.Add(
new ServiceField(FieldId, DataType, Required));
184 ContractId?.
ToString(), Method, ServiceUrl, OptionsUrl, ServiceFields.ToArray(), Host,
this));
189 lock (buyEDalerServices)
191 buyEDalerServices[Key] =
new KeyValuePair<IBuyEDalerService[], DateTime>(Result2, DateTime.UtcNow);
208 if (Service.
Id == ServiceId)
224 List<IPaymentService> Result =
new List<IPaymentService>();
229 Result.Add(PaymentService);
232 return Result.ToArray();
246 return PaymentService;
259 string Key = Currency.
Value.ToUpper() +
" " + Country.
Value.ToUpper();
261 lock (sellEDalerServices)
263 if (sellEDalerServices.TryGetValue(Key, out KeyValuePair<
ISellEDalerService[], DateTime> P) &&
264 P.Value.Subtract(DateTime.UtcNow).TotalHours < 1)
271 if (
string.IsNullOrEmpty(Host))
275 if (
string.IsNullOrEmpty(Token))
278 StringBuilder Url =
new StringBuilder();
280 Url.Append(
"https://");
282 Url.Append(
"/payout/available-sell-payment-method");
284 Dictionary<string, object> Request =
new Dictionary<string, object>()
286 {
"currency", Currency.Value },
287 {
"country", Country.Value }
291 new KeyValuePair<string, string>(
"Authorization",
"Bearer " + Token),
294 if (!(Obj is Array Services))
297 List<ISellEDalerService> Result =
new List<ISellEDalerService>();
299 foreach (
object Obj2
in Services)
301 if (!(Obj2 is Dictionary<string, object> Service &&
302 Service.TryGetValue(
"id", out Obj) && Obj is
string Id &&
303 Service.TryGetValue(
"displayName", out Obj) && Obj is
string DisplayName &&
304 Service.TryGetValue(
"logo", out Obj) && Obj is Dictionary<string, object> Logo &&
305 Logo.TryGetValue(
"url", out Obj) && Obj is
string LogoUrl &&
306 Logo.TryGetValue(
"width", out Obj) && Obj is
int LogoWidth &&
307 Logo.TryGetValue(
"height", out Obj) && Obj is
int LogoHeight &&
308 Service.TryGetValue(
"contractId", out
object ContractId) &&
309 Service.TryGetValue(
"fields", out Obj) && Obj is Array Fields &&
310 Service.TryGetValue(
"endpoint", out Obj) && Obj is Dictionary<string, object> Endpoint &&
311 Endpoint.TryGetValue(
"method", out Obj) && Obj is
string Method &&
312 string.Compare(Method,
"POST",
true) == 0 &&
313 Endpoint.TryGetValue(
"url", out Obj) && Obj is
string ServiceUrl))
318 if (!Endpoint.TryGetValue(
"optionsUrl", out Obj) || !(Obj is
string OptionsUrl))
321 List<ServiceField> ServiceFields =
new List<ServiceField>();
323 foreach (
object Obj3
in Fields)
325 if (!(Obj3 is Dictionary<string, object> Field &&
326 Field.TryGetValue(
"field", out Obj) && Obj is
string FieldId &&
327 Field.TryGetValue(
"dataType", out Obj) && Obj is
string DataType &&
328 Field.TryGetValue(
"required", out Obj) && Obj is
bool Required))
333 ServiceFields.Add(
new ServiceField(FieldId, DataType, Required));
337 ContractId?.
ToString(), Method, ServiceUrl, OptionsUrl, ServiceFields.ToArray(), Host,
this));
342 lock (sellEDalerServices)
344 sellEDalerServices[Key] =
new KeyValuePair<ISellEDalerService[], DateTime>(Result2, DateTime.UtcNow);
361 if (Service.
Id == ServiceId)
Reference to a Paiwise payment service.
bool CanBeUsedForPayment
If service can be used for payments.
Payment services made available by Paiwise.
string Name
Displayable name of service provider.
async Task< IBuyEDalerService[]> GetServicesForBuyingEDaler(CaseInsensitiveString Currency, CaseInsensitiveString Country)
Gets available payment services for buying eDaler.
Task< IConfigurablePage[]> GetConfigurablePages()
Gets an array of configurable pages for the module.
async Task< IPaymentService > GetServiceForPayment(string ServiceId, CaseInsensitiveString Currency, CaseInsensitiveString Country)
Gets a payment service.
int IconWidth
Width of icon, if available.
async Task< IPaymentService[]> GetServicesForPayment(CaseInsensitiveString Currency, CaseInsensitiveString Country)
Gets available payment services.
const string TimeoutMinutesSetting
Settings key for Paiwise timeout, in minutes.
async Task< ISellEDalerService > GetServiceForSellingEDaler(string ServiceId, CaseInsensitiveString Currency, CaseInsensitiveString Country)
Gets a payment service for selling eDaler.
PaiwisePaymentServices()
Payment services made available by Paiwise.
async Task< ISellEDalerService[]> GetServicesForSellingEDaler(CaseInsensitiveString Currency, CaseInsensitiveString Country)
Gets available payment services for seller eDaler.
int IconHeight
Height of icon, if available.
string Id
ID of service provider.
string IconUrl
Optional URL to icon of service provider.
const string TokenIdSetting
Settings key for Paiwise token.
Task Stop()
Stops the module.
const string HostSetting
Settings key for Paiwise host name.
Task Start()
Starts the module.
async Task< IBuyEDalerService > GetServiceForBuyingEDaler(string ServiceId, CaseInsensitiveString Currency, CaseInsensitiveString Country)
Gets a payment service for buying eDaler.
Reference to a Paiwise payment service.
Represents a field in a service.
Static class managing encoding and decoding of internet content.
static Task< object > PostAsync(Uri Uri, object Data, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
const string DefaultContentType
application/json
Configuration page for a configurable module.
Static class managing the runtime environment of the IoT Gateway.
static X509Certificate2 Certificate
Domain certificate.
static string GetUrl(string LocalResource)
Gets a URL for a resource.
Represents a case-insensitive string.
string Value
String-representation of the case-insensitive string. (Representation is case sensitive....
Static class managing persistent settings.
static async Task< string > GetAsync(string Key, string DefaultValue)
Gets a string-valued setting.
Interface for information about a service provider that users can use to buy eDaler.
Interface for information about a service provider that users can use to buy eDaler.
Interface for information about a service provider that users can use to pay for services.
Interface for information about a service provider that users can use to sell eDaler.
Interface for information about a service provider that users can use to sell eDaler.
string Id
ID of service provider.
Interface for configurable modules.
Configuration page for a configurable module.
delegate string ToString(IElement Element)
Delegate for callback methods that convert an element value to a string.