Class InterledgerApiClientImpl
- All Implemented Interfaces:
InterledgerApiClient
InterledgerApiClient interface.
This implementation provides a complete HTTP-based client for the Interledger Open Payments protocol, with cryptographic request signing using Ed25519 keys. The client is designed for Fliqa's payment facilitation use cases where Fliqa acts as an intermediary between payment senders and receivers.
Features
- Cryptographic request signing using Ed25519 private keys
- HTTP/2 client with configurable timeouts and connection limits
- Comprehensive error handling with structured exception types
- Request/response logging for debugging and auditing
- Input validation for all public methods
Thread Safety
This implementation is thread-safe and can be used concurrently from multiple threads. The underlying HTTP client and cryptographic operations are thread-safe.
Security
All requests to Interledger servers are signed using Ed25519 signatures following the HTTP Message Signatures specification. The client validates that all required parameters are provided and non-null before making requests.
Error Handling
The client distinguishes between different types of HTTP errors:
- 4xx errors - Client errors (invalid requests, authentication failures)
- 5xx errors - Server errors (Interledger server issues)
- Network errors - Connection timeouts, DNS failures, etc.
- Since:
- 1.0
- See Also:
-
Field Summary
Fields inherited from interface io.fliqa.client.interledger.InterledgerApiClient
INTERNAL_SERVER_ERROR -
Constructor Summary
ConstructorsConstructorDescriptionInterledgerApiClientImpl(WalletAddress clientWallet, PrivateKey privateKey, String keyId) Creates a new Interledger API client with default configuration options.InterledgerApiClientImpl(WalletAddress clientWallet, PrivateKey privateKey, String keyId, InterledgerClientOptions options) Creates a new Interledger API client with custom configuration options. -
Method Summary
Modifier and TypeMethodDescriptioncontinueGrant(PaymentPointer sender, Quote quote, URI returnUrl, String nonce) Creates a pending outgoing payment that requires user interaction for authorization.protected static HttpClientcreateIncomingPayment(PaymentPointer receiver, AccessGrant pendingGrant, BigDecimal amount) Creates an incoming payment request on the receiver's wallet.createPendingGrant(PaymentPointer receiver) Creates a pending grant for a receiving wallet to enable incoming payment creation.createQuote(String quoteToken, PaymentPointer sender, IncomingPayment incomingPayment) Creates a quote that calculates the exact cost for the sender to complete the payment.createQuoteRequest(PaymentPointer sender) Creates a quote request grant for the sender's wallet.finalizeGrant(OutgoingPayment outgoingPayment, String interactRef) Finalizes the grant after the user has approved the payment.finalizePayment(AccessGrant finalizedGrant, PaymentPointer senderWallet, Quote quote) Executes the final payment using the finalized grant.getIncomingPayment(IncomingPayment payment, AccessGrant grant) Retrieves the current status of an incoming payment.getWallet(WalletAddress address) Retrieves wallet information from an Interledger payment pointer.<T> Tsend(HttpRequest request, Class<T> responseType) Sends an HTTP request and processes the response to return the desired type.
-
Constructor Details
-
InterledgerApiClientImpl
public InterledgerApiClientImpl(WalletAddress clientWallet, PrivateKey privateKey, String keyId, InterledgerClientOptions options) Creates a new Interledger API client with custom configuration options.This constructor allows full customization of the HTTP client behavior including connection timeouts, request timeouts, and maximum concurrent connections.
- Parameters:
clientWallet- the wallet address of the payment facilitator (Fliqa)privateKey- Ed25519 private key for signing requestskeyId- identifier for the private key, used in signature headersoptions- HTTP client configuration including timeouts and connection limits- Throws:
IllegalArgumentException- if any parameter is null or keyId is empty- See Also:
-
InterledgerApiClientImpl
Creates a new Interledger API client with default configuration options.This convenience constructor uses default HTTP client settings, including standard timeouts and connection limits suitable for most use cases.
- Parameters:
clientWallet- the wallet address of the payment facilitator (Fliqa)privateKey- Ed25519 private key for signing requestskeyId- identifier for the private key, used in signature headers- Throws:
IllegalArgumentException- if any parameter is null or keyId is empty- See Also:
-
-
Method Details
-
createDefaultHttpClient
-
getWallet
Description copied from interface:InterledgerApiClientRetrieves wallet information from an Interledger payment pointer.This is typically the first step in any payment flow, used to discover the wallet's supported assets, authorization server, and resource server endpoints. The wallet information is essential for subsequent grant requests and payment operations.
- Specified by:
getWalletin interfaceInterledgerApiClient- Parameters:
address- the wallet address that facilitates, sends, or receives payments- Returns:
- wallet information including asset details, authorization server, and resource server URLs
- Throws:
InterledgerClientException- if the wallet cannot be found or accessed- See Also:
-
createPendingGrant
Description copied from interface:InterledgerApiClientCreates a pending grant for a receiving wallet to enable incoming payment creation.This grant provides Fliqa with permission to create incoming payment requests on behalf of the receiver. The grant includes access tokens that authorize operations like creating, reading, and completing incoming payments.
Step 1 in the payment flow (Receiver side).
- Specified by:
createPendingGrantin interfaceInterledgerApiClient- Parameters:
receiver- the wallet that will receive the payment- Returns:
- access grant containing tokens and permissions for incoming payments
- Throws:
InterledgerClientException- if the grant cannot be created or the wallet rejects the request- See Also:
-
createIncomingPayment
public IncomingPayment createIncomingPayment(PaymentPointer receiver, AccessGrant pendingGrant, BigDecimal amount) throws InterledgerClientException Description copied from interface:InterledgerApiClientCreates an incoming payment request on the receiver's wallet.This establishes a payment destination with a specific amount that senders can pay to. The incoming payment serves as the target for the outgoing payment from the sender's wallet.
Step 2 in the payment flow (Receiver side).
- Specified by:
createIncomingPaymentin interfaceInterledgerApiClient- Parameters:
receiver- the wallet that will receive the paymentpendingGrant- access grant obtained fromInterledgerApiClient.createPendingGrant(PaymentPointer)amount- the payment amount with two decimal places precision- Returns:
- incoming payment request that can be referenced by sender wallets
- Throws:
InterledgerClientException- if the payment request cannot be created- See Also:
-
createQuoteRequest
Description copied from interface:InterledgerApiClientCreates a quote request grant for the sender's wallet.This grant provides permission to request quotes from the sender's wallet, which is necessary to calculate transaction fees and exchange rates before creating the actual payment.
Step 3 in the payment flow (Sender side).
- Specified by:
createQuoteRequestin interfaceInterledgerApiClient- Parameters:
sender- the wallet that will send the payment- Returns:
- access grant for creating quotes on the sender's wallet
- Throws:
InterledgerClientException- if the quote request grant cannot be created- See Also:
-
createQuote
public Quote createQuote(String quoteToken, PaymentPointer sender, IncomingPayment incomingPayment) throws InterledgerClientException Description copied from interface:InterledgerApiClientCreates a quote that calculates the exact cost for the sender to complete the payment.The quote includes the debit amount (what the sender pays) and receive amount (what the receiver gets), accounting for any transaction fees and currency conversions. This quote links the sender's wallet to the specific incoming payment.
Step 4 in the payment flow (Sender side).
- Specified by:
createQuotein interfaceInterledgerApiClient- Parameters:
quoteToken- access token from the quote request grantsender- the wallet that will send the paymentincomingPayment- the target payment request created on the receiver's wallet- Returns:
- quote containing debit amount, receive amount, and payment details
- Throws:
InterledgerClientException- if the quote cannot be generated- See Also:
-
continueGrant
public OutgoingPayment continueGrant(PaymentPointer sender, Quote quote, URI returnUrl, String nonce) throws InterledgerClientException Description copied from interface:InterledgerApiClientCreates a pending outgoing payment that requires user interaction for authorization.This step initiates the interactive authorization flow where the user must visit a redirect URL to approve the payment in their wallet. The user will be redirected back to the return URL with an interaction reference upon completion.
Step 5 in the payment flow (Sender side).
- Specified by:
continueGrantin interfaceInterledgerApiClient- Parameters:
sender- the wallet that will send the paymentquote- the quote generated for this paymentreturnUrl- URI where the user will be redirected after payment authorizationnonce- unique identifier to prevent replay attacks and maintain state- Returns:
- outgoing payment with interaction details including the redirect URL
- Throws:
InterledgerClientException- if the payment cannot be created- See Also:
-
finalizeGrant
public AccessGrant finalizeGrant(OutgoingPayment outgoingPayment, String interactRef) throws InterledgerClientException Description copied from interface:InterledgerApiClientFinalizes the grant after the user has approved the payment.Once the user completes the interactive authorization flow, they are redirected back with an interaction reference. This method uses that reference to finalize the grant and obtain the final access token needed to execute the payment.
Step 6 in the payment flow (Client side).
- Specified by:
finalizeGrantin interfaceInterledgerApiClient- Parameters:
outgoingPayment- the pending payment to be finalizedinteractRef- interaction reference returned from the user's wallet after authorization- Returns:
- finalized access grant with tokens to execute the payment
- Throws:
InterledgerClientException- if the grant cannot be finalized or the interaction reference is invalid- See Also:
-
finalizePayment
public Payment finalizePayment(AccessGrant finalizedGrant, PaymentPointer senderWallet, Quote quote) throws InterledgerClientException Description copied from interface:InterledgerApiClientExecutes the final payment using the finalized grant.This method transfers the funds from the sender's wallet to the receiver's wallet using the finalized access grant. The payment amount and details are based on the previously generated quote.
Step 7 in the payment flow (Client side).
- Specified by:
finalizePaymentin interfaceInterledgerApiClient- Parameters:
finalizedGrant- the finalized access grant obtained fromInterledgerApiClient.finalizeGrant(OutgoingPayment, String)senderWallet- the wallet that will send the paymentquote- the quote that determines payment amounts and fees- Returns:
- completed payment details including transaction ID and status
- Throws:
InterledgerClientException- if the payment execution fails- See Also:
-
getIncomingPayment
public IncomingPayment getIncomingPayment(IncomingPayment payment, AccessGrant grant) throws InterledgerClientException Description copied from interface:InterledgerApiClientRetrieves the current status of an incoming payment.This method is used to monitor payment completion and track the received amount. It can be called multiple times to poll for payment status updates until the payment is marked as completed.
- Specified by:
getIncomingPaymentin interfaceInterledgerApiClient- Parameters:
payment- the incoming payment to checkgrant- the access grant that provides permission to read the payment- Returns:
- current payment status including completion state and received amount
- Throws:
InterledgerClientException- if the payment cannot be found or access is denied- See Also:
-
send
Sends an HTTP request and processes the response to return the desired type.- Type Parameters:
T- represents the type of the response object to be returned after deserialization.- Parameters:
request- the HTTP request to be sentresponseType- the class type of the response object to be returned- Returns:
- the deserialized response of type T
- Throws:
InterledgerClientException- if an error occurs during the request, response handling, or deserialization process
-