Allow selling
This commit is contained in:
@@ -60,6 +60,40 @@ namespace Controllers.Payment {
|
||||
return (false, e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public (bool, string) TrySell(string ImpodentKey, float Price) {
|
||||
// Find the impotency key
|
||||
ImpodentKey? found = null;
|
||||
foreach( ImpodentKey key in ImpodentKeys) {
|
||||
if (key.Key == ImpodentKey) {
|
||||
found = key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == null) {
|
||||
return (false, "Payment session closed or never existed");
|
||||
}
|
||||
|
||||
// Make sure the database is injected correctly
|
||||
if (_DBdriver == null) {
|
||||
found.Processed = true;
|
||||
return (false, "The Database cannot be loaded");
|
||||
}
|
||||
|
||||
// Get the users money
|
||||
string dbPrefix = $"[{found.User.ToLower()}]:";
|
||||
bool passed = float.TryParse(_DBdriver.Get( dbPrefix + "money" ), out float result);
|
||||
if (!passed) {
|
||||
found.Processed = true;
|
||||
return (false, "Unable to parse money from the database");
|
||||
}
|
||||
|
||||
// Add the money and save
|
||||
_DBdriver.Set( dbPrefix + "money", (result + Price).ToString());
|
||||
found.PaymentSuccess = true;
|
||||
found.Processed = true;
|
||||
return (true, "");
|
||||
}
|
||||
}
|
||||
|
||||
class ImpodentKey {
|
||||
|
||||
Reference in New Issue
Block a user