Skip to content

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

Closed
OleksandrSamsonov wants to merge 10 commits into
base44:mainfrom
OleksandrSamsonov:feat/wix-embedded-checkout
Closed

OleksandrSamsonov wants to merge 10 commits into
base44:mainfrom
OleksandrSamsonov:feat/wix-embedded-checkout

Conversation

@OleksandrSamsonov

@OleksandrSamsonov OleksandrSamsonov commented Nov 20, 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.
  • No signature changes to createCheckout, mountCheckout, completeCheckout, listPurchases or refund. preloadCheckout() stays "paypal" | "stripe".

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 adds a Pay button (class base44-checkout-pay). It turns on only when the element fires ready, and turns off on loaderror until the next ready.
  4. On click, the SDK calls confirmPayment() synchronously, before any await, so payment-method windows can open. The result is handled like this:
    • { status: "succeeded" } → completeCheckout(checkout_id) → onComplete. The button stays off.
    • { status: "canceled" } (a decline included) → onCancel. The button turns back on for a retry.
    • The element rejects → onError. The button stays off, because the element refuses another payment. Create a new checkout and mount it.
  5. setDisabled() and destroy() work as for PayPal. Callbacks stop after destroy(), but a succeeded payment is still completed.

JSDoc is updated for the provider table, presentation, the callbacks, setDisabled, mountCheckout, and both completeCheckout methods.

Tests

  • Unit tests for the Wix mount:
    • wpe options and intentId
    • missing client_id
    • ready / loaderror button state
    • sync confirm inside the click
    • success / cancel / error paths
    • double click and setDisabled
    • mount failure cleanup and script host check
  • Type test: embedded.provider === "wix" narrows.
  • npm test -w @base44/sdk (type tests plus 501 unit tests), npm run lint and npm run build pass.

🤖 Generated with Claude Code

OleksandrSamsonov and others added 2 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>
@OleksandrSamsonov
OleksandrSamsonov marked this pull request as ready for review November 20, 2026 15:52
The checkout never sets it, so the element is created with intentId only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
}
// Runs even after destroy(), so a paid order is still completed.
const result = await deps.completeCheckout(checkoutId);
paid = true;

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.

paid is set only after completeCheckout succeeds. If the card was charged but completeCheckout then fails (e.g. a network error), finally turns the button back on and the buyer may pay again. Could we keep the button off once confirmPayment() returns "succeeded", and retry only completeCheckout?

* - Base44 Payments: Renders the Wix Payment Element and a **Pay** button below it. Style the button with its `base44-checkout-pay` class. When the payment succeeds, the SDK calls {@linkcode completeCheckout | completeCheckout()} and then `onComplete`.
*
* To make the checkout appear faster, load the library ahead of time with [`preloadCheckout()`](#preloadcheckout) when the page opens.
* For PayPal and Stripe, to make the checkout appear faster, load the library ahead of time with [`preloadCheckout()`](#preloadcheckout) when the page opens.

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.

Any reason to keep Wix out of preloadCheckout()? The script URL redirects (tpa.wixapps.net → static.parastorage.com), so most of its cost is two connections, not the 4.7KB file. Preloading it when the page opens should save a noticeable part of the wait. Happy to add it.

});
};
button.addEventListener("click", onClick);
(element as unknown as HTMLElement).appendChild(button);

@ronnyrin ronnyrin Nov 23, 2026 •

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.

forcing a button will cause multiple issues:

  1. locale
  2. if i want to have something between the element and the button? like "subscribe to newsletter and updates".
  3. we have a wrapper (the div that contains both the element and the button) that the builder can't control and design (like have two col layout where the form is on the left and button on the right)
  4. if i want to do something between the click and the checkout? we will have to support options.onClick

deps.loadScript
);
const locale = (document.documentElement?.lang || navigator.language || "en").split("-")[0];
const paymentElement = wpe(embedded.client_id, { locale }).create("checkout", {

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.

like we discussed, change to getAccessToken() instead of clientId

const config = {
paypal: { script_url: "https://www.sandbox.paypal.com/web-sdk/v6/core" },
stripe: { script_url: "https://js.stripe.com/v3/" },
wix: { script_url: "https://tpa.wixapps.net/payment-elements/payment-elements.js" },

@ronnyrin ronnyrin Nov 23, 2026 •

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.

not related to the tests but in general but i wonder why in stripe and paypal the format is different (like not specific bundle)

OleksandrSamsonov and others added 7 commits November 23, 2026 23:59
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>
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>
@amitbardos

Copy link
Copy Markdown
Contributor

@OleksandrSamsonov I pushed two commits here, as we discussed in Slack:

bb58d72: the app brings its own Pay button. The Wix element has no button, and Wix's guide leaves it to the page. A hardcoded "Pay" from the SDK can't be translated, can't have content between it and the form, and fights the app's layout (Ronny's points above). So the Wix mount no longer draws a button:

  • mount.pay() pays. The app calls it from its own button's click handler, before any await, so confirmPayment() still runs inside the click.
  • onReadyChange(ready) tells the app when to enable its button (the element's ready / loaderror).
  • pay() keeps your guards: it does nothing until the element is ready, during a payment, or after one succeeded or failed. finished is set before completeCheckout(), so a failed complete after a successful charge can't lead to a second charge (my earlier comment).
  • setDisabled() is a no-op for Wix, like Stripe, since the app disables its own button.

7bcad99: Wix in preloadCheckout(). Loads the element script when the page opens. Most of its cost is the tpa.wixapps.net redirect, not the file.

Tests, type tests and lint pass. The builder guide change that goes with it is base44-dev/apper#46903, which should merge only after this is released.

// Renewed this long before it expires, as the Payment Element does.
const WIX_TOKEN_MARGIN_MS = 60_000;

interface WixTokens {

@ronnyrin ronnyrin Nov 25, 2026 •

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.

can we use @wix/sdk for it? it should remove a lot of code from here

@OleksandrSamsonov

Copy link
Copy Markdown
Collaborator Author

Moved to #392 (opened from a branch in this repo, so it gets preview packages). The review comments here are carried over in #392 (comment).

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.

4 participants