# Wix (beta)

> **Beta.** The OnCharge Wix integration is tested against a fake OnCharge and Wix's documented payloads, but has not yet run on a live Wix site. Its [README](https://oncharge.io/docs/files/wix/README.md) is the full reference, including what remains unverified. Contact OnCharge to join the beta.

The integration is a Velo **Payment Provider service plugin** plus backend code you add to your site. It takes card payments through the OnCharge hosted checkout, keeps Wix orders in step with OnCharge, reports shipment tracking (OnCharge pays out once the carrier confirms delivery), refunds from the Wix dashboard, and serves the [RUO compliance feed](https://oncharge.io/docs/compliance-feed).

**Requirements:** a Wix premium plan that accepts payments, a connected custom domain (OnCharge accepts return URLs and webhooks only on registered domains), and Dev Mode. Wix allows this kind of plugin only on the owner's own site, not in the App Market.

## How it plugs into Wix

| Wix calls | When | The integration |
|---|---|---|
| `connectAccount()` | You select **Connect** under Accept Payments | Checks the API key and secret with a signed request. |
| `createTransaction()` | A buyer places an order | [`POST /api/v1/checkout/sessions`](https://oncharge.io/docs/api#createcheckoutsession) (with the shipping address, line items and `Idempotency-Key: wix-<transaction id>`) and sends the buyer to the OnCharge checkout. |
| `refundTransaction()` | You refund from the Orders page | [`POST /api/v1/refunds`](https://oncharge.io/docs/api#createrefund). |

Payment results reach Wix through an HTTP function that verifies the OnCharge webhook and updates the Wix transaction. Fulfillments are reported to [`POST /api/v1/shipments`](https://oncharge.io/docs/shipments), with an hourly job resending numbers OnCharge could not judge yet.

## Set up

1. **Turn on Dev Mode** in the Wix editor (Wix Studio has the code panel on by default).
2. **Add the payment plugin:** Code sidebar → **Public & Backend** → **Service Plugins** → **+** → **Payment**, named `oncharge`. Replace the generated files with the integration's.
3. **Add the backend files** from the integration package (`http-functions.js`, `events.js`, `jobs.config` and the `oncharge/` folder), and install `@wix/stores` and `@wix/essentials`.
4. **Create the CMS collection** `OnChargeLog` with admin-only permissions (fields `kind` and `data`). It holds session IDs, handled webhook IDs, compliance nonces and pending tracking numbers; no card data or secrets.
5. **Save the secrets** in **Developer Tools → Secrets Manager**: `oncharge_api_key`, `oncharge_api_secret`, `oncharge_webhook_secret` and, for RUO stores, `oncharge_compliance_code`. They are read only in backend code.
6. **Edit `backend/oncharge/config.js`**: your site's domain, policy page paths and reviewer settings.
7. **Publish the site.** Service plugins, HTTP functions and backend events run only on the published site.
8. **In the OnCharge portal:** register the site's domain under **Security → Domains**, and register `https://<your domain>/_functions/onchargeWebhook` as the store's webhook URL. Save the signing secret it shows as `oncharge_webhook_secret`, then publish again.
9. **Connect OnCharge in Wix:** Dashboard → Settings → **Accept Payments** → **See More Payment Options** → OnCharge → **Connect**. OnCharge then appears at checkout as "Credit / Debit Card".

## Endpoints

Wix names an HTTP function after its exported JavaScript function, which cannot contain a hyphen, so the paths are camel case.

| URL | Purpose |
|---|---|
| `POST https://<domain>/_functions/onchargeWebhook` | OnCharge webhooks |
| `GET https://<domain>/_functions/onchargeReturn` | Return URL of each checkout session (signed state; redirects to the matching Wix page) |
| `GET https://<domain>/_functions/onchargeCompliance/proof` | Compliance feed: ownership proof |
| `GET https://<domain>/_functions/onchargeCompliance/content` | Compliance feed: catalogue (signed) |
| `GET https://<domain>/_functions/onchargeCompliance/reviewer-access` | Compliance feed: reviewer login status (signed) |

Webhooks: `payment.captured` approves the Wix transaction after checking amount and currency; `payment.pending`, `payment.refused` and `payment.cancelled` set the matching Wix status; refund, chargeback and delivery events are logged. Refunds issued in the OnCharge portal are not mirrored into Wix.

## RUO stores: compliance review

In the OnCharge portal, add your host, choose **Wix** and set the feed base path to **`/_functions/onchargeCompliance`**. Save the connection code as `oncharge_compliance_code`, publish, then select **Verify connection**. For reviewer access, create a separate site member with the same access a verified buyer has, set its login email in `config.js`, sign in as it once to check it shows every product with its price, confirm it in `config.js` and publish.

## Notes

- All OnCharge API calls run in backend code, where the secrets are available. Page code never sees them.
- Use USPS, UPS, FedEx or DHL Express in Wix fulfillments so OnCharge can confirm delivery; other carriers are sent without a carrier name.
