-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ACL-226] New HPP link builder with ability to show mandate results, …
…and set wait and/or signup (#328)
- Loading branch information
Showing
16 changed files
with
320 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/main/java/com/truelayer/java/HostedPaymentPageLinkBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.truelayer.java; | ||
|
||
import static org.apache.commons.lang3.ObjectUtils.isEmpty; | ||
|
||
import com.truelayer.java.entities.ResourceType; | ||
import java.net.URI; | ||
import java.text.MessageFormat; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE) | ||
public class HostedPaymentPageLinkBuilder { | ||
private final Environment environment; | ||
|
||
private ResourceType resourceType = ResourceType.PAYMENT; | ||
private String resourceId; | ||
private String resourceToken; | ||
private URI returnUri; | ||
private Integer maxWaitForResultSeconds; | ||
private Boolean signup; | ||
|
||
public HostedPaymentPageLinkBuilder resourceType(ResourceType resourceType) { | ||
this.resourceType = resourceType; | ||
return this; | ||
} | ||
|
||
public HostedPaymentPageLinkBuilder resourceId(String resourceId) { | ||
this.resourceId = resourceId; | ||
return this; | ||
} | ||
|
||
public HostedPaymentPageLinkBuilder resourceToken(String resourceToken) { | ||
this.resourceToken = resourceToken; | ||
return this; | ||
} | ||
|
||
public HostedPaymentPageLinkBuilder returnUri(URI returnUri) { | ||
this.returnUri = returnUri; | ||
return this; | ||
} | ||
|
||
public HostedPaymentPageLinkBuilder maxWaitForResultSeconds(int maxWaitForResultSeconds) { | ||
this.maxWaitForResultSeconds = maxWaitForResultSeconds; | ||
return this; | ||
} | ||
|
||
public HostedPaymentPageLinkBuilder signup(boolean signup) { | ||
this.signup = signup; | ||
return this; | ||
} | ||
|
||
public URI build() { | ||
if (isEmpty(this.resourceId)) { | ||
throw new TrueLayerException("resource_id must be set"); | ||
} | ||
|
||
if (isEmpty(resourceToken)) { | ||
throw new TrueLayerException("resource_token must be set"); | ||
} | ||
|
||
if (isEmpty(returnUri) || isEmpty(returnUri.toString())) { | ||
throw new TrueLayerException("return_uri must be set"); | ||
} | ||
|
||
URI hppLink = URI.create(MessageFormat.format( | ||
"{0}/{1}#{2}={3}&resource_token={4}&return_uri={5}", | ||
environment.getHppUri(), | ||
resourceType.getHppLinkPath(), | ||
resourceType.getHppLinkQueryParameter(), | ||
resourceId, | ||
resourceToken, | ||
returnUri)); | ||
|
||
if (!isEmpty(maxWaitForResultSeconds)) { | ||
hppLink = URI.create(MessageFormat.format("{0}&max_wait_for_result={1}", hppLink, maxWaitForResultSeconds)); | ||
} | ||
|
||
if (!isEmpty(signup)) { | ||
hppLink = URI.create(MessageFormat.format("{0}&signup={1}", hppLink, signup)); | ||
} | ||
|
||
return hppLink; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/truelayer/java/entities/ResourceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.truelayer.java.entities; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public enum ResourceType { | ||
PAYMENT("payments", "payment_id"), | ||
MANDATE("mandates", "mandate_id"), | ||
; | ||
|
||
private final String hppLinkPath; | ||
private final String hppLinkQueryParameter; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.