pub struct PaymentRequest {
pub payment_id: Option<String>,
pub amount: Option<Amount>,
pub unit: Option<CurrencyUnit>,
pub single_use: Option<bool>,
pub mints: Vec<MintUrl>,
pub mint_preferred: Option<bool>,
pub supported_methods: Vec<SupportedMethod>,
pub description: Option<String>,
pub transports: Vec<Transport>,
pub nut10: Option<Nut10SecretRequest>,
}Expand description
NUT-18 payment request.
A receiver creates this request to tell a payer how much to send, which
mints and payment methods are acceptable, and which transports can deliver
the resulting PaymentRequestPayload.
Fields§
§payment_id: Option<String>Payment id to include in the payment payload.
amount: Option<Amount>Requested amount net of input fees.
If this is set, Self::unit must also be set.
unit: Option<CurrencyUnit>Unit of the requested amount.
single_use: Option<bool>Whether this request is intended for a single payment.
mints: Vec<MintUrl>Mint URLs the receiver accepts or prefers.
If non-empty and Self::mint_preferred is omitted or false, this
list is strict and the payer must only send proofs from these mints. If
Self::mint_preferred is true, this list is advisory and other
mints may be used.
mint_preferred: Option<bool>Whether Self::mints is preferred instead of strict.
true means the payer should prefer the listed mints but may send from
others. false or omitted means the mint list is strict. Ignored when
Self::mints is empty.
supported_methods: Vec<SupportedMethod>Payment methods the payer’s mint must support.
If non-empty, the payer must send ecash from a mint that supports at least one listed method. Each method can carry a fee that only applies to payments from non-preferred mints, or from any mint if no mint list is set.
description: Option<String>Human-readable description for the payer to display.
transports: Vec<Transport>Transports for delivering the payment payload, sorted by preference.
An empty list means the payment is expected to be delivered in-band by the surrounding protocol.
nut10: Option<Nut10SecretRequest>Optional NUT-10 locking condition requested for the payment proofs.
Implementations§
Source§impl PaymentRequest
impl PaymentRequest
Sourcepub fn builder() -> PaymentRequestBuilder
pub fn builder() -> PaymentRequestBuilder
Create a new PaymentRequestBuilder
Source§impl PaymentRequest
CREQ-B encoding and decoding implementation
impl PaymentRequest
CREQ-B encoding and decoding implementation
Sourcepub fn to_bech32_string(&self) -> Result<String, Error>
pub fn to_bech32_string(&self) -> Result<String, Error>
Encodes a payment request to CREQB1 bech32m format.
This function serializes a payment request according to the NUT-26 specification and encodes it using the bech32m encoding scheme with the “creqb” human-readable part (HRP). The output is always uppercase for optimal QR code compatibility.
§Returns
Returns a Result containing:
Ok(String)- The bech32m-encoded payment request string in uppercaseErr(Error)- If serialization or encoding fails
§Errors
This function will return an error if:
- The payment request cannot be serialized to TLV format
- The bech32m encoding process fails
§Specification
See NUT-26 for the complete specification of the CREQB1 payment request format.
§Examples
use std::str::FromStr;
use cashu::nuts::nut18::PaymentRequest;
use cashu::{Amount, MintUrl};
let payment_request = PaymentRequest {
payment_id: Some("test123".to_string()),
amount: Some(Amount::from(1000)),
unit: Some(cashu::nuts::CurrencyUnit::Sat),
single_use: None,
mints: vec![MintUrl::from_str("https://mint.example.com")?],
mint_preferred: None,
supported_methods: vec![],
description: None,
transports: vec![],
nut10: None,
};
let encoded = payment_request.to_bech32_string()?;
assert!(encoded.starts_with("CREQB1"));Sourcepub fn from_bech32_string(s: &str) -> Result<PaymentRequest, Error>
pub fn from_bech32_string(s: &str) -> Result<PaymentRequest, Error>
Decodes a payment request from CREQB1 bech32m format.
This function takes a bech32m-encoded payment request string (case-insensitive) with the “creqb” human-readable part and deserializes it back into a payment request according to the NUT-26 specification.
§Arguments
s- The bech32m-encoded payment request string (case-insensitive)
§Returns
Returns a Result containing:
Ok(PaymentRequest)- The decoded payment requestErr(Error)- If decoding or deserialization fails
§Errors
This function will return an error if:
- The input string is not valid bech32m encoding
- The human-readable part is not “creqb” (case-insensitive)
- The decoded data cannot be deserialized into a valid payment request
- The TLV structure is malformed
§Specification
See NUT-26 for the complete specification of the CREQB1 payment request format.
§Examples
use cashu::nuts::nut18::PaymentRequest;
let encoded = "CREQB1QYQQWAR9WD6RZV3NQ5QPS6R5W3C8XW309AKKJMN59EJHSCTDWPKX2TNRDAKS4U8XXF";
let payment_request = PaymentRequest::from_bech32_string(encoded)?;
assert_eq!(payment_request.payment_id, Some("test123".to_string()));Trait Implementations§
Source§impl Clone for PaymentRequest
impl Clone for PaymentRequest
Source§fn clone(&self) -> PaymentRequest
fn clone(&self) -> PaymentRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more