public abstract class BasePaymentFlowManager extends java.lang.Object implements PaymentFlowManager
There are numerous empty methods that should be implemented for different modes and states of payment flows.
Created by Philip Vendil on 2018-12-20.Constructor and Description |
---|
BasePaymentFlowManager() |
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
findCookie(CachableHttpServletRequest request,
java.lang.String cookieName)
Help method to find first cookie with specified name.
|
protected java.lang.String |
findToken(CachableHttpServletRequest request,
java.lang.String parameterName,
java.lang.String headerName,
java.lang.String cookieName)
Help method retrieving a JWT token by searching the parameters, header or cookie.
|
protected org.jose4j.jwt.JwtClaims |
getAndVerifyTokenClaims(CachableHttpServletRequest request,
ExpectedTokenType expectedTokenType)
Help method to find and verify JWT token from a HTTP request.
|
protected java.lang.String |
getCentralSystemRecipientId()
Method that should be overridden in distributed setups.
|
protected CurrencyConverter |
getCurrencyConverter() |
protected LightningHandler |
getLightningHandler() |
protected OrderRequestGeneratorFactory |
getOrderRequestGeneratorFactory() |
PaymentFlow |
getPaymentFlowByAnnotation(PaymentRequired paymentRequired,
CachableHttpServletRequest request)
Method to create a new instance of related mode of PaymentFlow initialized with
current state in the payment flow.
|
PaymentFlow |
getPaymentFlowFromToken(CachableHttpServletRequest request,
ExpectedTokenType expectedTokenType)
Method to create a new instance of related mode of PaymentFlow initialized with
current state in the payment flow.
|
protected abstract PaymentFlowMode |
getPaymentFlowMode(OrderRequest orderRequest)
Method that should return mode of payment flow in relation.
|
protected PaymentHandler |
getPaymentHandler() |
protected abstract boolean |
getRegisterNewInvoices() |
protected RequestPolicyFactory |
getRequestPolicyFactory() |
protected abstract TokenGenerator |
getTokenGenerator()
Method that must be implemented and return the TokenGenerator used.
|
protected abstract java.time.Duration |
getTokenNotBeforeDuration() |
protected boolean |
hasSettlementToken(CachableHttpServletRequest request)
Help method checking if JWT token is set in HTTP header.
|
protected PaymentFlow |
lookupPaymentFlow(PaymentRequired paymentRequired,
CachableHttpServletRequest request,
OrderRequest orderRequest,
org.jose4j.jwt.JwtClaims tokenClaims,
ExpectedTokenType expectedTokenType)
Help method creating a new instance of configured payment flow (depending on PaymentFlowMode).
|
public PaymentFlow getPaymentFlowByAnnotation(PaymentRequired paymentRequired, CachableHttpServletRequest request) throws InternalErrorException, java.io.IOException, TokenException
getPaymentFlowByAnnotation
in interface PaymentFlowManager
paymentRequired
- the related annotation for the resource needing payment.request
- the HTTP request to parse JWT token from.java.lang.IllegalArgumentException
- if user specified parameters (used by the constructor) was invalid.java.io.IOException
- if communication problems occurred with underlying components.InternalErrorException
- if internal errors occurred processing the method.TokenException
- if problems occurred generating or validating related JWT Token.public PaymentFlow getPaymentFlowFromToken(CachableHttpServletRequest request, ExpectedTokenType expectedTokenType) throws java.lang.IllegalArgumentException, InternalErrorException, java.io.IOException, TokenException
This method should be called in states that doesn't have access to the PaymentRequired annotation, such as status controllers and similar.
getPaymentFlowFromToken
in interface PaymentFlowManager
request
- the HTTP request to parse JWT token from.expectedTokenType
- the expected type of JWT token.java.lang.IllegalArgumentException
- if user specified parameters (used by the constructor) was invalid.java.io.IOException
- if communication problems occurred with underlying components.InternalErrorException
- if internal errors occurred processing the method.TokenException
- if problems occurred generating or validating related JWT Token.protected RequestPolicyFactory getRequestPolicyFactory()
protected LightningHandler getLightningHandler()
protected PaymentHandler getPaymentHandler()
protected CurrencyConverter getCurrencyConverter()
protected OrderRequestGeneratorFactory getOrderRequestGeneratorFactory()
protected abstract TokenGenerator getTokenGenerator()
protected abstract PaymentFlowMode getPaymentFlowMode(OrderRequest orderRequest)
orderRequest
- the related order request.PaymentFlowMode
protected java.lang.String getCentralSystemRecipientId()
protected abstract java.time.Duration getTokenNotBeforeDuration()
protected abstract boolean getRegisterNewInvoices()
protected PaymentFlow lookupPaymentFlow(PaymentRequired paymentRequired, CachableHttpServletRequest request, OrderRequest orderRequest, org.jose4j.jwt.JwtClaims tokenClaims, ExpectedTokenType expectedTokenType) throws InternalErrorException
paymentRequired
- the annotation signaling the requested resource requires payment.
Can be null for some nodes in a distributed setup.request
- the related HTTP Request in this phase of the payment flow.orderRequest
- the orderRequest calculated either from paymentRequired annotation
of extracted from JWT token depending on state in the payment flow.tokenClaims
- all claims parsed from the related JWT token. Null in no related token exists in current state.expectedTokenType
- the expected type of JWT token expected in this state of the payment flow.InternalErrorException
- if internal errors occurred creating the payment flow.protected boolean hasSettlementToken(CachableHttpServletRequest request)
request
- the http request to lookup JWT in.protected org.jose4j.jwt.JwtClaims getAndVerifyTokenClaims(CachableHttpServletRequest request, ExpectedTokenType expectedTokenType) throws TokenException, InternalErrorException, java.io.IOException
request
- the http request to parse token from.expectedTokenType
- the expected type token to parse and verify.java.io.IOException
- if communication problems occurred with underlying components.InternalErrorException
- if internal errors occurred processing the token.TokenException
- if problems occurred generating or validating related JWT Token.protected java.lang.String findToken(CachableHttpServletRequest request, java.lang.String parameterName, java.lang.String headerName, java.lang.String cookieName)
request
- hte related http request.parameterName
- the parameter name to lookup, null to skip.headerName
- the header name to lookup, null to skip.cookieName
- the cookie name to lookup, null to skip.protected java.lang.String findCookie(CachableHttpServletRequest request, java.lang.String cookieName)
request
- the http request to parse cookie fromcookieName
- the name of the cookie to find.