Skip to content

TWO-24892: buyer surcharge rounding (basis + brand-driven step)#328

Closed
dgjlindsay wants to merge 1 commit into
doug/TWO-24751-terms-chipsfrom
doug/TWO-24892-surcharge-rounding
Closed

TWO-24892: buyer surcharge rounding (basis + brand-driven step)#328
dgjlindsay wants to merge 1 commit into
doug/TWO-24751-terms-chipsfrom
doug/TWO-24892-surcharge-rounding

Conversation

@dgjlindsay

Copy link
Copy Markdown
Contributor

What

Ports the Magento buyer-surcharge-rounding feature to WooCommerce (TWO-24892, child of TWO-24739 plugin parity).

The merchant picks a rounding basis (None / Up / Down / Standard) and a rounding step from a brand-driven dropdown. The plugin relays buyer_fee_share.rounding = {step: <float>, basis: "UP"|"DOWN"|"STANDARD"} to POST /v1/pricing/order/fee. All arithmetic stays server-side — the plugin only relays the contract, mirroring Magento's Service/Order/SurchargeCalculator.

How (mirrors magento-plugin 1:1)

  • brands/two.php — new available_rounding_steps brand key (default 0.10 / 0.50 / 1.00 / 5.00 / 10.00), the only source for the step dropdown. An overlay narrows the set (cf. available_terms).
  • WC_Twoinc::get_rounding_step_options() — canonical two-decimal option list (number_format(…,2)) so the stored value round-trips, ascending (ksort SORT_NUMERIC); mirrors the Magento RoundingStep source model + Loader sort. Two new select fields in the offset-pricing section.
  • WC_Twoinc_Payment_Terms — reads the options in get_offset_settings(); build_rounding() emits the block, omitting it for a None/unmapped basis or a non-positive step (the API requires both keys and rejects step <= 0).
  • Tests — build_buyer_fee_share rounding cases (basis→API map, None/zero/negative/unmapped omission, rides alongside reference terms, ignored when offset disabled) + a Reflection test pinning the step-option producer (canonical format, sort, overlay narrowing, skip-invalid).

Semantics

  • None → no rounding block sent (standard 2dp).
  • Up / Down / Standard → round to nearest step (Standard = commercial half-up). The backend does the maths.

Stacking

Stacked on doug/TWO-24751-terms-chips (the only branch carrying both the buyer_fee_share builder and the brand-config layer). Rebases onto staging once TWO-24751 merges.

Out of scope (blocked, separate tickets)

  • WC-ABN narrowing (0.50/1.00) → TWO-24894 — blocked: offset-pricing parity not yet ported into the ABN overlay.
  • PrestaShop rounding → TWO-24893 — blocked: PS has no surcharge/offset-pricing feature yet.

Test / lint

php tests/unit/run.php green on PHP 7.4 + 8.2 (32/32); php -l clean. i18n .pot regeneration deferred to the Lokalise flow (no CI gate). Two adversarial review rounds → clean.

🤖 Generated with Claude Code

PR opened by Claude on Doug's behalf.

Port the Magento buyer-surcharge-rounding feature to WooCommerce. The
merchant picks a rounding basis (None / Up / Down / Standard) and a
rounding step from a brand-driven dropdown; the plugin relays
buyer_fee_share.rounding = {step, basis} to POST /v1/pricing/order/fee.
The backend does the arithmetic — the plugin only relays the contract,
mirroring Magento's Service/Order/SurchargeCalculator.

- brands/two.php: available_rounding_steps brand key (default
  0.10/0.50/1.00/5.00/10.00), the only source for the step dropdown.
  An overlay narrows the set (cf. available_terms).
- WC_Twoinc::get_rounding_step_options(): canonical 2dp option list so
  the stored value round-trips, mirroring the Magento RoundingStep
  source model. Two new select fields in the offset-pricing section.
- WC_Twoinc_Payment_Terms: read the options in get_offset_settings();
  build_rounding() emits the block, omitting it for a None/unmapped
  basis or a non-positive step (the API requires both keys and rejects
  step <= 0).
- tests/unit: build_buyer_fee_share rounding cases (basis->API map,
  None/zero-step omission, rides alongside reference terms, ignored
  when offset disabled).

Stacked on doug/TWO-24751-terms-chips (carries the buyer_fee_share
builder + brand-config layer). Rebases onto staging once TWO-24751
merges. i18n .pot regeneration deferred to the Lokalise flow.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions

Copy link
Copy Markdown

🖌 Pre-commit success 🏆

Details
Downloading virtualenv (4.3MiB)
 Downloaded virtualenv
Installed 11 packages in 13ms
[INFO] Initializing environment for https://github.com/pre-commit/mirrors-prettier.
[INFO] Initializing environment for https://github.com/pre-commit/mirrors-prettier:prettier@3.1.0.
[INFO] Initializing environment for https://github.com/two-inc/git-hooks.
[INFO] Installing environment for https://github.com/pre-commit/mirrors-prettier.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
prettier.................................................................Passed

Exit code: 0

Author ✍️@dgjlindsay

@dgjlindsay

Copy link
Copy Markdown
Contributor Author

Closing: superseded. Commits fully contained in staging (integrated via #329#339). Empty delta vs staging. Reopen if wrong. — closed by Claude on behalf of Doug

@dgjlindsay dgjlindsay closed this Jul 5, 2026
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.

1 participant