Skip to content

Fix line item unit amount parsing from price field. - #13187

Merged
jaynewstrom-stripe merged 2 commits into
masterfrom
jaynewstrom/fix-line-item-unit-amount
Jun 3, 2026
Merged

Fix line item unit amount parsing from price field.#13187
jaynewstrom-stripe merged 2 commits into
masterfrom
jaynewstrom/fix-line-item-unit-amount

Conversation

@jaynewstrom-stripe

Copy link
Copy Markdown
Collaborator

Summary

Updates the checkout session parser to read unit amount from the price field instead of calculating it from total/quantity.

Motivation

The previous implementation calculated unit amount by dividing total by quantity, which was incorrect when the total included taxes or other adjustments. The API provides the correct unit amount in the price field, which should be used instead.

Testing

  • Added tests
  • Modified tests
  • Manually verified

Changelog

[Fixed] Fixed incorrect unit amount calculation for line items in checkout sessions when totals include taxes.

@jaynewstrom-stripe
jaynewstrom-stripe marked this pull request as ready for review June 2, 2026 16:41
@jaynewstrom-stripe
jaynewstrom-stripe requested review from a team as code owners June 2, 2026 16:41
cttsai-stripe
cttsai-stripe previously approved these changes Jun 3, 2026
val subtotal = obj.optLong(FIELD_SUBTOTAL, -1).takeIf { it >= 0 } ?: return@mapNotNull null
val total = obj.optLong(FIELD_TOTAL, -1).takeIf { it >= 0 } ?: return@mapNotNull null
val unitAmount = if (quantity > 0) total / quantity else null
val unitAmount = obj.optLong(FIELD_UNIT_AMOUNT_OVERRIDE, -1).takeIf { it >= 0 }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want to test the override case?

@jaynewstrom-stripe
jaynewstrom-stripe merged commit ee7721f into master Jun 3, 2026
49 checks passed
@jaynewstrom-stripe
jaynewstrom-stripe deleted the jaynewstrom/fix-line-item-unit-amount branch June 3, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants