diff --git a/.changeset/payment-provider-client-is-public.md b/.changeset/payment-provider-client-is-public.md new file mode 100644 index 0000000..4a35889 --- /dev/null +++ b/.changeset/payment-provider-client-is-public.md @@ -0,0 +1,5 @@ +--- +"@dashcommerce/core": patch +--- + +Docs: an on-page checkout's `client` data is public. `create-session` sends it to the browser, so provider authors must never put a secret key or webhook secret in it. diff --git a/packages/core/README.md b/packages/core/README.md index 5e9a141..a7d6e4d 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -69,6 +69,7 @@ For provider authors, `PaymentProvider` can declare: - `credentialFields`: the label, accepted prefixes and help text for the settings form. - `webhookHeaders`: the headers that identify its webhooks, besides `x--signature`. `verifyWebhook` receives every request header, and `credentials` (the provider's saved secret key and webhook secret) for headers signed with the API key rather than the webhook secret. +- `checkoutStyles`: `["hosted", "on_page"]` to offer checkout over the store's page. `initCheckout` then returns `{ kind: "on_page", client }`, and the storefront hands `client` to the provider's browser client. `client` is public: `create-session` sends it to the browser as JSON, so put only what the browser needs in it (Paystack sends `{ accessCode }`), never a secret key or webhook secret. - `checkConnection`: one read-only call with the saved keys, behind a "Test connection" button in Settings. Return `{ ok, message }`, with `ok: false` and a message the merchant can act on for a wrong or under-permitted key. `parseWebhookEvent` may return `refund.updated` to move a pending refund to `succeeded` or `failed`. A failed refund stops counting against its order: the refunded total, payment status and order status are worked out again, and stock the refund put back is taken back off. diff --git a/packages/core/src/payment-provider/types.ts b/packages/core/src/payment-provider/types.ts index 006dd4e..69d537f 100644 --- a/packages/core/src/payment-provider/types.ts +++ b/packages/core/src/payment-provider/types.ts @@ -147,6 +147,8 @@ export type InitCheckoutResult = * Pay over the store's page. `client` is handed to the provider's * browser client (see the package's checkout-client entry), e.g. * Paystack's `{ accessCode }`. Never trusted as proof of payment. + * Public: `create-session` sends it to the browser as JSON, so + * never put a secret key or webhook secret in it. */ kind: "on_page"; checkoutReference: string;