@@ -2045,21 +2045,22 @@ where
2045
2045
/// [`send_payment`].
2046
2046
///
2047
2047
/// ```
2048
+ /// # use bitcoin::hashes::Hash;
2048
2049
/// # use lightning::events::{Event, EventsProvider};
2049
2050
/// # use lightning::types::payment::PaymentHash;
2050
- /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, RecipientOnionFields, Retry};
2051
- /// # use lightning::routing::router::RouteParameters;
2051
+ /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
2052
+ /// # use lightning::routing::router::RouteParametersConfig;
2053
+ /// # use lightning_invoice::Bolt11Invoice;
2052
2054
/// #
2053
2055
/// # fn example<T: AChannelManager>(
2054
- /// # channel_manager: T, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields ,
2055
- /// # route_params: RouteParameters, retry: Retry
2056
+ /// # channel_manager: T, invoice: &Bolt11Invoice, route_params_config: RouteParametersConfig ,
2057
+ /// # retry: Retry
2056
2058
/// # ) {
2057
2059
/// # let channel_manager = channel_manager.get_cm();
2058
- /// // let (payment_hash, recipient_onion, route_params) =
2059
- /// // payment::payment_parameters_from_invoice(&invoice);
2060
- /// let payment_id = PaymentId([42; 32]);
2061
- /// match channel_manager.send_payment(
2062
- /// payment_hash, recipient_onion, payment_id, route_params, retry
2060
+ /// # let payment_id = PaymentId([42; 32]);
2061
+ /// # let payment_hash = PaymentHash((*invoice.payment_hash()).to_byte_array());
2062
+ /// match channel_manager.pay_for_bolt11_invoice(
2063
+ /// invoice, payment_id, None, route_params_config, retry
2063
2064
/// ) {
2064
2065
/// Ok(()) => println!("Sending payment with hash {}", payment_hash),
2065
2066
/// Err(e) => println!("Failed sending payment with hash {}: {:?}", payment_hash, e),
@@ -4771,6 +4772,34 @@ where
4771
4772
self.pending_outbound_payments.test_set_payment_metadata(payment_id, new_payment_metadata);
4772
4773
}
4773
4774
4775
+ /// Pays a [`Bolt11Invoice`] associated with the `payment_id`. See [`Self::send_payment`] for more info.
4776
+ ///
4777
+ /// # Payment Id
4778
+ /// The invoice's `payment_hash().0` serves as a reliable choice for the `payment_id`.
4779
+ ///
4780
+ /// # Handling Invoice Amounts
4781
+ /// Some invoices include a specific amount, while others require you to specify one.
4782
+ /// - If the invoice **includes** an amount, user must not provide `amount_msats`.
4783
+ /// - If the invoice **doesn't include** an amount, you'll need to specify `amount_msats`.
4784
+ ///
4785
+ /// If these conditions aren’t met, the function will return [`RetryableSendFailure::InvalidAmount`].
4786
+ ///
4787
+ /// # Custom Routing Parameters
4788
+ /// Users can customize routing parameters via [`RouteParametersConfig`].
4789
+ /// To use default settings, call the function with `RouteParametersConfig::default()`.
4790
+ pub fn pay_for_bolt11_invoice(
4791
+ &self, invoice: &Bolt11Invoice, payment_id: PaymentId, amount_msats: Option<u64>,
4792
+ route_params_config: RouteParametersConfig, retry_strategy: Retry
4793
+ ) -> Result<(), RetryableSendFailure> {
4794
+ let best_block_height = self.best_block.read().unwrap().height;
4795
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4796
+ self.pending_outbound_payments
4797
+ .pay_for_bolt11_invoice(invoice, payment_id, amount_msats, route_params_config, retry_strategy,
4798
+ &self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4799
+ &self.entropy_source, &self.node_signer, best_block_height, &self.logger,
4800
+ &self.pending_events, |args| self.send_payment_along_path(args))
4801
+ }
4802
+
4774
4803
/// Pays the [`Bolt12Invoice`] associated with the `payment_id` encoded in its `payer_metadata`.
4775
4804
///
4776
4805
/// The invoice's `payer_metadata` is used to authenticate that the invoice was indeed requested
0 commit comments