public interface PaymentHandler
All payment flows need a custom implementations of a payment handler persisting generated invoices and constructing orders from an order request constructed from a WebService with PaymentRequired annotation.
It is recommended to implement a class that inherits the BasePaymentHandler that takes care of most of the logic.
Created by Philip Vendil on 2018-12-04.
Modifier and Type | Method and Description |
---|---|
Settlement |
checkSettlement(byte[] preImageHash,
boolean includeInvoice)
Method to check if a given preImageHash is settled and returns a settlement value
object if invoice is settled.
|
Order |
createOrder(byte[] preImageHash,
OrderRequest orderRequest)
Method to create an order from a preImageHash and and order request.
|
LightningHandlerContext |
getLightningHandlerContext()
Method to generate the latest LightningHandlerContext of latest
known state of the lightning node.
|
void |
init()
Method that is called during the startup the application to
set up all required sub components of the PaymentHandler.
|
Invoice |
lookupInvoice(byte[] preImageHash)
Method to lookup an invoice in the PaymentHandler.
|
void |
markAsExecuted(byte[] preImageHash)
Method to flag a related payment flow is a pay per request type and has been processed successfully.
|
void |
registerListener(PaymentListener listener)
Method to add the listener to the set of listeners listening
on payment events.
|
Settlement |
registerSettledInvoice(Invoice settledInvoice,
boolean registerNew,
OrderRequest orderRequest,
LightningHandlerContext context)
Method to manually register an invoice as settled (isSettled must be set to true) used
in some payment flows instead of listening on lightningHandler events.
|
void |
unregisterListener(PaymentListener listener)
Method to remove the listener to the set of listeners listening
on payment events.
|
void init() throws InternalErrorException
InternalErrorException
- if internal error occurred setting
up the PaymentHandler.Order createOrder(byte[] preImageHash, OrderRequest orderRequest) throws java.io.IOException, InternalErrorException
preImageHash
- the unique preImageHash used to identify a payment flow
withing a lightning payment.orderRequest
- the specification of the order that should be created calculated
from data in the PaymentRequired annotation.java.io.IOException
- if communication exception occurred in underlying components.InternalErrorException
- if internal exception occurred creating the order.Invoice lookupInvoice(byte[] preImageHash) throws java.io.IOException, InternalErrorException
preImageHash
- the unique preImageHash used to identify an invoice
withing a lightning payment.java.io.IOException
- if communication exception occurred in underlying components.InternalErrorException
- if internal exception occurred looking up the invoice.Settlement checkSettlement(byte[] preImageHash, boolean includeInvoice) throws AlreadyExecutedException, java.lang.IllegalArgumentException, java.io.IOException, InternalErrorException
preImageHash
- the preImageHash of the invoice to check.includeInvoice
- if a invoice should be included in the settlement response. This might
consume more resources.AlreadyExecutedException
- if related payment is pay per request and is already executed.java.lang.IllegalArgumentException
- if related payment is per request and is already executed.java.io.IOException
- if communication exception occurred in underlying components.InternalErrorException
- if internal exception occurred looking up the settlement.Settlement registerSettledInvoice(Invoice settledInvoice, boolean registerNew, OrderRequest orderRequest, LightningHandlerContext context) throws java.lang.IllegalArgumentException, java.io.IOException, InternalErrorException
settledInvoice
- a settled invoice that should be registered in the payment handler.registerNew
- if a new payment data should be created if no prior object existed for related
preImageHash.orderRequest
- the specification of the order that should be created calculated
from data in the PaymentRequired annotation. Only used if new payment data needs to be
registered.context
- the latest known state of the lightning handler. Null if no known state exists.java.lang.IllegalArgumentException
- if settled invoices preImageHash does exists as payment data and registerNew is false.java.io.IOException
- if communication exception occurred in underlying components.InternalErrorException
- if internal exception occurred registering a settled invoice.void markAsExecuted(byte[] preImageHash) throws java.io.IOException, InternalErrorException
preImageHash
- the preImageHash of the payment to mark as processed.java.io.IOException
- if communication exception occurred in underlying components.InternalErrorException
- if internal exception occurred updating the payment or no related payment found.void registerListener(PaymentListener listener) throws InternalErrorException
listener
- the listener to register.InternalErrorException
- if internal exception occurred registering the listener.void unregisterListener(PaymentListener listener) throws InternalErrorException
listener
- the listener to un-register.InternalErrorException
- if internal exception occurred un-registering the listener.LightningHandlerContext getLightningHandlerContext() throws InternalErrorException
InternalErrorException
- if internal exception occurred fetching latest known state of lightning handler.