Standalone browser SDK for embedding AnyCac cart, checkout, and payment return flows into external storefronts.
Load the SDK from your Cloudflare-hosted URL:
<script src="https://anycac-sdk.pages.dev/public/anycac.js"></script>If you later attach a custom domain, replace the hosted URL with your own host.
- This repo deploys as a tiny Worker that serves static assets from
public/ public/anycac.jsis currently served at/public/anycac.jsworker.jsdoes not run business logic; it only forwards requests to the static asset binding- This setup is useful when your platform forces
npx wrangler deploy - After deploy, the SDK is available at
https://anycac-sdk.pages.dev/public/anycac.js
If your deploy environment forces npx wrangler deploy, this repository is now configured for that flow.
If you deploy from the CLI, use:
npx wrangler deployThis keeps the repo minimal: one SDK file plus documentation.
This guide explains how customers can integrate the AnyCac SDK into their website.
AnyCac SDK lets you:
- Add products to Woo cart from your own UI
- Open a right-side cart slider from any trigger element
- Embed cart, checkout, and return (thank you) pages in your site
- Handle PayPal/Stripe redirect returns automatically
Your payment backend stays in Woo with the AnyCac-compatible WooCommerce plugin.
Use your deployed Cloudflare SDK URL:
<script src="https://anycac-sdk.pages.dev/public/anycac.js"></script>If you attach a custom domain, use that instead.
Call AnyCac.init() once on page load.
AnyCac.init({
paymentStore: 'https://woo-store.test', // required
autoRouteCallbacks: true, // optional (default: true)
autoMount: true, // optional (default: true)
cartTrigger: '#anycacCartTrigger', // optional
routes: {
cart: { path: '/cart', container: '#cartFrame' }, // path required, container optional
checkout: { path: '/checkout', container: '#checkoutFrame' }, // path required, container optional
return: { path: '/thank-you', container: '#thankYouFrame' } // path required, container optional
},
storageKey: 'anycac_payment_state' // optional
})paymentStore(string, required)- Base URL of your Woo payment store
autoRouteCallbacks(boolean, defaulttrue)- Auto-detects return query params and routes to checkout/thank-you pages
autoMount(boolean, defaulttrue)- Auto-mounts iframe for current configured route
cartTrigger(string | Element | NodeList | Element[])- Click trigger(s) that open cart slider
routescart.path,checkout.path,return.path- Optional
containerselector for embedding iframe into existing element
storageKey(string, optional)- Session storage key used internally for payment redirect state
Use AnyCac.addToCart(payload) from your product card/button.
AnyCac.addToCart({
name: 'Premium T-Shirt',
price: 29.99,
sku: 'TSHIRT-2026',
quantity: 1,
url: 'https://example.com/products/premium-tshirt',
image_url: 'https://example.com/image.jpg',
extra: { color: 'White', size: 'M' },
meta: { source: 'landing-page' }
}, { openSlider: true })Options:
openSlider: true(default behavior)openModal: falseandopenSlider: falseto send command without opening slider
If you pass cartTrigger, SDK binds click automatically.
<button id="anycacCartTrigger">Cart</button>You can also bind manually:
AnyCac.bindCartTrigger('#anycacCartTrigger')Open programmatically:
AnyCac.openCartSlider()Create 3 site routes/pages:
- Cart page (
/cart) - Checkout page (
/checkout) - Return/Thank-you page (
/thank-you)
Each page should have an iframe container or let SDK mount into document.body.
<div class="native-frame">
<iframe id="checkoutFrame"></iframe>
</div>
<script>
AnyCac.init({
paymentStore: 'https://woo-store.test',
routes: {
cart: { path: '/cart', container: '#cartFrame' },
checkout: { path: '/checkout', container: '#checkoutFrame' },
return: { path: '/thank-you', container: '#thankYouFrame' }
}
})
</script>If the provider returns to /checkout.html or /thank-you.html, add redirects:
/checkout.html->/checkout/cart.html->/cart/thank-you.html->/thank-you
Subscribe with:
AnyCac.on('cart.added', handler)
AnyCac.on('cart.error', handler)
AnyCac.on('payment.redirect', handler)
AnyCac.on('payment.complete', handler)
AnyCac.on('modal.opened', handler)
AnyCac.on('modal.closed', handler)
AnyCac.on('transport.response', handler)Unsubscribe:
AnyCac.off('cart.added', handler)Expected flow:
- Customer checkout in embedded iframe
- Redirect to payment provider in top window
- Provider returns to store callback URL with params
- SDK detects params and routes to configured
returnorcheckout - Woo callback is forwarded into iframe (
anycac_iframe_forward=1) to finalize and show thank-you
If callback lands on legacy .html paths, route those paths to your real frontend routes.
AnyCac.init(config)AnyCac.addToCart(payload, options)AnyCac.openCartSlider()AnyCac.openCartModal()AnyCac.openModal(url, title)AnyCac.closeModal()AnyCac.routePaymentCallbacks()AnyCac.mountCart(target)AnyCac.mountCheckout(target)AnyCac.mountReturn(target)AnyCac.mountCurrentRoute()AnyCac.bindCartTrigger(trigger)AnyCac.on(event, handler)AnyCac.off(event, handler)AnyCac.version
- Callback stays on homepage or root
- Ensure
autoRouteCallbacks: true - Ensure route paths in config match real frontend paths
- Ensure
- Cart slider opens but add-to-cart appears delayed
- Woo iframe still needs AJAX and render time; this is expected
- Stripe opens inside iframe
- Ensure the payment store correctly redirects the top window for hosted checkout flows
- Thank-you not shown
- Confirm return params are routed to
return.path - Ensure the
returnpage container exists if using an explicitcontainer
- Confirm return params are routed to
- Add the AnyCac script to all shop, cart, checkout, and return pages
- Add one
AnyCac.init(...)call on app boot - Configure
routesto your real frontend paths - Add a nav cart icon and set
cartTrigger - Wire product buttons to
AnyCac.addToCart(...) - Verify full PayPal and Stripe round-trip in sandbox