Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NeuroAccessLink.cs
5using Waher.Script;
7
9{
14 {
19 {
20 }
21
27 public Grade Supports(Uri Link)
28 {
29 return Link.Scheme.Equals(Constants.UriSchemes.NeuroAccess, StringComparison.OrdinalIgnoreCase) ? Grade.Ok : Grade.NotAtAll;
30 }
31
38 public Task<bool> TryOpenLink(Uri Link, bool ShowErrorIfUnable)
39 {
40 string? Token = Constants.UriSchemes.RemoveScheme(Link.OriginalString);
41 if (string.IsNullOrEmpty(Token))
42 return Task.FromResult(false);
43
44 JwtToken? Parsed = ServiceRef.CryptoService.ParseAndValidateJwtToken(Token);
45 if (Parsed is null)
46 return Task.FromResult(false);
47
48 if (!Parsed.TryGetClaim("cmd", out object Obj) || Obj is not string Command ||
49 !Parsed.TryGetClaim(JwtClaims.ClientId, out Obj) || Obj is not string ClientId ||
50 ClientId != ServiceRef.CryptoService.DeviceID ||
51 !Parsed.TryGetClaim(JwtClaims.Issuer, out Obj) || Obj is not string Issuer ||
52 Issuer != ServiceRef.CryptoService.DeviceID ||
53 !Parsed.TryGetClaim(JwtClaims.Subject, out Obj) || Obj is not string Subject ||
54 Subject != ServiceRef.XmppService.BareJid)
55 {
56 return Task.FromResult(false);
57 }
58
59 switch (Command)
60 {
61 case "bes": // Buy eDaler Successful
62 if (!Parsed.TryGetClaim("tid", out Obj) || Obj is not string TransactionId ||
63 !Parsed.TryGetClaim("amt", out object Amount) ||
64 !Parsed.TryGetClaim("cur", out Obj) || Obj is not string Currency)
65 {
66 return Task.FromResult(false);
67 }
68
69 decimal AmountDec;
70
71 try
72 {
73 AmountDec = Expression.ToDecimal(Amount);
74 }
75 catch (Exception)
76 {
77 return Task.FromResult(false);
78 }
79
80 ServiceRef.XmppService.BuyEDalerCompleted(TransactionId, AmountDec, Currency);
81 return Task.FromResult(true);
82
83 case "bef": // Buy eDaler Failed
84 if (!Parsed.TryGetClaim("tid", out Obj) || Obj is not string TransactionId2)
85 return Task.FromResult(false);
86
87 ServiceRef.XmppService.BuyEDalerFailed(TransactionId2, ServiceRef.Localizer[nameof(AppResources.PaymentFailed)]);
88 return Task.FromResult(true);
89
90 case "bec": // Buy eDaler Cancelled
91 if (!Parsed.TryGetClaim("tid", out Obj) || Obj is not string TransactionId3)
92 return Task.FromResult(false);
93
94 ServiceRef.XmppService.BuyEDalerFailed(TransactionId3, ServiceRef.Localizer[nameof(AppResources.PaymentCancelled)]);
95 return Task.FromResult(true);
96
97 case "ses": // Sell eDaler Successful
98 if (!Parsed.TryGetClaim("tid", out Obj) || Obj is not string TransactionId4 ||
99 !Parsed.TryGetClaim("amt", out Amount) ||
100 !Parsed.TryGetClaim("cur", out Obj) || Obj is not string Currency4)
101 {
102 return Task.FromResult(false);
103 }
104
105 try
106 {
107 AmountDec = Expression.ToDecimal(Amount);
108 }
109 catch (Exception)
110 {
111 return Task.FromResult(false);
112 }
113
114 ServiceRef.XmppService.SellEDalerCompleted(TransactionId4, AmountDec, Currency4);
115 return Task.FromResult(true);
116
117 case "sef": // Sell eDaler Failed
118 if (!Parsed.TryGetClaim("tid", out Obj) || Obj is not string TransactionId5)
119 return Task.FromResult(false);
120
121 ServiceRef.XmppService.SellEDalerFailed(TransactionId5, ServiceRef.Localizer[nameof(AppResources.PaymentFailed)]);
122 return Task.FromResult(true);
123
124 case "sec": // Sell eDaler Cancelled
125 if (!Parsed.TryGetClaim("tid", out Obj) || Obj is not string TransactionId6)
126 return Task.FromResult(false);
127
128 ServiceRef.XmppService.SellEDalerFailed(TransactionId6, ServiceRef.Localizer[nameof(AppResources.PaymentCancelled)]);
129 return Task.FromResult(true);
130
131 case "beos": // Buy eDaler Get Options Successful
132 if (!Parsed.TryGetClaim("tid", out Obj) || Obj is not string TransactionId7)
133 return Task.FromResult(false);
134
135 ServiceRef.XmppService.BuyEDalerGetOptionsCompleted(TransactionId7, []);
136 return Task.FromResult(true);
137
138 case "beof": // Buy eDaler Get Options Failed
139 if (!Parsed.TryGetClaim("tid", out Obj) || Obj is not string TransactionId8)
140 return Task.FromResult(false);
141
142 ServiceRef.XmppService.BuyEDalerGetOptionsFailed(TransactionId8, ServiceRef.Localizer[nameof(AppResources.UnableToGetOptions)]);
143 return Task.FromResult(true);
144
145 case "beoc": // Buy eDaler Get Options Cancelled
146 if (!Parsed.TryGetClaim("tid", out Obj) || Obj is not string TransactionId9)
147 return Task.FromResult(false);
148
149 ServiceRef.XmppService.BuyEDalerGetOptionsFailed(TransactionId9, ServiceRef.Localizer[nameof(AppResources.GettingOptionsCancelled)]);
150 return Task.FromResult(true);
151
152 case "seos": // Sell eDaler Get Options Successful
153 if (!Parsed.TryGetClaim("tid", out Obj) || Obj is not string TransactionId10)
154 return Task.FromResult(false);
155
156 ServiceRef.XmppService.SellEDalerGetOptionsCompleted(TransactionId10, []);
157 return Task.FromResult(true);
158
159 case "seof": // Sell eDaler Get Options Failed
160 if (!Parsed.TryGetClaim("tid", out Obj) || Obj is not string TransactionId11)
161 return Task.FromResult(false);
162
163 ServiceRef.XmppService.SellEDalerGetOptionsFailed(TransactionId11, ServiceRef.Localizer[nameof(AppResources.UnableToGetOptions)]);
164 return Task.FromResult(true);
165
166 case "seoc": // Sell eDaler Get Options Cancelled
167 if (!Parsed.TryGetClaim("tid", out Obj) || Obj is not string TransactionId12)
168 return Task.FromResult(false);
169
170 ServiceRef.XmppService.SellEDalerGetOptionsFailed(TransactionId12, ServiceRef.Localizer[nameof(AppResources.GettingOptionsCancelled)]);
171 return Task.FromResult(true);
172
173 default:
174 return Task.FromResult(false);
175 }
176 }
177 }
178}
const string NeuroAccess
The App's URI Scheme (neuroaccess)
Definition: Constants.cs:94
static ? string RemoveScheme(string Url)
Removes the URI Schema from an URL.
Definition: Constants.cs:218
A set of never changing property constants and helpful values.
Definition: Constants.cs:7
Base class that references services in the app.
Definition: ServiceRef.cs:31
static ICryptoService CryptoService
Crypto service.
Definition: ServiceRef.cs:163
static IStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:235
static IXmppService XmppService
The XMPP service for XMPP communication.
Definition: ServiceRef.cs:67
Class managing a script expression.
Definition: Expression.cs:39
static decimal ToDecimal(object Object)
Converts an object to a double value.
Definition: Expression.cs:4883
Static class containing predefined JWT claim names.
Definition: JwtClaims.cs:10
const string Issuer
Issuer of the JWT
Definition: JwtClaims.cs:14
const string Subject
Subject of the JWT (the user)
Definition: JwtClaims.cs:19
const string ClientId
Client identifier
Definition: JwtClaims.cs:154
Contains information about a Java Web Token (JWT). JWT is defined in RFC 7519: https://tools....
Definition: JwtToken.cs:21
bool TryGetClaim(string Key, out object Value)
Tries to get a claim from the JWT token.
Definition: JwtToken.cs:181
Grade
Grade enumeration
Definition: Grade.cs:7