# Receiving Payments
To receive a payment, you'll need to create an invoice of your own with an
amount and description. ChannelManager
contains the remaining information
needed for the invoice. Use the provided utility to generate an invoice and
register a pending payment in ChannelManager
.
- Rust
- Java
let amt_msat = 10_000;
let description = "coffee".to_string();
let invoice = match utils::create_invoice_from_channelmanager(
&channel_manager,
keys_manager,
currency,
Some(amt_msat),
description,
).expect("ERROR: failed to create invoice");
let encoded_invoice = invoice.to_string();
While it is possible to create an invoice without using the utility,
ChannelManager
will reject any incoming HTLCs for unregistered payments to
protect your privacy. In this case, use either create_inbound_payment
or
create_inbound_payment_for_hash
to register a payment with ChannelManager
before creating the invoice with the returned payment hash and/or secret.
As with sending a payment, LDK will generate an event once a payment is
received. It is your responsibility to handle the PaymentReceived
event by
using ChannelManager
to release the preimage and claim the funds.
- Rust
- Java
// In the event handler passed to BackgroundProcessor::start
match event {
Event::PaymentReceived { payment_hash, payment_preimage, payment_secret, amt, .. } => {
let payment_hash = hex_utils::hex_str(&payment_hash.0);
match channel_manager.claim_funds(payment_preimage.unwrap()) {
true => println!("EVENT: received payment for {}", payment_hash),
false => panic!("ERROR: failed to claim payment for {}", payment_hash),
}
}
// ...
}
So there you have it! Those are the basics of using LDK. As you can see, LDK offers a ton of flexibility for building Lightning-enabled wallets and apps.