Skip to content

#12 take care the ftPayItemId is null if empty to avoid issues with b…#13

Merged
MaximilianFT merged 1 commit intomainfrom
bugfix/12-devkit-howto_08-sign-tip-pay-item-id-wrong
Mar 12, 2026
Merged

#12 take care the ftPayItemId is null if empty to avoid issues with b…#13
MaximilianFT merged 1 commit intomainfrom
bugfix/12-devkit-howto_08-sign-tip-pay-item-id-wrong

Conversation

@turtletramp
Copy link
Collaborator

No description provided.

…ackend API (reject because of 400 BAD REUEST on /sign)
Copilot AI review requested due to automatic review settings March 6, 2026 17:08
@turtletramp turtletramp marked this pull request as ready for review March 6, 2026 17:08
@turtletramp turtletramp requested a review from a team March 6, 2026 17:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #12 by ensuring that ftPayItemId is null (rather than an empty string) when no ID is set, to prevent problems with the backend when an empty string is sent in the JSON payload.

Changes:

  • ftPayItemId in PayItem is changed to a nullable string? type to allow null values.
  • A normalization loop is added to the ReceiptRequest constructor to convert any empty ftPayItemId values to null before the pay items are stored.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
libPosSystemAPI/DTO/PayItem.cs Changes ftPayItemId to string? to allow null, but retains = string.Empty as the default initializer
libPosSystemAPI/DTO/ReceiptRequest.cs Adds a loop in the constructor to normalize empty ftPayItemId strings to null

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string ftPayItemId { get; set; } = string.Empty;
public string? ftPayItemId { get; set; } = string.Empty;
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ftPayItemId property is now declared as string? but the initializer is still = string.Empty. Since [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] only omits a property when its value equals the type's default (null for reference types), an instance of PayItem where ftPayItemId is never set will still serialize the property as "" — not omit it. This defeats the purpose of the change, because any PayItem that isn't processed through the ReceiptRequest constructor (e.g. deserialized from JSON and re-serialized, or directly constructed outside of ReceiptRequest) will still emit "ftPayItemId": "" in the JSON payload.

The default initializer should be changed from = string.Empty to = null (or simply removed, since null is already the implicit default for string?), so that the [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] attribute works correctly and the property is omitted from serialization when no ID is assigned.

Suggested change
public string? ftPayItemId { get; set; } = string.Empty;
public string? ftPayItemId { get; set; }

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +34
// verify that empty ftPayItemIDs are null
foreach (var payItem in cbPayItems)
{
if (payItem.ftPayItemId == "")
{
payItem.ftPayItemId = null;
}
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normalization loop in the constructor mutates the PayItem objects in the caller-provided cbPayItems list in-place (setting ftPayItemId = null on the original objects). This is an unexpected side effect: callers may not expect that passing their list into the ReceiptRequest constructor will modify their PayItem objects. If the root issue (see PayItem.cs line 9) is fixed by changing the default initializer to null, then this normalization loop would become unnecessary and could be removed entirely.

Suggested change
// verify that empty ftPayItemIDs are null
foreach (var payItem in cbPayItems)
{
if (payItem.ftPayItemId == "")
{
payItem.ftPayItemId = null;
}
}

Copilot uses AI. Check for mistakes.
@MaximilianFT MaximilianFT merged commit 657cfb0 into main Mar 12, 2026
5 checks passed
@MaximilianFT MaximilianFT deleted the bugfix/12-devkit-howto_08-sign-tip-pay-item-id-wrong branch March 12, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DevKit HOWTO_08] sign request in lib does produce empty ftPyItemId field for the tip pay item entry - should be undefined if empty

4 participants