Skip to content

feat(payments): support the Wix Payment Element in mountCheckout - #392

Draft
OleksandrSamsonov wants to merge 15 commits into
mainfrom
feat/wix-payment-element
Draft

OleksandrSamsonov wants to merge 15 commits into
mainfrom
feat/wix-payment-element

Conversation

@OleksandrSamsonov

@OleksandrSamsonov OleksandrSamsonov commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What

mountCheckout() can now render an embedded Base44 Payments checkout with the Wix Payment Element.

Public types

  • One new member of the EmbeddedCheckout union, exported from the package:
    export interface WixEmbeddedCheckout {
      provider: "wix";
      /** May be absent, so don't rely on it. */
      client_id?: string;
    }
  • client_id is optional on purpose. It will be replaced by an access token later, so apps should only pass the createCheckout() result to mountCheckout().
  • The checkout's checkout_id is the payment session id, which the element takes as its intentId. There is no separate order id.
  • MountCheckoutOptions.onReadyChange?(ready) and CheckoutMount.pay?(), for Base44 Payments only (see the mount flow).
  • preloadCheckout() also takes "wix" and loads the element script early.
  • No other signature changes to createCheckout, mountCheckout, completeCheckout, listPurchases or refund.

Backend contract this relies on

  • Creating an embedded Base44 Payments checkout creates a payment session and returns its id (checkout_id) and the element's client id (embedded.client_id).
  • Reading a session gives a neutral payment object: status (PENDING, PAID, DECLINED, REFUNDED, PARTIALLY_REFUNDED), chargeId once paid, amount (decimal string) and currency. completeCheckout() maps this to paid / pending.
  • GET /payments/config returns wix.script_url. Only https://tpa.wixapps.net is allowed.

Mount flow

  1. Without client_id, the mount rejects before anything loads.
  2. The SDK loads the element script and calls wpe({ getAccessToken, locale }).create("checkout", { intentId: checkout_id }), then await element.mount(box). A failed mount cleans up and rejects. Locale comes from <html lang> or navigator.language.
    • getAccessToken gives the element an anonymous Wix visitor token, which the SDK mints from client_id (POST https://www.wixapis.com/oauth2/token) and renews through the refresh token, minting again if that fails.
    • The SDK keeps one visitor per client ID in memory, so remounts and several checkouts reuse its token and concurrent calls share one request.
  3. The SDK draws no button. The app brings its own Pay button, so it controls the text, language and layout. onReadyChange(true) fires on the element's ready, and onReadyChange(false) on loaderror. The app enables its button only while ready.
  4. The app calls mount.pay() from its button's click handler, before any await. pay() calls confirmPayment() synchronously, so payment-method windows can open. The result is handled like this:
    • { status: "succeeded" } → completeCheckout(checkout_id) → onComplete. pay() does nothing after this, even if completeCheckout() fails, so there is no second charge.
    • { status: "canceled" } (a decline included) → onCancel. The app can call pay() again.
    • The element rejects → onError. pay() does nothing after this, because the element refuses another payment. Create a new checkout and mount it.
    • pay() also does nothing while the element isn't ready or a payment is running.
  5. setDisabled() is a no-op, as for Stripe, since the app owns the button. Callbacks stop after destroy(), but a succeeded payment is still completed.

JSDoc is updated for the provider table, presentation, the callbacks, setDisabled, pay, preloadCheckout, mountCheckout (with a Base44 Payments example), and both completeCheckout methods.

Tests

  • Unit tests for the Wix mount:
    • wpe options and intentId
    • missing client_id
    • ready / loaderror → onReadyChange
    • sync confirm inside pay()
    • success / cancel / error paths
    • pay() guards (not ready, double call, after success or error)
    • preloadCheckout("wix")
    • visitor token: mint, reuse, renew, renewal race, refresh fallback, failure
    • mount failure cleanup and script host check
  • Type tests: embedded.provider === "wix" narrows; pay, onReadyChange and preloadCheckout("wix").
  • npm test -w @base44/sdk (type tests plus 500 unit tests), npm run lint and npm run build pass.

🤖 Generated with Claude Code

OleksandrSamsonov and others added 9 commits November 20, 2026 16:37
Add a WixEmbeddedCheckout member to EmbeddedCheckout. mountCheckout loads
the element script from the payments config, mounts the element with a Pay
button the SDK owns, calls confirmPayment() inside the click, then
completes the checkout and calls onComplete, as it does for PayPal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its mount() is async, so a failed mount now rejects mountCheckout and
cleans up instead of leaving a Pay button. Also scope payment_declined
docs to PayPal and note that Base44 Payments checkouts are completed too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The checkout never sets it, so the element is created with intentId only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The checkout_id is now the element's intentId, so WixEmbeddedCheckout drops
order_id, and client_id is optional. A mount without it rejects. The element
is created with wpe({ clientId, locale }) and confirmPayment() resolves
{ status }. The Pay button stays off until the element is ready, and after
the element rejects a payment, since it refuses another one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…derror

Reject a checkout without a client ID before fetching the config. Turn the
Pay button off on loaderror until the element is ready again. Type the
payment result and note in setDisabled() that the button stays off after a
rejected payment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt is down

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… SDK

mountCheckout now passes getAccessToken to the element instead of the
client ID. The SDK mints an anonymous visitor token from the checkout's
client ID, renews it through the refresh token (or mints again when that
fails), and keeps one visitor per client ID in memory, so remounts and
other checkouts reuse it and concurrent calls share one request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ckout

# Conflicts:
#	packages/sdk/src/modules/payments.types.ts
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/sdk@0.8.63-pr.392.bf1bd0a

Prefer not to change any import paths? Install using npm alias so your code still imports @base44/sdk:

npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.63-pr.392.bf1bd0a"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "@base44/sdk": "npm:@base44-preview/sdk@0.8.63-pr.392.bf1bd0a"
  }
}

Preview published to npm registry — try new features instantly!

@github-actions github-actions Bot added the docs-draft PR has auto-drafted documentation suggestions label Nov 25, 2026
amitbardos and others added 4 commits November 25, 2026 14:10
The Wix Payment Element has no button, and Wix's guide leaves it to the
page. A hardcoded "Pay" button from the SDK can't be translated, can't
have content between it and the form, and fights the app's own layout.

The mount now returns pay(), which the app calls from its own button's
click handler, and onReadyChange tells it when to enable that button.
pay() keeps the old guards: it does nothing until the element is ready,
during a payment, or after one succeeded or failed, so a failed
completeCheckout() after a successful charge can't lead to a second one.
setDisabled() is a no-op for Base44 Payments, as it is for Stripe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
preloadCheckout('wix') loads the element's script when the page opens.
Most of its cost is the tpa.wixapps.net redirect to static.parastorage.com
(two connections), not the 4.7KB file, so starting it early takes a
noticeable part of the wait off the buyer's click.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ckout

# Conflicts:
#	packages/sdk/src/modules/payments.types.ts
@OleksandrSamsonov

Copy link
Copy Markdown
Collaborator Author

This PR replaces #386 (it was opened from a fork, so it got no preview package). Review comments from #386 and where they stand here:

# Comment Status
1 Keep the button off once confirmPayment() succeeds, even if completeCheckout() fails Done. finished is set before completeCheckout(), so pay() does nothing after a success. Test: "doesn't charge again when completing the checkout fails after the payment".
2 Add Wix to preloadCheckout() Done in 7bcad99: preloadCheckout("wix").
3 Locale should not be set in the client Open. Kept as is for now: the element can change locale on the fly, and Stripe/PayPal also take it in the client (reply). If we drop it, the element falls back to its default.
4 Don't force an SDK Pay button Done in bb58d72: no SDK button. The app calls mount.pay() from its own button and gets onReadyChange(ready). setDisabled() is a no-op, as for Stripe.
5 Use getAccessToken() instead of clientId Done in 2938d3c: the SDK mints and renews a visitor token and passes getAccessToken.
6 Why is the Wix script URL format different from Stripe/PayPal in tests No change. The config returns the unversioned loader URL, which redirects to the current build. A versioned URL would also need its CDN host in the allow list.
7 Use @wix/sdk for the token code Not done. @wix/sdk would add 8 runtime dependencies (jose, @wix/identity, @wix/redirects, @wix/image-kit, …) to @base44/sdk to replace about 50 lines (mint, refresh, fall back to mint, one shared request). Same request shapes as its OAuthStrategy. Happy to switch if we prefer the dependency.

Branch also merged with main (provider table: kept "Embedded: Yes" plus main's refund/subscription rows). Tests (500), type tests, lint and build pass.

🤖 Generated with Claude Code

OleksandrSamsonov and others added 2 commits November 26, 2026 13:35
Base44 Payments (Wix) embedded checkouts accept a buyer billing address.
Reuses the ShippingAddress shape. Notes that Wix embedded takes a
shipping address but no shipping fee yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base44 Payments (Wix) shipping is out of scope for now. Only billing is
supported there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-draft PR has auto-drafted documentation suggestions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants