67 lines
2.1 KiB
Text
67 lines
2.1 KiB
Text
|
|
//SPDX-License-Identifier: LGPL-3.0-only
|
||
|
|
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
module;
|
||
|
|
|
||
|
|
#ifdef NOSTRO_BUNQ_ENABLED
|
||
|
|
#include "../lib/json.hpp"
|
||
|
|
#include <openssl/types.h>
|
||
|
|
#endif
|
||
|
|
|
||
|
|
export module Nostro:Bunq;
|
||
|
|
#ifdef NOSTRO_BUNQ_ENABLED
|
||
|
|
|
||
|
|
import std;
|
||
|
|
import Crafter.Network;
|
||
|
|
import :Account;
|
||
|
|
import :Currency;
|
||
|
|
import :Transaction;
|
||
|
|
|
||
|
|
using namespace Crafter;
|
||
|
|
|
||
|
|
namespace Nostro {
|
||
|
|
export struct BunqConnector;
|
||
|
|
|
||
|
|
export struct BunqAccount : public Account {
|
||
|
|
std::uint32_t id;
|
||
|
|
BunqConnector* connector;
|
||
|
|
|
||
|
|
BunqAccount(std::string&& name, std::string&& bic, std::string&& iban, Currency currency, std::int64_t balance, std::uint32_t id, BunqConnector* connector);
|
||
|
|
void Send(std::string_view iban, std::string_view name, std::int64_t amount, Currency currency) const;
|
||
|
|
void Send(std::string_view iban, std::string_view name, std::int64_t amount, Currency currency, std::string_view description) const;
|
||
|
|
private:
|
||
|
|
void SendPayment(std::string iban) const;
|
||
|
|
};
|
||
|
|
|
||
|
|
export struct BunqConnector {
|
||
|
|
std::string sessionToken;
|
||
|
|
std::string installationToken;
|
||
|
|
EVP_PKEY* privateKey;
|
||
|
|
std::string apiKey;
|
||
|
|
std::string name;
|
||
|
|
std::vector<BunqAccount> accounts;
|
||
|
|
std::uint32_t id;
|
||
|
|
|
||
|
|
void RefreshSession();
|
||
|
|
void RefreshAccounts();
|
||
|
|
bool TestConnector();
|
||
|
|
|
||
|
|
static constexpr std::string connectorId = "bunq";
|
||
|
|
inline static ClientHTTP1 client = ClientHTTP1("public-api.sandbox.bunq.com", 443, Crafter::TLSClientCredentials{});
|
||
|
|
static std::vector<BunqConnector> connectors;
|
||
|
|
static BunqConnector& Create(std::string&& apiKey, std::string_view allowedIp);
|
||
|
|
using Account = BunqAccount;
|
||
|
|
};
|
||
|
|
|
||
|
|
void to_json(nlohmann::json& j, const BunqConnector& connector);
|
||
|
|
void from_json(const nlohmann::json& j, BunqConnector& connector);
|
||
|
|
}
|
||
|
|
|
||
|
|
template<>
|
||
|
|
struct std::formatter<Nostro::BunqConnector> : std::formatter<std::string> {
|
||
|
|
auto format(const Nostro::BunqConnector& obj, std::format_context& ctx) const {
|
||
|
|
return std::formatter<std::string>::format(obj.name, ctx);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
#endif
|