Skip to content

plugin-ecommerce: restore the Stripe cart drift check with a metadata digest, and keep shippingAddress under the metadata limit #19055

Open

Description

@ratomirjovanovic

Follow-up to #19024 (the fix for #19017), split out so that PR can ship on its own.

Problem

  1. fix(plugin-ecommerce): drop cart items from Stripe payment intent metadata #19024 removes cartItemsSnapshot from the PaymentIntent metadata to stay under Stripe's 500-character limit. With it, validateSettlement no longer checks that transaction.items still match what was priced in initiatePayment. The amount check remains, but a change to the items between initiatePayment and confirmOrder is no longer detected. It also means a custom cart item field that the transactions schema does not store no longer fails confirmation (see the CodeRabbit thread on confirmOrder.ts in fix(plugin-ecommerce): drop cart items from Stripe payment intent metadata #19024).
  2. shippingAddress is still written to the metadata as the JSON of the address object the client sends. A full saved address document (with id, customer, createdAt, updatedAt and long address lines) can go past 500 characters and fail paymentIntents.create in the same way as bug(plugin-ecommerce): Stripe adapter exceeds 500-char metadata limit #19017.

Proposal

  1. Store a fixed-size digest instead of the snapshot: cartItemsHash = SHA-256 of stableSerialize(normalizeCartItems(flattenedCart)) (64 hex characters). validateSettlement compares it with the same hash of normalizeCartItems(transaction.items). Metadata can only be written with the secret key, so a plain hash is enough. PaymentIntents without the hash (created by the version that ships fix(plugin-ecommerce): drop cart items from Stripe payment intent metadata #19024) skip the comparison, so upgrading stays safe.
  2. Add a shippingAddress field to the transactions collection, like billingAddress, and stop writing the address to the metadata.

Acceptance criteria

  • New PaymentIntents carry cartItemsHash, and validateSettlement rejects a mismatch.
  • PaymentIntents without cartItemsHash still confirm.
  • Normalization tests cover relationship objects vs IDs, key order, null variants and custom properties.
  • A test with a realistic full shipping address keeps every metadata value under 500 characters.

Activity

  1. KRISH2507 commented on Oct 27, 2026

    @KRISH2507

    Hi @ratomirjovanovic, I would love to pick this up! I am currently investigating the crypto implementation for the cartItemsHash digest and the necessary schema updates for the shippingAddress. I'll start working on a draft PR and will reach out if I hit any roadblocks.

  2. ratomirjovanovic commented on Oct 27, 2026

    @ratomirjovanovic
    Author

    Thanks @KRISH2507, go ahead. Two things that may save you some time:

    • fix(plugin-ecommerce): drop cart items from Stripe payment intent metadata #19024 is still open and this builds on it (it removes cartItemsSnapshot), so it is probably easiest to branch from it or wait until it lands. Otherwise the two will conflict in initiatePayment and confirmOrder.
    • For the hash, the part that needs the most care is the normalization: relationship fields can arrive as an ID or as a populated document, and optional fields as undefined or null, so both sides need to reduce to the same shape before stableSerialize. The acceptance criteria list the cases I would test.

    Adding shippingAddress to the transactions collection is a schema change for the SQL adapters, so a line about running a migration in the changeset would help.

    Happy to review the PR when it is up.

  3. ratomirjovanovic commented on Oct 27, 2026

    @ratomirjovanovic
    Author

    @KRISH2507 heads up: #19024 was closed in favor of #19025, which already stores a hash of the cart items in the PaymentIntent metadata and checks it in confirmOrder. So the first half of this issue is covered there.

    What #19025 does not change is shippingAddress, which is still sent as one JSON string and can pass Stripe's 500-character limit with long address lines. If you want to pick something up, that part is still open. Probably best to base it on #19025 so the two don't conflict in initiatePayment.

  4. ratomirjovanovic commented on Oct 30, 2026

    @ratomirjovanovic
    Author

    In case it helps: the cart hash part looks covered by #19025 already (hashCartItems in initiatePayment, checked in confirmOrder), so shippingAddress is probably the bit still open. @KRISH2507 also mentioned earlier that they were looking at this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions