This commit is contained in:
parent
94a995d814
commit
aaa7a8ce99
10 changed files with 543 additions and 8 deletions
|
|
@ -192,6 +192,37 @@ std::vector<BankCredit> ParseBunqPayments(std::string_view json) {
|
|||
return out;
|
||||
}
|
||||
|
||||
std::optional<BankCredit> ParseBunqCallback(std::string_view json) {
|
||||
const auto doc = Json::Parse(json);
|
||||
if (!doc || !doc->IsObject()) return std::nullopt;
|
||||
const Json::Value* note = doc->Find("NotificationUrl");
|
||||
if (!note || !note->IsObject()) return std::nullopt;
|
||||
const Json::Value* object = note->Find("object");
|
||||
if (!object || !object->IsObject()) return std::nullopt;
|
||||
const Json::Value* p = object->Find("Payment");
|
||||
if (!p || !p->IsObject()) return std::nullopt;
|
||||
|
||||
const Json::Value* amount = p->Find("amount");
|
||||
if (!amount || !amount->IsObject()) return std::nullopt;
|
||||
// Only euro can pay a euro order; see ParseBunqPayments for why a
|
||||
// foreign-currency credit is skipped rather than counted at face value.
|
||||
if (amount->Str("currency") != "EUR") return std::nullopt;
|
||||
const std::optional<std::int64_t> minor =
|
||||
ParseSignedAmountToMinor(amount->Str("value"));
|
||||
if (!minor) return std::nullopt;
|
||||
|
||||
BankCredit c;
|
||||
c.id = std::format("{}", p->Int("id"));
|
||||
c.reference = std::string(p->Str("description"));
|
||||
c.amountMinor = *minor;
|
||||
c.method = std::string(BunqMethodFor(p->Str("type")));
|
||||
// An id is what deduplication rests on. A callback without one cannot be
|
||||
// deduplicated, so accepting it would let a retry credit the same money
|
||||
// twice — refuse instead.
|
||||
if (c.id.empty() || c.id == "0") return std::nullopt;
|
||||
return c;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class BunqCreditSource final : public CreditSource {
|
||||
|
|
|
|||
Loading…
Reference in a new issue