Java client for the Lightning Charge REST API
I'm working on it...
- Clone and build, skipping tests.
git clone https://github.com/rodolfoguinez/lightning-charge-client-java.git cd lightning-charge-client-java mvn clean package -Dmaven.test.skip=true
- Then add
target/lightning-charge-client-1.0.jar
to your project.
Create a handler for the payments received. Then create the client library object, providing the host
, port
, user
and password
of your Lightning Charge, and the payment handler.
PaymentEventHandler paymentEventHandler = (Invoice invoice) -> {
// Here you can handle your received payment
System.out.println("New payment received: " + invoice.getId());
};
String host = "http://localhost";
String port = "9112";
String user = "api-token";
String password = "xxxxx";
LightningChargeClient lightningClient = new LightningChargeClient(host, port, user, password, paymentEventHandler);
If you want, you can set a Log4j Logger to the client
Logger logger = LogManager.getLogger("LighningChargeClient");
lightningClient.setLogger(logger);
-
Getting the server info
Info info = lightningClient.getInfo(); System.out.println(info.getId() + ", " + info.getPort() + ", " + info.getVersion());
-
Send a empty invoice
Invoice invoice = lightningClient.postEmptyInvoice(); System.out.println("Empty invoice created with id: " + invoice.getId());
-
Send a $10 USD invoice
Invoice invoice = new Invoice(); invoice.setCurrency("USD"); invoice.setAmount("10"); invoice = lightningClient.postInvoice(invoice); System.out.println("Invoice created with id: " + invoice.getId());
-
Send a 10 Satoshi invoice
Invoice invoice = new Invoice(); invoice.setMsatoshi("10000"); // 10.000 msatoshi = 10 satoshi invoice = lightningClient.postInvoice(invoice); System.out.println("Invoice created with id: " + invoice.getId());
-
Get a specific invoice
Invoice invoice = lightningClient.getInvoice(id); System.out.println("Status of invoice id " + id + ": " + invoice.getStatus());
-
Get all the invoices
List<Invoice> invoiceList = lightningClient.getInvoiceList(); //...
As I said before, you have to implement the PaymentEventHandler
interface, and pass it to LightningChargeClient
constructor.
To do this, you can create a new class that implements PaymentEventHandler
, or you can use lambda and make it easier.
PaymentEventHandler paymentEventHandler = (Invoice invoice) -> {
// Here you can handle your received payment
System.out.println("New payment received: " + invoice.getId());
};
LightningChargeClient lightningClient = new LightningChargeClient(host, port, user, password, paymentEventHandler);
The MIT License (MIT)
Copyright (c) 2018 Rodolfo Guíñez Espinoza
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.