+ /// Creates an [`Invoice`] for the request with the given required fields.
+ ///
+ /// Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after
+ /// calling this method in `std` builds. For `no-std` builds, a final [`Duration`] parameter
+ /// must be given, which is used to set [`Invoice::created_at`] since [`std::time::SystemTime`]
+ /// is not available.
+ ///
+ /// The caller is expected to remember the preimage of `payment_hash` in order to claim a payment
+ /// for the invoice.
+ ///
+ /// The `payment_paths` parameter is useful for maintaining the payment recipient's privacy. It
+ /// must contain one or more elements ordered from most-preferred to least-preferred, if there's
+ /// a preference. Note, however, that any privacy is lost if a public node id was used for
+ /// [`Offer::signing_pubkey`].
+ ///
+ /// Errors if the request contains unknown required features.
+ ///
+ /// [`Duration`]: core::time::Duration
+ /// [`Invoice`]: crate::offers::invoice::Invoice
+ /// [`Invoice::created_at`]: crate::offers::invoice::Invoice::created_at
+ pub fn respond_with(
+ &self, payment_paths: Vec<(BlindedPath, BlindedPayInfo)>, payment_hash: PaymentHash,
+ #[cfg(any(test, not(feature = "std")))]
+ created_at: core::time::Duration
+ ) -> Result<InvoiceBuilder, SemanticError> {
+ if self.features().requires_unknown_bits() {
+ return Err(SemanticError::UnknownRequiredFeatures);
+ }
+
+ #[cfg(all(not(test), feature = "std"))]
+ let created_at = std::time::SystemTime::now()
+ .duration_since(std::time::SystemTime::UNIX_EPOCH)
+ .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
+
+ InvoiceBuilder::for_offer(self, payment_paths, created_at, payment_hash)
+ }
+