pub struct Invoice { /* private fields */ }Expand description
Representation of an invoice. Invoices are created by the
PaymentGateway.
Invoices have an expiration block, after which they are considered
expired. However, note that the payment gateway by default will continue
updating invoices even after expiration.
To receive updates for a given Invoice, use a
Subscriber.
Implementations§
Source§impl Invoice
impl Invoice
Sourcepub fn uri(&self) -> String
pub fn uri(&self) -> String
Returns a URI containing the address and amount due as a String. For
example:
"monero:4A1WSBQdCbUCqt3DaGfmqVFchXScF43M6c5r4B6JXT3dUwuALncU9XTEnRPmUMcB3c16kVP9Y7thFLCJ5BaMW3UmSy93w3w?tx_amount=0.001"Monero URIs can be thought of as fancy addresses that pre-fill the amount field for the user (and sometimes the description field as well). They are supported by all major wallets.
Sourcepub fn is_confirmed(&self) -> bool
pub fn is_confirmed(&self) -> bool
Returns true if the Invoice has received the required number of
confirmations.
Sourcepub fn is_paid(&self) -> bool
pub fn is_paid(&self) -> bool
Returns true if the Invoice has been paid in full (regadless of
whether all required confirmations have been received).
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Returns true if the Invoice’s current block is greater than or equal
to its expiration block.
Sourcepub fn index(&self) -> SubIndex
pub fn index(&self) -> SubIndex
Returns the subaddress index of this Invoice.
Sourcepub fn creation_height(&self) -> u64
pub fn creation_height(&self) -> u64
Returns the blockchain height at which the Invoice was created.
Sourcepub fn amount_requested(&self) -> u64
pub fn amount_requested(&self) -> u64
Returns the amount of monero requested in piconeros.
Sourcepub fn amount_paid(&self) -> u64
pub fn amount_paid(&self) -> u64
Returns the amount of monero paid in piconeros.
Sourcepub fn xmr_requested(&self) -> f64
pub fn xmr_requested(&self) -> f64
Returns the amount of monero requested in XMR.
Note that rounding may occur because the precision of f64 is
insufficient for representing large amounts of XMR out to many decimal
places. If accuracy is desired,
amount_requested() should be preferred.
§Examples
// Create a new `Invoice` for 1 millinero.
let invoice_id = payment_gateway.new_invoice(1_000_000_000, 3, 5, "for pizza".to_string()).await?;
let small_invoice = payment_gateway.get_invoice(invoice_id).await?.expect("invoice ID not found");
// One millinero, as expected.
assert_eq!(small_invoice.xmr_requested(), 0.001);
// Create a new `Invoice` for 18446744.073709551615 XMR.
let invoice_id = payment_gateway.new_invoice(18_446_744_073_709_551_615, 3, 5, "for lambo".to_string()).await?;
let large_invoice = payment_gateway.get_invoice(invoice_id).await?.expect("invoice ID not found");
// The large value has been rounded slightly due to f64 precision limitations.
assert_eq!(large_invoice.xmr_requested(), 18446744.07370955);Sourcepub fn xmr_paid(&self) -> f64
pub fn xmr_paid(&self) -> f64
Returns the amount of monero paid in XMR.
Note that rounding may occur because the precision of f64 is
insufficient for representing large amounts of XMR out to many decimal
places. If accuracy is desired, amount_paid()
should be preferred.
For an example of possible rounding error, see
xmr_requested()
Sourcepub fn confirmations_required(&self) -> u64
pub fn confirmations_required(&self) -> u64
Returns the number of confirmations this Invoice requires before it is
considered fully confirmed.
Sourcepub fn confirmations(&self) -> Option<u64>
pub fn confirmations(&self) -> Option<u64>
Returns the number of confirmations this Invoice has received since it
was paid in full. Returns None if the Invoice has not yet been paid
in full.
Sourcepub fn current_height(&self) -> u64
pub fn current_height(&self) -> u64
Returns the last daemon height at which this Invoice was updated.
Returns 0 if the Invoice has not yet been updated.
Sourcepub fn expiration_height(&self) -> u64
pub fn expiration_height(&self) -> u64
Returns the daemon height at which this Invoice will expire.
Sourcepub fn expiration_in(&self) -> u64
pub fn expiration_in(&self) -> u64
Returns the number of blocks before expiration.
§Examples
// Create a new `Invoice` requiring 3 confirmations, and expiring in 5 blocks.
let invoice_id = payment_gateway.new_invoice(10000, 3, 5, "for pizza".to_string()).await?;
let mut subscriber = payment_gateway.subscribe(invoice_id).expect("invoice ID not found");
let invoice = subscriber.recv().await.expect("invoice update not received");
assert_eq!(invoice.expiration_in(), 5);Sourcepub fn description(&self) -> &str
pub fn description(&self) -> &str
Returns the description of this invoice.
Trait Implementations§
Source§impl<'__de, __Context> BorrowDecode<'__de, __Context> for Invoice
impl<'__de, __Context> BorrowDecode<'__de, __Context> for Invoice
Source§fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Source§impl<'de> Deserialize<'de> for Invoice
impl<'de> Deserialize<'de> for Invoice
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for Invoice
This custom PartialEq implementation is necessary so that the order of
Transfers can be ignored while comparing Invoices.
impl PartialEq for Invoice
This custom PartialEq implementation is necessary so that the order of
Transfers can be ignored while comparing Invoices.
impl Eq for Invoice
Auto Trait Implementations§
impl Freeze for Invoice
impl RefUnwindSafe for Invoice
impl Send for Invoice
impl Sync for Invoice
impl Unpin for Invoice
impl UnwindSafe for Invoice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more