-
Notifications
You must be signed in to change notification settings - Fork 6
feat(payments): Add account id build method #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Quentin-David-24
wants to merge
1
commit into
main
Choose a base branch
from
feat/payments-account-id-build
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/java/com/formance/formance_sdk/utils/custom_helpers/PaymentsAccountId.java
This file contains hidden or 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,34 @@ | ||
| // Package custom helpers provides utilities to easy usage of Formance API. | ||
| // This file is NOT auto-generated and can be freely modified. | ||
| package com.formance.formance_sdk.utils.custom_helpers; | ||
|
|
||
| import java.util.Base64; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| public class PaymentsAccountId { | ||
| /** | ||
| * Creates an account ID string | ||
| * @param connectorId The ID of the connector | ||
| * @param reference The identifier of the account from the connector's provider. | ||
| * @return The identifier for Formance payments account. | ||
| * @throws IllegalArgumentException if connectorId or reference is null/blank, or if connectorId is invalid. | ||
| * | ||
| */ | ||
| public static String Build(String connectorId, String reference) { | ||
| if (connectorId == null || connectorId.isBlank()) { | ||
| throw new IllegalArgumentException("connectorId must not be null or blank"); | ||
| } | ||
| if (reference == null || reference.isBlank()) { | ||
| throw new IllegalArgumentException("reference must not be null or blank"); | ||
| } | ||
|
|
||
| String connectorIdJson = new String(Base64.getDecoder().decode(connectorId), StandardCharsets.UTF_8); | ||
| String json = String.format("{\"ConnectorID\":%s,\"Reference\":\"%s\"}", connectorIdJson, reference.replace("\\", "\\\\").replace("\"", "\\\"")); | ||
|
|
||
| try { | ||
| return Base64.getEncoder().withoutPadding().encodeToString(json.getBytes(StandardCharsets.UTF_8)); | ||
| } catch (Exception e) { | ||
| throw new IllegalArgumentException("Failed to build account ID. Please check if the connectorId is valid.", e); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: formancehq/formance-sdk-java
Length of output: 155
🏁 Script executed:
Repository: formancehq/formance-sdk-java
Length of output: 1948
🏁 Script executed:
Repository: formancehq/formance-sdk-java
Length of output: 367
🏁 Script executed:
Repository: formancehq/formance-sdk-java
Length of output: 4084
Escape JSON control characters in
referenceto prevent malformed IDs.The current escaping only handles backslash and quote. Control characters like newline, tab, and other characters below 0x20 are not escaped, resulting in invalid JSON when such characters appear in
reference. This breaks the account ID format expected by the Formance API.Add a helper method to properly escape all JSON-required characters:
Suggested fix (local escape helper)
🤖 Prompt for AI Agents