60 lines
2.5 KiB
C++
60 lines
2.5 KiB
C++
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
||
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
module Nostro.App:Banks_impl;
|
||
|
|
import std;
|
||
|
|
import :Banks;
|
||
|
|
|
||
|
|
using namespace Nostro::App;
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
// bunq. An API key is the user's own, and a connection made with one does whatever bunq lets its user do. A
|
||
|
|
// connection through OAuth is an app's: bunq lets it pay between the user's own accounts, and make drafts for the
|
||
|
|
// user to approve in bunq's app.
|
||
|
|
constexpr std::array<Way, 2> bunqWays = {{
|
||
|
|
{.key = "key", .auth = "api key", .title = "API key", .about = "Full access, with a key you make in the bunq app", .revoke = "The API key itself stays valid until you revoke it in the bunq app.", .form = ConnectForm::BunqKey},
|
||
|
|
{.key = "oauth", .auth = "oauth", .title = "OAuth", .about = "Limited access, for an OAuth client of your own", .revoke = "The permission itself stays valid until you revoke it in the bunq app.", .form = ConnectForm::BunqOAuth, .ownAccountsOnly = true},
|
||
|
|
}};
|
||
|
|
|
||
|
|
constexpr std::array<Bank, 1> banks = {{
|
||
|
|
{.id = "bunq", .name = "bunq", .ways = bunqWays},
|
||
|
|
}};
|
||
|
|
}
|
||
|
|
|
||
|
|
std::span<const Bank> Nostro::App::Banks() noexcept {
|
||
|
|
return banks;
|
||
|
|
}
|
||
|
|
|
||
|
|
const Bank* Nostro::App::FindBank(std::string_view id) noexcept {
|
||
|
|
const auto found = std::ranges::find(banks, id, &Bank::id);
|
||
|
|
return found != banks.end() ? &*found : nullptr;
|
||
|
|
}
|
||
|
|
|
||
|
|
const Way* Nostro::App::FindWay(std::string_view bank, std::string_view auth) noexcept {
|
||
|
|
const Bank* const known = FindBank(bank);
|
||
|
|
if(known == nullptr) {
|
||
|
|
return nullptr;
|
||
|
|
}
|
||
|
|
const auto found = std::ranges::find(known->ways, auth, &Way::auth);
|
||
|
|
return found != known->ways.end() ? &*found : nullptr;
|
||
|
|
}
|
||
|
|
|
||
|
|
std::string Nostro::App::BankName(std::string_view id) {
|
||
|
|
const Bank* const known = FindBank(id);
|
||
|
|
return std::string(known != nullptr ? known->name : id);
|
||
|
|
}
|
||
|
|
|
||
|
|
std::string Nostro::App::WayName(std::string_view bank, std::string_view auth) {
|
||
|
|
const Way* const known = FindWay(bank, auth);
|
||
|
|
return std::string(known != nullptr ? known->title : auth);
|
||
|
|
}
|
||
|
|
|
||
|
|
bool Nostro::App::OwnAccountsOnly(std::string_view bank, std::string_view auth) noexcept {
|
||
|
|
const Way* const known = FindWay(bank, auth);
|
||
|
|
return known != nullptr && known->ownAccountsOnly;
|
||
|
|
}
|
||
|
|
|
||
|
|
std::string Nostro::App::Revoking(std::string_view bank, std::string_view auth) {
|
||
|
|
const Way* const known = FindWay(bank, auth);
|
||
|
|
return std::string(known != nullptr ? known->revoke : "What it was connected with stays valid at the bank until you revoke it there.");
|
||
|
|
}
|