commit 1e3783301f34379c6c9fde3f86111534ebcde8d3
parent 1dac9a6c47ee1e023087cfb6bff2946011bd42d3
Author: Antoine A <>
Date: Fri, 4 Apr 2025 11:17:11 +0200
common: improve payto API
Diffstat:
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -1339,9 +1339,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "miniz_oxide"
-version = "0.8.5"
+version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5"
+checksum = "ff70ce3e48ae43fa075863cef62e8b43b71a4f2382229920e0df362592919430"
dependencies = [
"adler2",
]
diff --git a/common/taler-common/src/types/payto.rs b/common/taler-common/src/types/payto.rs
@@ -36,7 +36,7 @@ pub fn payto(url: impl AsRef<str>) -> PaytoURI {
pub trait PaytoImpl: Sized {
fn as_payto(&self) -> PaytoURI;
fn as_full_payto(&self, name: &str) -> PaytoURI {
- self.as_payto().with_query([("receiver-name", name)])
+ self.as_payto().as_full_payto(name)
}
fn as_transfer_payto(
&self,
@@ -44,9 +44,7 @@ pub trait PaytoImpl: Sized {
amount: Option<&Amount>,
subject: Option<&str>,
) -> PaytoURI {
- self.as_full_payto(name)
- .with_query([("amount", amount)])
- .with_query([("message", subject)])
+ self.as_payto().as_transfer_payto(name, amount, subject)
}
fn parse(uri: &PaytoURI) -> Result<Self, PaytoErr>;
}
@@ -66,6 +64,21 @@ impl PaytoURI {
payto(format!("payto://{domain}{path}"))
}
+ pub fn as_full_payto(self, name: &str) -> PaytoURI {
+ self.with_query([("receiver-name", name)])
+ }
+
+ pub fn as_transfer_payto(
+ self,
+ name: &str,
+ amount: Option<&Amount>,
+ subject: Option<&str>,
+ ) -> PaytoURI {
+ self.as_full_payto(name)
+ .with_query([("amount", amount)])
+ .with_query([("message", subject)])
+ }
+
fn query<Q: DeserializeOwned>(&self) -> Result<Q, PaytoErr> {
let query = self.0.query().unwrap_or_default().as_bytes();
let de = serde_urlencoded::Deserializer::new(url::form_urlencoded::parse(query));