99import com .truelayer .java .commonapi .ICommonApi ;
1010import com .truelayer .java .commonapi .ICommonHandler ;
1111import com .truelayer .java .entities .RequestScopes ;
12- import com .truelayer .java .hpp .IHostedPaymentPageLinkBuilder ;
1312import com .truelayer .java .http .OkHttpClientFactory ;
1413import com .truelayer .java .http .RetrofitFactory ;
1514import com .truelayer .java .http .auth .cache .ICredentialsCache ;
16- import com .truelayer .java .http .auth .cache .SimpleCredentialsCache ;
15+ import com .truelayer .java .http .auth .cache .InMemoryCredentialsCache ;
1716import com .truelayer .java .http .interceptors .logging .DefaultLogConsumer ;
1817import com .truelayer .java .mandates .IMandatesApi ;
1918import com .truelayer .java .mandates .IMandatesHandler ;
@@ -72,6 +71,9 @@ public class TrueLayerClientBuilder {
7271
7372 private Consumer <String > logMessageConsumer ;
7473
74+ /**
75+ * Holder for the cache implementation. Null if caching is disabled
76+ */
7577 private ICredentialsCache credentialsCache ;
7678
7779 private ProxyConfiguration proxyConfiguration ;
@@ -182,12 +184,13 @@ public TrueLayerClientBuilder withHttpLogs(Consumer<String> logConsumer) {
182184 * @return the instance of the client builder used
183185 */
184186 public TrueLayerClientBuilder withCredentialsCaching () {
185- this .credentialsCache = new SimpleCredentialsCache (Clock .systemUTC ());
187+ this .credentialsCache = new InMemoryCredentialsCache (Clock .systemUTC ());
186188 return this ;
187189 }
188190
189191 /**
190192 * Utility to enable a custom cache for Oauth credentials.
193+ * @param credentialsCache the custom cache implementation
191194 * @return the instance of the client builder used
192195 */
193196 public TrueLayerClientBuilder withCredentialsCaching (ICredentialsCache credentialsCache ) {
@@ -228,10 +231,6 @@ public TrueLayerClient build() {
228231 .httpClient (RetrofitFactory .build (authServerApiHttpClient , environment .getAuthApiUri ()))
229232 .build ();
230233
231- IHostedPaymentPageLinkBuilder hppLinkBuilder = com .truelayer .java .hpp .HostedPaymentPageLinkBuilder .New ()
232- .uri (environment .getHppUri ())
233- .build ();
234-
235234 // We're reusing a client with only User agent and Idempotency key interceptors and give it our base payment
236235 // endpoint
237236 ICommonApi commonApi = RetrofitFactory .build (authServerApiHttpClient , environment .getPaymentsApiUri ())
@@ -241,7 +240,7 @@ public TrueLayerClient build() {
241240 // We're building a client which has the authentication handler and the options to cache the token.
242241 // this one represents the baseline for the client used for Signup+ and Payments
243242 OkHttpClient authenticatedApiClient = httpClientFactory .buildAuthenticatedApiClient (
244- authServerApiHttpClient , authenticationHandler , credentialsCache );
243+ clientCredentials . clientId , authServerApiHttpClient , authenticationHandler , credentialsCache );
245244 ISignupPlusApi signupPlusApi = RetrofitFactory .build (authenticatedApiClient , environment .getPaymentsApiUri ())
246245 .create (ISignupPlusApi .class );
247246 SignupPlusHandler .SignupPlusHandlerBuilder signupPlusHandlerBuilder =
@@ -256,7 +255,6 @@ public TrueLayerClient build() {
256255 if (isEmpty (signingOptions )) {
257256 return new TrueLayerClient (
258257 authenticationHandler ,
259- hppLinkBuilder ,
260258 commonHandler ,
261259 signupPlusHandler ,
262260 new HostedPaymentPageLinkBuilder (environment ));
@@ -324,7 +322,6 @@ public TrueLayerClient build() {
324322 payoutsHandler ,
325323 signupPlusHandler ,
326324 commonHandler ,
327- hppLinkBuilder ,
328325 new HostedPaymentPageLinkBuilder (environment ));
329326 }
330327
0 commit comments