@colixsystems/widget-sdk 0.293.0 → 0.295.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/dist/contract.cjs +12 -2
- package/dist/contract.js +12 -2
- package/dist/hooks.js +34 -26
- package/dist/index.d.ts +31 -1
- package/package.json +1 -1
- package/src/contract.js +12 -2
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
76
76
|
| **FILESTORE** (`ctx.filestore`) | `usePdfExport({ spaceType, folderId })` (optional: spaceType, folderId) | `{ openPdf, opening, canOpenPdf, exportToPdf, exporting, error, lastExported }` | `ctx.filestore.files.renderPdf` + `ctx.device.pdfViewer`, `ctx.filestore.files.exportPdf` — `files.write:*`. `openPdf(html, { fileName? })` renders the HTML to a PDF server-side and OPENS it (web: PDF tab; native: print / share sheet) without saving. `exportToPdf(html, { fileName?, folderId? })` renders it and saves it as a file (`application/pdf`). Same server-side renderer on web + native. |
|
|
77
77
|
| **PAYMENTS** (`ctx.payments`) | `useAccessPlans()` | `{ plans, loading, error, purchaseAvailable, purchase, cancel, refresh }` | `ctx.payments.{listAccessPlans,purchaseAccessPlan,cancelAccessPlan}` — `payments.charge:appUser`. Plans selling access to restricted pages; `purchase(planId)` names only the plan, the server sets price and group. `purchaseAvailable` is `false` in an iOS / Android build (digital goods need store billing): show a visible not-available state. |
|
|
78
78
|
| **PAYMENTS** (`ctx.payments`) | `useAppSubscription()` | `{ subscription, loading, error, cancel, refresh }` | `ctx.payments.{getAppSubscription,cancelAppSubscription}` — `payments.charge:appUser`. The signed-in user's subscription to a paid app (`{ active, renews, access_ends_at }`); `cancel()` stops it renewing, and access runs to `access_ends_at`. |
|
|
79
|
-
| **PAYMENTS** (`ctx.payments`) | `usePayments()` | `{ requestPayment, getPayment }` | `ctx.payments.*` — `payments.charge:appUser`. `requestPayment` requires `kind` (`"physical"` \| `"service"` \| `"digital"`): what is sold. A `"digital"` charge is refused in an iOS or Android build (`DIGITAL_SALE_NEEDS_STORE_BILLING`). Rejects with `PaymentError { code, message, retryable }`; when `retryable` is `false` show `message` and drop the retry. Charges are accepted ONLY in the currency the workspace sells in — omit `currency` and the platform applies it (a disagreeing literal is a publish-blocking `payment-currency` finding). |
|
|
79
|
+
| **PAYMENTS** (`ctx.payments`) | `usePayments()` | `{ requestPayment, getPayment, requestGuestPayment, getGuestPayment }` | `ctx.payments.*` — `payments.charge:appUser`; guest checkout (`requestGuestPayment`, a visitor with no account buying physical goods for an order they created) also `payments.charge:guest`. `requestPayment` requires `kind` (`"physical"` \| `"service"` \| `"digital"`): what is sold. A `"digital"` charge is refused in an iOS or Android build (`DIGITAL_SALE_NEEDS_STORE_BILLING`). Rejects with `PaymentError { code, message, retryable }`; when `retryable` is `false` show `message` and drop the retry. Charges are accepted ONLY in the currency the workspace sells in — omit `currency` and the platform applies it (a disagreeing literal is a publish-blocking `payment-currency` finding). |
|
|
80
80
|
| **NOTIFICATIONS** (`ctx.notifications`) | `useSendNotification()` | `{ send, sending, error }` | `ctx.notifications.send` — `notifications.send:appUser`. `send({ recipient_user_id, title, body, link?, payload? })` notifies one app user in the same workspace; call from an event handler (never render); rejects with `NotificationError`. |
|
|
81
81
|
| **NOTIFICATIONS** (`ctx.notifications`) | `useRecordMutes(tableId)` | `{ isMuted, loading, error, refetch }` | `ctx.notifications.mutes` — no scope. Which records of one table the signed-in user has muted, in one request for a whole list; `isMuted(recordId)` turns false when a timed mute lapses, and a `useRecordMute` write shows at once. |
|
|
82
82
|
| **NOTIFICATIONS** (`ctx.notifications`) | `useRecordMute(tableId, recordId)` | `{ muted, mutedUntil, loading, error, mute, unmute, refetch }` | `ctx.notifications.mutes` — no scope. Mutes one record's notifications for the signed-in user, `mute(until)` with an ISO time, a `Date`, or `null` for until unmuted. Needs read access to the record (`RECORD_NOT_FOUND` otherwise). |
|
|
@@ -90,7 +90,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
90
90
|
|
|
91
91
|
## Status
|
|
92
92
|
|
|
93
|
-
`v0.
|
|
93
|
+
`v0.295.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
94
|
+
|
|
95
|
+
### What's new in 0.295.0 (contract 1.242.0)
|
|
96
|
+
|
|
97
|
+
**Guest checkout: a visitor who is not signed in can pay for physical goods.** `usePayments()` gains `requestGuestPayment({ amount_cents, currency?, description, return_path?, order })` and `getGuestPayment(paymentId)`. There is no `kind`: a guest buys physical goods only, and the shipping address and contact live on the order. So `order` is required, and it must be a row the visitor created with `useDatastoreMutation().create` in the last 15 minutes, in a table with a payment-status column that the maker lets everyone add rows to (and nobody read). Only that visitor can pay for it. The host runs a security check, opens hosted Checkout as for `requestPayment`, and keeps the guest's one-time credential; `getGuestPayment(id)` reads the payment back with it, so a widget passes only the id. The widget also needs the `payments.charge:guest` scope, and the workspace must offer guest checkout. New `PaymentError` codes: `TRIAL_RESTRICTED` (non-retryable), and the retryable `GUEST_CHECKOUT_LIMIT_REACHED`, `CAPTCHA_FAILED` and `CAPTCHA_UNAVAILABLE`. The injected payments client gains `requestGuestPayment()` and `getGuestPayment()` (`@colixsystems/payments-client` 0.7.0). Additive.
|
|
94
98
|
|
|
95
99
|
### What's new in 0.293.0 (contract 1.240.0)
|
|
96
100
|
|
package/dist/contract.cjs
CHANGED
|
@@ -2428,6 +2428,10 @@ const HOOKS = [
|
|
|
2428
2428
|
"({ amount_cents, currency?, description, kind, return_path?, order? }) => Promise<{ id, status, order }> // kind is REQUIRED: \"physical\" | \"service\" | \"digital\" — what is sold; a digital charge is refused in an iOS/Android build (DIGITAL_SALE_NEEDS_STORE_BILLING); order: { table_id, record_id } — the order row this pays for, in a table with a payment-status column; the SERVER marks it paid when the payment settles, so never write \"paid\" yourself (refused: ORDER_NOT_FOUND, ORDER_NOT_PAYABLE, ORDER_ALREADY_PAID; ORDER_PAYMENT_IN_PROGRESS is retryable while another checkout for the order is open); host opens hosted Checkout; rejects with PaymentError { code, message, retryable } — render the message when retryable is false, never \"try again\"",
|
|
2429
2429
|
getPayment:
|
|
2430
2430
|
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // order: { table_id, record_id } | null — read it after returning from Checkout",
|
|
2431
|
+
requestGuestPayment:
|
|
2432
|
+
"({ amount_cents, currency?, description, return_path?, order }) => Promise<{ id, status, order }> // a visitor who is NOT signed in buys physical goods (no kind). order is REQUIRED: create the order row first with useDatastoreMutation().create (the maker lets everyone add rows to the orders table and nobody read them; collect the shipping address and contact there), then pay for it within 15 minutes — only the visitor who created it can. Needs the payments.charge:guest scope too. The host runs a security check and opens hosted Checkout. Refused: TRIAL_RESTRICTED, GUEST_CHECKOUT_LIMIT_REACHED (retryable), CAPTCHA_FAILED / CAPTCHA_UNAVAILABLE (retryable), NOT_FOUND where the shop does not offer guest checkout, plus the requestPayment refusals",
|
|
2433
|
+
getGuestPayment:
|
|
2434
|
+
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // a guest's status read; the host holds the guest's one-time credential, so pass only the id",
|
|
2431
2435
|
},
|
|
2432
2436
|
requiredContextSlice: ["payments.requestPayment"],
|
|
2433
2437
|
scopes: ["payments.charge:appUser"],
|
|
@@ -4531,11 +4535,13 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
4531
4535
|
},
|
|
4532
4536
|
payments: {
|
|
4533
4537
|
description:
|
|
4534
|
-
"Injected @colixsystems/payments-client instance (REQ-BILL-07-WIDGETPAY). { requestPayment(body) -> Promise<{ id, status }>, getPayment(id) -> Promise<payment>, listAccessPlans() -> Promise<{ data, meta }>, purchaseAccessPlan({ plan_id, return_path? }) -> Promise<{ plan_id, status }>, cancelAccessPlan(planId) -> Promise<{ plan_id, renews, access_ends_at }>, getAppSubscription() -> Promise<{ active, renews, access_ends_at }>, cancelAppSubscription() -> Promise<{ active, renews, access_ends_at }> }; wire is snake_case (amount_cents, return_path, order). Backs usePayments(), useAccessPlans() and useAppSubscription(); requires the payments.charge:appUser scope. The host opens hosted Checkout itself — same-tab on web, in-app browser on native (or auto-confirms under the mock provider); the charge settles to the workspace owner.",
|
|
4538
|
+
"Injected @colixsystems/payments-client instance (REQ-BILL-07-WIDGETPAY). { requestPayment(body) -> Promise<{ id, status }>, getPayment(id) -> Promise<payment>, requestGuestPayment(body) -> Promise<{ id, status }>, getGuestPayment(id) -> Promise<payment>, listAccessPlans() -> Promise<{ data, meta }>, purchaseAccessPlan({ plan_id, return_path? }) -> Promise<{ plan_id, status }>, cancelAccessPlan(planId) -> Promise<{ plan_id, renews, access_ends_at }>, getAppSubscription() -> Promise<{ active, renews, access_ends_at }>, cancelAppSubscription() -> Promise<{ active, renews, access_ends_at }> }; wire is snake_case (amount_cents, return_path, order). Backs usePayments(), useAccessPlans() and useAppSubscription(); requires the payments.charge:appUser scope, and guest checkout (requestGuestPayment, a visitor with no account buying physical goods) also payments.charge:guest. The host opens hosted Checkout itself — same-tab on web, in-app browser on native (or auto-confirms under the mock provider); the charge settles to the workspace owner.",
|
|
4535
4539
|
required: true,
|
|
4536
4540
|
fields: {
|
|
4537
4541
|
requestPayment: "function",
|
|
4538
4542
|
getPayment: "function",
|
|
4543
|
+
requestGuestPayment: "function",
|
|
4544
|
+
getGuestPayment: "function",
|
|
4539
4545
|
listAccessPlans: "function",
|
|
4540
4546
|
purchaseAccessPlan: "function",
|
|
4541
4547
|
cancelAccessPlan: "function",
|
|
@@ -6821,7 +6827,11 @@ const CONTRACT = deepFreeze({
|
|
|
6821
6827
|
// 1.239.0: additive (sc-15658) — an app-triggered run must finish within 250 ms
|
|
6822
6828
|
// of the press; `useAction` errors carry the new code ACTION_TIMEOUT
|
|
6823
6829
|
// (504), whose outcome is unknown.
|
|
6824
|
-
|
|
6830
|
+
// 1.242.0: additive (sc-15359) — `usePayments()` gains
|
|
6831
|
+
// `requestGuestPayment` / `getGuestPayment` (a visitor with no account
|
|
6832
|
+
// pays for an order they created), the payments slice gains both, the
|
|
6833
|
+
// `payments.charge:guest` scope, and four new PaymentError codes.
|
|
6834
|
+
version: "1.242.0",
|
|
6825
6835
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6826
6836
|
hooks: HOOKS,
|
|
6827
6837
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -2424,6 +2424,10 @@ const HOOKS = [
|
|
|
2424
2424
|
"({ amount_cents, currency?, description, kind, return_path?, order? }) => Promise<{ id, status, order }> // kind is REQUIRED: \"physical\" | \"service\" | \"digital\" — what is sold; a digital charge is refused in an iOS/Android build (DIGITAL_SALE_NEEDS_STORE_BILLING); order: { table_id, record_id } — the order row this pays for, in a table with a payment-status column; the SERVER marks it paid when the payment settles, so never write \"paid\" yourself (refused: ORDER_NOT_FOUND, ORDER_NOT_PAYABLE, ORDER_ALREADY_PAID; ORDER_PAYMENT_IN_PROGRESS is retryable while another checkout for the order is open); host opens hosted Checkout; rejects with PaymentError { code, message, retryable } — render the message when retryable is false, never \"try again\"",
|
|
2425
2425
|
getPayment:
|
|
2426
2426
|
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // order: { table_id, record_id } | null — read it after returning from Checkout",
|
|
2427
|
+
requestGuestPayment:
|
|
2428
|
+
"({ amount_cents, currency?, description, return_path?, order }) => Promise<{ id, status, order }> // a visitor who is NOT signed in buys physical goods (no kind). order is REQUIRED: create the order row first with useDatastoreMutation().create (the maker lets everyone add rows to the orders table and nobody read them; collect the shipping address and contact there), then pay for it within 15 minutes — only the visitor who created it can. Needs the payments.charge:guest scope too. The host runs a security check and opens hosted Checkout. Refused: TRIAL_RESTRICTED, GUEST_CHECKOUT_LIMIT_REACHED (retryable), CAPTCHA_FAILED / CAPTCHA_UNAVAILABLE (retryable), NOT_FOUND where the shop does not offer guest checkout, plus the requestPayment refusals",
|
|
2429
|
+
getGuestPayment:
|
|
2430
|
+
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // a guest's status read; the host holds the guest's one-time credential, so pass only the id",
|
|
2427
2431
|
},
|
|
2428
2432
|
requiredContextSlice: ["payments.requestPayment"],
|
|
2429
2433
|
scopes: ["payments.charge:appUser"],
|
|
@@ -4527,11 +4531,13 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
4527
4531
|
},
|
|
4528
4532
|
payments: {
|
|
4529
4533
|
description:
|
|
4530
|
-
"Injected @colixsystems/payments-client instance (REQ-BILL-07-WIDGETPAY). { requestPayment(body) -> Promise<{ id, status }>, getPayment(id) -> Promise<payment>, listAccessPlans() -> Promise<{ data, meta }>, purchaseAccessPlan({ plan_id, return_path? }) -> Promise<{ plan_id, status }>, cancelAccessPlan(planId) -> Promise<{ plan_id, renews, access_ends_at }>, getAppSubscription() -> Promise<{ active, renews, access_ends_at }>, cancelAppSubscription() -> Promise<{ active, renews, access_ends_at }> }; wire is snake_case (amount_cents, return_path, order). Backs usePayments(), useAccessPlans() and useAppSubscription(); requires the payments.charge:appUser scope. The host opens hosted Checkout itself — same-tab on web, in-app browser on native (or auto-confirms under the mock provider); the charge settles to the workspace owner.",
|
|
4534
|
+
"Injected @colixsystems/payments-client instance (REQ-BILL-07-WIDGETPAY). { requestPayment(body) -> Promise<{ id, status }>, getPayment(id) -> Promise<payment>, requestGuestPayment(body) -> Promise<{ id, status }>, getGuestPayment(id) -> Promise<payment>, listAccessPlans() -> Promise<{ data, meta }>, purchaseAccessPlan({ plan_id, return_path? }) -> Promise<{ plan_id, status }>, cancelAccessPlan(planId) -> Promise<{ plan_id, renews, access_ends_at }>, getAppSubscription() -> Promise<{ active, renews, access_ends_at }>, cancelAppSubscription() -> Promise<{ active, renews, access_ends_at }> }; wire is snake_case (amount_cents, return_path, order). Backs usePayments(), useAccessPlans() and useAppSubscription(); requires the payments.charge:appUser scope, and guest checkout (requestGuestPayment, a visitor with no account buying physical goods) also payments.charge:guest. The host opens hosted Checkout itself — same-tab on web, in-app browser on native (or auto-confirms under the mock provider); the charge settles to the workspace owner.",
|
|
4531
4535
|
required: true,
|
|
4532
4536
|
fields: {
|
|
4533
4537
|
requestPayment: "function",
|
|
4534
4538
|
getPayment: "function",
|
|
4539
|
+
requestGuestPayment: "function",
|
|
4540
|
+
getGuestPayment: "function",
|
|
4535
4541
|
listAccessPlans: "function",
|
|
4536
4542
|
purchaseAccessPlan: "function",
|
|
4537
4543
|
cancelAccessPlan: "function",
|
|
@@ -6817,7 +6823,11 @@ const CONTRACT = deepFreeze({
|
|
|
6817
6823
|
// 1.239.0: additive (sc-15658) — an app-triggered run must finish within 250 ms
|
|
6818
6824
|
// of the press; `useAction` errors carry the new code ACTION_TIMEOUT
|
|
6819
6825
|
// (504), whose outcome is unknown.
|
|
6820
|
-
|
|
6826
|
+
// 1.242.0: additive (sc-15359) — `usePayments()` gains
|
|
6827
|
+
// `requestGuestPayment` / `getGuestPayment` (a visitor with no account
|
|
6828
|
+
// pays for an order they created), the payments slice gains both, the
|
|
6829
|
+
// `payments.charge:guest` scope, and four new PaymentError codes.
|
|
6830
|
+
version: "1.242.0",
|
|
6821
6831
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6822
6832
|
hooks: HOOKS,
|
|
6823
6833
|
primitives: PRIMITIVES,
|
package/dist/hooks.js
CHANGED
|
@@ -7008,6 +7008,7 @@ const NON_RETRYABLE_PAYMENT_CODES = new Set([
|
|
|
7008
7008
|
"PAYMENTS_DISABLED",
|
|
7009
7009
|
"PAYMENTS_SCOPE_NOT_GRANTED",
|
|
7010
7010
|
"PAYMENTS_UNAVAILABLE",
|
|
7011
|
+
"TRIAL_RESTRICTED",
|
|
7011
7012
|
"UNSUPPORTED_CURRENCY",
|
|
7012
7013
|
"VALIDATION",
|
|
7013
7014
|
]);
|
|
@@ -7036,6 +7037,9 @@ const NON_RETRYABLE_PAYMENT_CODES = new Set([
|
|
|
7036
7037
|
* `order` is not one this user can pay for
|
|
7037
7038
|
* - "ORDER_PAYMENT_IN_PROGRESS" — another checkout for the order is open
|
|
7038
7039
|
* (retryable: it clears when that one ends)
|
|
7040
|
+
* - "TRIAL_RESTRICTED" — a trial workspace takes no guest payments
|
|
7041
|
+
* - "GUEST_CHECKOUT_LIMIT_REACHED" — the shop's guest budget is spent for now
|
|
7042
|
+
* - "CAPTCHA_FAILED" / "CAPTCHA_UNAVAILABLE" — the guest's security check
|
|
7039
7043
|
* - "CONNECT_NOT_READY" / "PAYMENTS_DISABLED" — provider not ready
|
|
7040
7044
|
* - "DECLINED" — the charge was declined
|
|
7041
7045
|
* - "INTERNAL" — anything else
|
|
@@ -7135,6 +7139,23 @@ function toPaymentError(err) {
|
|
|
7135
7139
|
* Mollie webhook may land a moment after the redirect; if it is still `PENDING`
|
|
7136
7140
|
* when you give up, show a "still processing" state rather than "paid".
|
|
7137
7141
|
*
|
|
7142
|
+
* GUEST CHECKOUT — a visitor who is NOT signed in buys physical goods:
|
|
7143
|
+
* requestGuestPayment({ amount_cents, currency?, description, return_path?,
|
|
7144
|
+
* order }) → Promise<{ id, status, order, ... }>. Create the order row
|
|
7145
|
+
* first with `useDatastoreMutation().create` (the maker gives everyone
|
|
7146
|
+
* permission to add rows to the orders table, and no permission to read
|
|
7147
|
+
* them), then pass its `{ table_id, record_id }` as `order` within 15
|
|
7148
|
+
* minutes — it is REQUIRED, and only the visitor who created it can pay for
|
|
7149
|
+
* it. Collect the shipping address and contact on that order row. There is
|
|
7150
|
+
* no `kind`: guest checkout sells physical goods only. The host runs a
|
|
7151
|
+
* security check and opens hosted Checkout exactly as for requestPayment.
|
|
7152
|
+
* getGuestPayment(paymentId) → Promise<payment> — the same read for a guest;
|
|
7153
|
+
* the host holds the guest's one-time credential, so pass only the id.
|
|
7154
|
+
* Requires the `payments.charge:guest` scope as well. Refusals beyond the
|
|
7155
|
+
* charge refusals: TRIAL_RESTRICTED, GUEST_CHECKOUT_LIMIT_REACHED (retryable),
|
|
7156
|
+
* CAPTCHA_FAILED / CAPTCHA_UNAVAILABLE (retryable), and NOT_FOUND where the
|
|
7157
|
+
* workspace does not offer guest checkout.
|
|
7158
|
+
*
|
|
7138
7159
|
* Requires the `payments.charge:appUser` scope in the manifest's
|
|
7139
7160
|
* `requestedScopes`. The charge settles to the workspace owner; the app user
|
|
7140
7161
|
* confirms the amount in hosted Checkout. No card data touches the widget —
|
|
@@ -7149,39 +7170,26 @@ export function usePayments() {
|
|
|
7149
7170
|
"workspace whose host supports payments.",
|
|
7150
7171
|
);
|
|
7151
7172
|
}
|
|
7152
|
-
const
|
|
7153
|
-
|
|
7154
|
-
typeof ctx.payments.getPayment === "function"
|
|
7155
|
-
? ctx.payments.getPayment
|
|
7156
|
-
: null,
|
|
7157
|
-
);
|
|
7158
|
-
requestRef.current = ctx.payments.requestPayment;
|
|
7159
|
-
getRef.current =
|
|
7160
|
-
typeof ctx.payments.getPayment === "function"
|
|
7161
|
-
? ctx.payments.getPayment
|
|
7162
|
-
: null;
|
|
7173
|
+
const paymentsRef = useRef(ctx.payments);
|
|
7174
|
+
paymentsRef.current = ctx.payments;
|
|
7163
7175
|
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
throw
|
|
7169
|
-
}
|
|
7170
|
-
}, []);
|
|
7171
|
-
const getPayment = useCallback(async (paymentId) => {
|
|
7172
|
-
if (!getRef.current) {
|
|
7173
|
-
throw new PaymentError(
|
|
7174
|
-
"INTERNAL",
|
|
7175
|
-
"getPayment is not supported by this host.",
|
|
7176
|
-
);
|
|
7176
|
+
// Read the host's method at call time: the host may rebuild its slice.
|
|
7177
|
+
const call = useCallback(async (name, args) => {
|
|
7178
|
+
const method = paymentsRef.current[name];
|
|
7179
|
+
if (typeof method !== "function") {
|
|
7180
|
+
throw new PaymentError("INTERNAL", `${name} is not supported by this host.`);
|
|
7177
7181
|
}
|
|
7178
7182
|
try {
|
|
7179
|
-
return await
|
|
7183
|
+
return await method(...args);
|
|
7180
7184
|
} catch (err) {
|
|
7181
7185
|
throw toPaymentError(err);
|
|
7182
7186
|
}
|
|
7183
7187
|
}, []);
|
|
7184
|
-
|
|
7188
|
+
const requestPayment = useCallback((args) => call("requestPayment", [args]), [call]);
|
|
7189
|
+
const getPayment = useCallback((paymentId) => call("getPayment", [paymentId]), [call]);
|
|
7190
|
+
const requestGuestPayment = useCallback((args) => call("requestGuestPayment", [args]), [call]);
|
|
7191
|
+
const getGuestPayment = useCallback((paymentId) => call("getGuestPayment", [paymentId]), [call]);
|
|
7192
|
+
return { requestPayment, getPayment, requestGuestPayment, getGuestPayment };
|
|
7185
7193
|
}
|
|
7186
7194
|
|
|
7187
7195
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1569,9 +1569,34 @@ export interface PaymentResult {
|
|
|
1569
1569
|
order?: PaymentOrder | null;
|
|
1570
1570
|
}
|
|
1571
1571
|
|
|
1572
|
+
/**
|
|
1573
|
+
* A visitor who is not signed in paying for physical goods. There is no
|
|
1574
|
+
* `kind`: guest checkout sells physical goods only.
|
|
1575
|
+
*/
|
|
1576
|
+
export interface GuestPaymentRequest {
|
|
1577
|
+
amount_cents: number;
|
|
1578
|
+
currency?: string;
|
|
1579
|
+
description: string;
|
|
1580
|
+
return_path?: string;
|
|
1581
|
+
/**
|
|
1582
|
+
* Required. The order row the visitor created with
|
|
1583
|
+
* `useDatastoreMutation().create` in the last 15 minutes, in a table with a
|
|
1584
|
+
* payment-status column that everyone may add rows to. Collect the shipping
|
|
1585
|
+
* address and contact on it.
|
|
1586
|
+
*/
|
|
1587
|
+
order: PaymentOrder;
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1572
1590
|
export interface PaymentsApi {
|
|
1573
1591
|
requestPayment(args: PaymentRequest): Promise<PaymentResult>;
|
|
1574
1592
|
getPayment(paymentId: string): Promise<PaymentResult>;
|
|
1593
|
+
/**
|
|
1594
|
+
* Guest checkout. Requires the `payments.charge:guest` scope as well. The
|
|
1595
|
+
* host runs a security check and opens hosted Checkout.
|
|
1596
|
+
*/
|
|
1597
|
+
requestGuestPayment(args: GuestPaymentRequest): Promise<PaymentResult>;
|
|
1598
|
+
/** A guest's status read; the host holds their credential, so pass only the id. */
|
|
1599
|
+
getGuestPayment(paymentId: string): Promise<PaymentResult>;
|
|
1575
1600
|
}
|
|
1576
1601
|
|
|
1577
1602
|
/**
|
|
@@ -1581,7 +1606,8 @@ export interface PaymentsApi {
|
|
|
1581
1606
|
* redirect on web, the in-app browser on native) — you never open a URL and
|
|
1582
1607
|
* never collect card data. Confirm completion from server state (the webhook
|
|
1583
1608
|
* flips your record) or poll `getPayment(id)`. The charge settles to the
|
|
1584
|
-
* workspace owner.
|
|
1609
|
+
* workspace owner. A visitor who is not signed in pays with
|
|
1610
|
+
* `requestGuestPayment`, which also needs the `payments.charge:guest` scope.
|
|
1585
1611
|
*/
|
|
1586
1612
|
export function usePayments(): PaymentsApi;
|
|
1587
1613
|
|
|
@@ -1682,6 +1708,10 @@ export class PaymentError extends Error {
|
|
|
1682
1708
|
| "ORDER_NOT_PAYABLE"
|
|
1683
1709
|
| "ORDER_ALREADY_PAID"
|
|
1684
1710
|
| "ORDER_PAYMENT_IN_PROGRESS"
|
|
1711
|
+
| "TRIAL_RESTRICTED"
|
|
1712
|
+
| "GUEST_CHECKOUT_LIMIT_REACHED"
|
|
1713
|
+
| "CAPTCHA_FAILED"
|
|
1714
|
+
| "CAPTCHA_UNAVAILABLE"
|
|
1685
1715
|
| "PAYMENTS_DISABLED"
|
|
1686
1716
|
| "DECLINED"
|
|
1687
1717
|
| "FORBIDDEN"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.295.0",
|
|
4
4
|
"description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
|
|
5
5
|
"homepage": "https://github.com/Colix-AB/AppStudio",
|
|
6
6
|
"type": "module",
|
package/src/contract.js
CHANGED
|
@@ -2424,6 +2424,10 @@ const HOOKS = [
|
|
|
2424
2424
|
"({ amount_cents, currency?, description, kind, return_path?, order? }) => Promise<{ id, status, order }> // kind is REQUIRED: \"physical\" | \"service\" | \"digital\" — what is sold; a digital charge is refused in an iOS/Android build (DIGITAL_SALE_NEEDS_STORE_BILLING); order: { table_id, record_id } — the order row this pays for, in a table with a payment-status column; the SERVER marks it paid when the payment settles, so never write \"paid\" yourself (refused: ORDER_NOT_FOUND, ORDER_NOT_PAYABLE, ORDER_ALREADY_PAID; ORDER_PAYMENT_IN_PROGRESS is retryable while another checkout for the order is open); host opens hosted Checkout; rejects with PaymentError { code, message, retryable } — render the message when retryable is false, never \"try again\"",
|
|
2425
2425
|
getPayment:
|
|
2426
2426
|
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // order: { table_id, record_id } | null — read it after returning from Checkout",
|
|
2427
|
+
requestGuestPayment:
|
|
2428
|
+
"({ amount_cents, currency?, description, return_path?, order }) => Promise<{ id, status, order }> // a visitor who is NOT signed in buys physical goods (no kind). order is REQUIRED: create the order row first with useDatastoreMutation().create (the maker lets everyone add rows to the orders table and nobody read them; collect the shipping address and contact there), then pay for it within 15 minutes — only the visitor who created it can. Needs the payments.charge:guest scope too. The host runs a security check and opens hosted Checkout. Refused: TRIAL_RESTRICTED, GUEST_CHECKOUT_LIMIT_REACHED (retryable), CAPTCHA_FAILED / CAPTCHA_UNAVAILABLE (retryable), NOT_FOUND where the shop does not offer guest checkout, plus the requestPayment refusals",
|
|
2429
|
+
getGuestPayment:
|
|
2430
|
+
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // a guest's status read; the host holds the guest's one-time credential, so pass only the id",
|
|
2427
2431
|
},
|
|
2428
2432
|
requiredContextSlice: ["payments.requestPayment"],
|
|
2429
2433
|
scopes: ["payments.charge:appUser"],
|
|
@@ -4527,11 +4531,13 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
4527
4531
|
},
|
|
4528
4532
|
payments: {
|
|
4529
4533
|
description:
|
|
4530
|
-
"Injected @colixsystems/payments-client instance (REQ-BILL-07-WIDGETPAY). { requestPayment(body) -> Promise<{ id, status }>, getPayment(id) -> Promise<payment>, listAccessPlans() -> Promise<{ data, meta }>, purchaseAccessPlan({ plan_id, return_path? }) -> Promise<{ plan_id, status }>, cancelAccessPlan(planId) -> Promise<{ plan_id, renews, access_ends_at }>, getAppSubscription() -> Promise<{ active, renews, access_ends_at }>, cancelAppSubscription() -> Promise<{ active, renews, access_ends_at }> }; wire is snake_case (amount_cents, return_path, order). Backs usePayments(), useAccessPlans() and useAppSubscription(); requires the payments.charge:appUser scope. The host opens hosted Checkout itself — same-tab on web, in-app browser on native (or auto-confirms under the mock provider); the charge settles to the workspace owner.",
|
|
4534
|
+
"Injected @colixsystems/payments-client instance (REQ-BILL-07-WIDGETPAY). { requestPayment(body) -> Promise<{ id, status }>, getPayment(id) -> Promise<payment>, requestGuestPayment(body) -> Promise<{ id, status }>, getGuestPayment(id) -> Promise<payment>, listAccessPlans() -> Promise<{ data, meta }>, purchaseAccessPlan({ plan_id, return_path? }) -> Promise<{ plan_id, status }>, cancelAccessPlan(planId) -> Promise<{ plan_id, renews, access_ends_at }>, getAppSubscription() -> Promise<{ active, renews, access_ends_at }>, cancelAppSubscription() -> Promise<{ active, renews, access_ends_at }> }; wire is snake_case (amount_cents, return_path, order). Backs usePayments(), useAccessPlans() and useAppSubscription(); requires the payments.charge:appUser scope, and guest checkout (requestGuestPayment, a visitor with no account buying physical goods) also payments.charge:guest. The host opens hosted Checkout itself — same-tab on web, in-app browser on native (or auto-confirms under the mock provider); the charge settles to the workspace owner.",
|
|
4531
4535
|
required: true,
|
|
4532
4536
|
fields: {
|
|
4533
4537
|
requestPayment: "function",
|
|
4534
4538
|
getPayment: "function",
|
|
4539
|
+
requestGuestPayment: "function",
|
|
4540
|
+
getGuestPayment: "function",
|
|
4535
4541
|
listAccessPlans: "function",
|
|
4536
4542
|
purchaseAccessPlan: "function",
|
|
4537
4543
|
cancelAccessPlan: "function",
|
|
@@ -6817,7 +6823,11 @@ const CONTRACT = deepFreeze({
|
|
|
6817
6823
|
// 1.239.0: additive (sc-15658) — an app-triggered run must finish within 250 ms
|
|
6818
6824
|
// of the press; `useAction` errors carry the new code ACTION_TIMEOUT
|
|
6819
6825
|
// (504), whose outcome is unknown.
|
|
6820
|
-
|
|
6826
|
+
// 1.242.0: additive (sc-15359) — `usePayments()` gains
|
|
6827
|
+
// `requestGuestPayment` / `getGuestPayment` (a visitor with no account
|
|
6828
|
+
// pays for an order they created), the payments slice gains both, the
|
|
6829
|
+
// `payments.charge:guest` scope, and four new PaymentError codes.
|
|
6830
|
+
version: "1.242.0",
|
|
6821
6831
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6822
6832
|
hooks: HOOKS,
|
|
6823
6833
|
primitives: PRIMITIVES,
|