Skip to content

feat: support one-off charges via mode: oneOff#11

Merged
BenKalsky merged 1 commit into
mainfrom
feat/one-off-charge
May 1, 2026
Merged

feat: support one-off charges via mode: oneOff#11
BenKalsky merged 1 commit into
mainfrom
feat/one-off-charge

Conversation

@BenKalsky
Copy link
Copy Markdown
Member

Summary

Adds one-off charge support to createSumitChargeRoute via a new mode option, paired with the new builder/alias landing in sumit-api#11 (`buildOneOffChargePayload` + `normalizeChargeResponse`).

What's new

```ts
createSumitChargeRoute({
companyId,
apiKey,
mode: "oneOff", // default "recurring" — back-compat
onResult,
});
```

`mode` Endpoint Required item fields
`"recurring"` (default) `POST /billing/recurring/charge/` name, description, unitPrice, currency, durationMonths
`"oneOff"` `POST /billing/payments/charge/` name, description, unitPrice, currency

The same `` and `SingleUseToken` work for both — only the route's `mode` changes. The validator no longer requires `durationMonths` in one-off mode but still requires it in recurring mode.

Internally, response normalization switched from `normalizeRecurringChargeResponse` to its new alias `normalizeChargeResponse` (same function, clearer name).

Test plan

  • `pnpm test` — 31/31 passing (3 new tests: oneOff happy path, relaxed validation, recurring still requires durationMonths)
  • `pnpm typecheck` clean
  • `pnpm build` clean

Depends on

sumit-api#11 — must merge first since this PR imports the new `buildOneOffChargePayload` and `normalizeChargeResponse`.

🤖 Generated with Claude Code

`createSumitChargeRoute` previously hardcoded the recurring endpoint and
required `item.durationMonths`. It now accepts `mode: "recurring" |
"oneOff"` (default `"recurring"` for back-compat). One-off mode:

- Targets `POST /billing/payments/charge/` instead of `/billing/recurring/charge/`.
- Calls `buildOneOffChargePayload` from sumit-api — Items omit
  `Duration_Months` / `Recurrence`.
- Drops the `durationMonths` validation requirement.

Same `<SumitCheckout />`, same `SingleUseToken` — only the route's
`mode` changes.

Switches the response normalizer to the new `normalizeChargeResponse`
alias (was `normalizeRecurringChargeResponse`); behaviour is identical
since the underlying logic always handled both shapes.

3 new tests cover the oneOff happy path, the relaxed durationMonths
requirement, and the still-enforced recurring requirement.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@BenKalsky BenKalsky merged commit f3f605e into main May 1, 2026
1 of 2 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e744cda233

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2 to +4
buildOneOffChargePayload,
buildRecurringChargePayload,
normalizeRecurringChargeResponse,
normalizeChargeResponse,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Bump required sumit-api version for new imports

This change adds static imports for buildOneOffChargePayload and normalizeChargeResponse, but package.json still allows sumit-api >=0.1.0; any install that resolves an older compatible version will fail module loading before the handler runs (including recurring-only usage) because ESM imports are resolved eagerly. Please raise the peer/dev dependency minimum to the first sumit-api release that exports these symbols so consumers do not hit runtime/boot-time import errors.

Useful? React with 👍 / 👎.

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