public abstract class BasePaymentHandler extends java.lang.Object implements PaymentHandler, LightningEventListener
Created by Philip Vendil on 2018-12-09.
Modifier and Type | Field and Description |
---|---|
protected static java.util.logging.Logger |
log |
protected PaymentDataConverter |
paymentDataConverter |
protected PaymentEventBus |
paymentEventBus |
Constructor and Description |
---|
BasePaymentHandler()
Empty Constructor
|
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.
|
protected abstract PaymentData |
findPaymentData(byte[] preImageHash)
Method to lookup a payment data in the payment handler.
|
protected abstract java.time.Duration |
getDefaultInvoiceValidity() |
protected abstract java.time.Duration |
getDefaultSettlementValidity() |
protected abstract LightningHandler |
getLightningHandler()
Method that should returned the used LightningHandler.
|
LightningHandlerContext |
getLightningHandlerContext()
Method to generate the latest LNDLightningHandlerContext 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.
|
protected abstract boolean |
isLightningHandlerAutoconnect() |
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.
|
protected abstract PaymentData |
newPaymentData(byte[] preImageHash,
OrderRequest orderRequest)
Method that should generate a new PaymentData for a given order request.
|
void |
onLightningEvent(LightningEvent event)
This method is called every time an lightning invoice was added or settled.
|
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.
|
protected abstract void |
updatePaymentData(PaymentEventType type,
PaymentData paymentData,
LightningHandlerContext context)
Method called on update events about a given payment data.
|
protected static java.util.logging.Logger log
protected PaymentEventBus paymentEventBus
protected PaymentDataConverter paymentDataConverter
public void init() throws InternalErrorException
init
in interface PaymentHandler
InternalErrorException
- if internal error occurred setting
up the PaymentHandler.public Order createOrder(byte[] preImageHash, OrderRequest orderRequest) throws java.io.IOException, InternalErrorException
createOrder
in interface PaymentHandler
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.public Invoice lookupInvoice(byte[] preImageHash) throws java.io.IOException, InternalErrorException
lookupInvoice
in interface PaymentHandler
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.public Settlement checkSettlement(byte[] preImageHash, boolean includeInvoice) throws AlreadyExecutedException, java.lang.IllegalArgumentException, java.io.IOException, InternalErrorException
checkSettlement
in interface PaymentHandler
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.public Settlement registerSettledInvoice(Invoice settledInvoice, boolean registerNew, OrderRequest orderRequest, LightningHandlerContext context) throws java.lang.IllegalArgumentException, java.io.IOException, InternalErrorException
registerSettledInvoice
in interface PaymentHandler
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 or related invoice isn't settled.java.io.IOException
- if communication exception occurred in underlying components.InternalErrorException
- if internal exception occurred registering a settled invoice.public void markAsExecuted(byte[] preImageHash) throws java.io.IOException, InternalErrorException
markAsExecuted
in interface PaymentHandler
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.public void registerListener(PaymentListener listener) throws InternalErrorException
registerListener
in interface PaymentHandler
listener
- the listener to register.InternalErrorException
- if internal exception occurred registering the listener.public void unregisterListener(PaymentListener listener) throws InternalErrorException
unregisterListener
in interface PaymentHandler
listener
- the listener to un-register.InternalErrorException
- if internal exception occurred un-registering the listener.public LightningHandlerContext getLightningHandlerContext() throws InternalErrorException
getLightningHandlerContext
in interface PaymentHandler
InternalErrorException
- if internal exception occurred fetching latest known state of lightning handler.protected abstract LightningHandler getLightningHandler()
protected abstract java.time.Duration getDefaultInvoiceValidity()
protected abstract java.time.Duration getDefaultSettlementValidity()
protected abstract boolean isLightningHandlerAutoconnect() throws InternalErrorException
InternalErrorException
- if problems occurred parsing configuration.protected abstract PaymentData newPaymentData(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 payment data 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 generating new payment data.protected abstract PaymentData findPaymentData(byte[] preImageHash) throws java.io.IOException, InternalErrorException
preImageHash
- the unique preImageHash used to identify a payment flow
withing a lightning payment.java.io.IOException
- if communication exception occurred in underlying components.InternalErrorException
- if internal exception occurred fetching related payment data.protected abstract void updatePaymentData(PaymentEventType type, PaymentData paymentData, LightningHandlerContext context) throws java.io.IOException, InternalErrorException
type
- the type of event such as INVOICE_CREATED or INVOICE_SETTLED.paymentData
- the payment data to update and persist.context
- the latest known state of the lightning handler. Null if no known state exists.java.io.IOException
- if communication exception occurred in underlying components.InternalErrorException
- if internal exception occurred updating related payment data.public void onLightningEvent(LightningEvent event)
onLightningEvent
in interface LightningEventListener
event
- the related lightning event.LightningEvent