novinzodevelopers
Plugins

Payments

Run a store's hosted payment method from a plugin, report each payment's outcome and receive provider notifications.

A plugin granted payments:provide can run one of a store's payment methods. Buyers pay on a page your plugin opens at its payment provider, and your plugin reports how each payment ended.

Novinzo keeps the order, the checkout session, the recorded amount and the completion. Your plugin cannot mark a checkout paid unless the reported payment matches the one Novinzo recorded for it.

Novinzo ships no payment plugin of its own. A store can run one as a store-private plugin.

How a payment flows

The seller configures your plugin, for example on its admin screen. Your plugin calls PluginPaymentMethodActivate with the method's displayName and, optionally, an iconUrl, then gives its provider the returned paymentWebhooksUrl.

The buyer chooses your method at checkout. Novinzo calls CreateHostedPayment with a new paymentId and the exact amount.

Your plugin opens a payment at its provider and answers with the provider's page. Novinzo records the payment as pending and the storefront redirects the buyer there.

The provider notifies your plugin through the payment webhook URL. Your plugin verifies the notification and calls PluginPaymentReport.

Novinzo checks the report against its record. A matching succeeded report completes the checkout and runs the usual order fulfillment.

Every five minutes Novinzo also sends ReconcileHostedPayments with the store's payments that are still open. Report any that ended, so a lost notification does not leave a checkout open.

Your method's icon

Pass iconUrl to PluginPaymentMethodActivate to show your own mark beside your method's name at checkout and in the dashboard. It must be an https URL you host, and every call sets it again: leave it out and the method shows the generic plugin icon.

Renewing subscriptions

A store can sell subscriptions. By default a subscription paid through your method renews by pay link: Novinzo emails the buyer a link to a checkout for each renewal, which they pay with your method like any checkout.

To renew automatically, your provider must save the method the buyer paid with and charge it again without them. Declare that you do by activating with recurring: true:

{ "displayName": "Acme Pay", "recurring": true }

Every activation sets the declaration again. Activate without it and your method renews by pay link from then on; subscriptions already renewing automatically switch to pay links. A retired method also renews by pay link.

With the declaration, Novinzo:

  1. Sends "saveMethod": true in CreateHostedPayment when the payment starts a subscription. When the buyer saved a method through your method before, it also sends that method's externalCustomerId, so you save the new one under the same customer.

  2. Expects your succeeded report for that payment to carry the saved method:

    {
      "paymentId": "a4e2b1c0-9d8f-4e7a-b6c5-d4e3f2a1b0c9",
      "externalId": "inv_8F2K",
      "outcome": "succeeded",
      "amount": { "amountMinorUnits": "1999", "currency": "USD" },
      "savedMethod": {
        "externalCustomerId": "cus_41",
        "externalMethodToken": "pm_9QX",
        "display": "Visa •••• 4242"
      }
    }

    externalCustomerId and externalMethodToken are your provider's references, trimmed, 1 through 255 characters. display is what the buyer knows the method by, trimmed, 1 through 255 characters; buyers and sellers see it. Novinzo keeps the first method reported for a payment. A success without savedMethod completes the checkout, and the subscription renews by pay link.

  3. Calls ChargeSavedMethod at each renewal, and RemoveSavedMethod when no subscription needs a method any more.

Plugins built before subscriptions keep working unchanged: every field above is optional.

ChargeSavedMethod

{
  "storeId": "7d5c4a7e-1f0b-4c35-9a52-1b2f0e8d9c41",
  "connectionId": "3f1d0c52-8f7e-4c2b-9a14-6d5e4b3a2c10",
  "paymentId": "0b1c2d3e-4f50-4617-8829-3a4b5c6d7e8f",
  "orderId": "c3a1e0f2-6b7d-4e8a-9f10-2b3c4d5e6f70",
  "renewalId": "6f1c2a3b-4d5e-4f60-8a7b-9c0d1e2f3a4b",
  "amount": { "amountMinorUnits": "2500", "currency": "USD" },
  "savedMethod": {
    "externalCustomerId": "cus_41",
    "externalMethodToken": "pm_9QX",
    "display": "Visa •••• 4242"
  },
  "idempotencyKey": "subscription-renewal:6f1c2a3b-4d5e-4f60-8a7b-9c0d1e2f3a4b:1"
}

Charge the saved method exactly amount, without the buyer. Charge at most once per idempotencyKey: pass it to your provider as its idempotency key, or keep it yourself, and answer a repeated key with the first charge's outcome. Store paymentId with your provider's reference, as for a hosted payment.

Answer 200 with one of four results:

ResultMeaningWhat Novinzo does
{ "_tag": "Succeeded", "externalId": "ch_1" }Paid in full.Pays the renewal and starts the next period.
{ "_tag": "Pending", "externalId": "ch_1" }The provider is still deciding.Waits for your PluginPaymentReport for paymentId and externalId.
{ "_tag": "NeedsBuyer", "reason": "authentication" }The provider needs the buyer (authentication, or reapproval of the method).Emails the buyer a pay link for this renewal.
{ "_tag": "Declined", "retryable": true, "code": "insufficient_funds" }The provider refused the charge.Emails the buyer; a retryable decline is charged again during the grace period under a new key.

externalId is required with Succeeded and Pending, and code with Declined (1 through 255 characters). Report a Pending charge's outcome with PluginPaymentReport exactly as for a hosted payment: succeeded pays the renewal, failed reopens it to be charged again during grace.

A non-200 status, a malformed body or a timeout leaves the outcome unknown. Novinzo does not assume the charge failed: it asks again with the same idempotencyKey for up to 12 hours, and never charges that renewal under a new key while the outcome is unknown. Answer a repeated key from what you recorded, never by charging again.

RemoveSavedMethod

Payload: { "storeId": "<uuid>", "connectionId": "<uuid>", "savedMethod": { … } }. Have your provider forget the method, then answer 200 {"ok":true}. A method your provider no longer has counts as removed.

The permission

Request payments:provide during registration, or list it in permissions in a store-private plugin's novinzo.plugin.json. The seller grants it per store.

It authorizes three backend RPCs and nothing else:

RPCPurpose
PluginPaymentMethodActivateMake your plugin the store's plugin payment method.
PluginPaymentMethodDeactivateRetire your plugin's payment method on the store.
PluginPaymentReportReport how a payment your plugin took ended.

Call them over the BACKEND binding with the inbound invocation token, as described in Backend RPC. The invocation's store is the store the call acts on.

A plugin without the grant receives PermissionDenied. A seller session calling these RPCs receives PluginPaymentCallerNotPluginError.

Your own payment method

A store owner can run their own payment method as a store-private plugin, with the same contract as every other plugin on this page:

  • List payments:provide in permissions in novinzo.plugin.json, and grant it when you install the plugin.
  • Send the RPCs above to https://dashboard.novinzo.com/api/rpc with fetch. A store-private plugin has no BACKEND binding; the requests are otherwise the same.
  • Activate from a request that carries an invocation token, such as a save on the plugin's admin screen ("hasAdminScreens": true).
  • Set the provider's API key and webhook signing secret as the plugin's secrets: it only ever runs for your store. Keep the provider's URLs in code, since wrangler.jsonc vars are not deployed.
  • When the provider refuses a call with a status that is not 2xx, log which call it was, the status and the response body with console.error, never the request's headers or credentials. The provider's error body is often the only record of why it refused, and the plugin's logs are where it can be found later.

Activating the method

Activate once your plugin can take payments for the store, typically after the seller saves working provider credentials.

Send { "displayName": "Acme Pay" }. The display name is what buyers choose at checkout. It is trimmed and holds 1 through 64 characters.

Success returns two values:

FieldMeaning
connectionIdThe store's connection for your method. Novinzo sends it in CreateHostedPayment.
paymentWebhooksUrlThe public URL of your /payment-webhooks surface for this store. Give your provider a URL beneath it.

The method follows these rules:

  • Each plugin has at most one method per store. A store can take payments through any number of plugins, and buyers choose between them at checkout.
  • Activating again while your method is live renames it and returns the same connectionId and URL.
  • An uninstall or grant revocation committed while your call runs refuses the activation with PermissionDenied.

The dashboard shows the method as managed by its plugin. Sellers cannot connect it themselves, but they can disconnect it.

Retiring the method

A method is retired when any of these happens:

  • Your plugin calls PluginPaymentMethodDeactivate.
  • The seller disconnects the method in the dashboard.
  • The seller withdraws payments:provide through SetPluginPermissions.
  • The seller uninstalls your plugin.

A retired method takes no new payments. Payments opened before retirement stay yours: Novinzo still asks your plugin to cancel and reconcile them, and their notifications still reach it while it is installed.

Activating after retirement creates a new connection with a new paymentWebhooksUrl. Give your provider the new URL. The old URL keeps serving payments opened through the old connection.

Hosted-payment functions

Novinzo calls these functions like every other function: POST, JSON, with x-novinzo-store-id and x-novinzo-plugin-invocation. Reject a payload storeId that differs from the store header.

FunctionPathTimeout
CreateHostedPayment/functions/create-hosted-payment20 seconds
CancelHostedPayment/functions/cancel-hosted-payment20 seconds
ReconcileHostedPayments/functions/reconcile-hosted-payments1 minute
ChargeSavedMethod/functions/charge-saved-method20 seconds
RemoveSavedMethod/functions/remove-saved-method20 seconds

These functions need no subscription. Novinzo calls the plugin that runs the payment's method, and only while that plugin is installed on the store. ChargeSavedMethod and RemoveSavedMethod are described in Renewing subscriptions.

CreateHostedPayment

Novinzo calls this when the buyer pays with your method:

{
  "storeId": "7d5c4a7e-1f0b-4c35-9a52-1b2f0e8d9c41",
  "connectionId": "3f1d0c52-8f7e-4c2b-9a14-6d5e4b3a2c10",
  "paymentId": "a4e2b1c0-9d8f-4e7a-b6c5-d4e3f2a1b0c9",
  "orderId": "d09f5b85-7496-4a27-b5a5-e5f661d8d070",
  "amount": { "amountMinorUnits": "1999", "currency": "USD" },
  "email": "buyer@example.com",
  "returnUrl": "https://<store domain>/…",
  "cancelUrl": "https://<store domain>/…"
}

Open a payment at your provider for exactly amount. Store paymentId with your provider's reference, because every later call and report names both.

email is the buyer's address for the provider's receipt. returnUrl is where the buyer goes after paying, and cancelUrl is where the buyer goes to give up. Pass them to your provider when it supports return URLs.

Answer 200 with one of two results:

{
  "_tag": "Created",
  "externalId": "inv_8F2K",
  "redirectUrl": "https://pay.example.com/inv_8F2K",
  "expiresAt": "2026-10-22T13:00:00.000Z"
}
{ "_tag": "Refused", "message": "This store is not set up to take payments yet" }
  • externalId is your provider's reference: a trimmed string of 1 through 255 characters.
  • redirectUrl must be an absolute https: URL of at most 2048 characters. The storefront navigates the buyer to it.
  • expiresAt is optional. Send it when the provider says when the page stops accepting payment.
  • Refused is an answer, not a failure. Use it when the store is not configured or the provider declines the amount or currency. Novinzo may show the message to the buyer after your method's display name.

Novinzo records the payment only after a Created answer. A non-200 status, a malformed body or a timeout fails the payment attempt, and the buyer sees that your method could not open its payment page.

CancelHostedPayment

Payload: { "storeId": "<uuid>", "payment": { "paymentId": "<uuid>", "externalId": "inv_8F2K" } }.

Novinzo calls this when the buyer gives up on a payment or the checkout moves to another payment. Stop your provider from taking the payment, then answer 200 {"ok":true}.

Answer success only once nothing can be paid on that page. If money is already held or arriving, fail the call instead.

A failed or timed-out cancel keeps the checkout open, so it can still complete when the buyer pays. Novinzo treats the payment as cancelled only after your plugin confirms.

ReconcileHostedPayments

Payload: { "storeId": "<uuid>", "payments": [{ "paymentId": "<uuid>", "externalId": "inv_8F2K" }] }. The array holds at least one payment.

Novinzo's scheduled pass runs every five minutes. It asks about open payments created within the last eight days, at most 200 per pass across all stores, grouped into one call per plugin and store.

Ask your provider about each payment and report every one that ended with PluginPaymentReport. Leave payments that are still open unreported. Answer 200 {"ok":true}.

A failed or timed-out call is logged and the payments are offered again on a later pass. Other plugins and stores are still asked.

Reporting outcomes

Send PluginPaymentReport with the payment's paymentId, your externalId, the provider's outcome and the amount the provider says the payment was for:

{
  "paymentId": "a4e2b1c0-9d8f-4e7a-b6c5-d4e3f2a1b0c9",
  "externalId": "inv_8F2K",
  "outcome": "succeeded",
  "amount": { "amountMinorUnits": "1999", "currency": "USD" }
}
outcomeMeaningEffect
succeededPaid in full.Completes the checkout and runs order fulfillment.
failed, cancelled, expiredThe buyer did not pay.Ends a checkout still waiting on the payment, then the payment itself.
refundedThe whole payment went back to the buyer.Marks a succeeded payment refunded.
disputedThe buyer charged it back.Marks a succeeded or refunded payment disputed.

Success returns { "paymentStatus": "<status>" }: the payment's status after the report, whether or not the report changed it.

Two optional fields give fraud scoring what your provider knows. Neither moves the payment:

  • dispute, with disputed: { "externalId": "<your provider's dispute id or null>", "reason": "<reason>", "providerReason": "<its own code or null>" }. reason is fraud (the cardholder did not make or allow the payment), not_received, not_as_described, duplicate, other or unknown. Without it the dispute is recorded with reason unknown.
  • cardAttempt, when the buyer paid by card: { "attemptId": "<your provider's id of the attempt>", "attempt": <attempt> }, the approval behind a succeeded report or the decline behind a failed one. The attempt has the shape of PaymentAttempted's attempt: outcome, a declineCategory when declined, and card. Never send the full card number or its security code. An attempt reported again under the same attemptId is recorded once.

Novinzo applies a report only when it matches its record:

  • The payment must have been taken through your plugin's method on the invocation's store. Otherwise the report fails with PluginPaymentNotFoundError, exactly as for a payment that does not exist.
  • externalId, currency and amount must equal what Novinzo recorded. Otherwise the report fails with PluginPaymentMismatchError, whose field names the first mismatch. Nothing is applied.
  • Amounts compare exactly. A provider that rounds or converts the amount has not taken the payment Novinzo asked for.

Reports are safe to repeat. Each outcome moves a payment only from the states it can follow, so a repeated, delayed or out-of-order report changes nothing it should not. A repeated success does not send fulfillment or the order email twice.

A success can arrive after the local checkout session expired, because the provider's page has its own lifetime. Novinzo still completes that checkout.

If the checkout has since moved to another payment or the buyer cancelled it, a success records the payment as succeeded so the seller sees the money, but completes nothing.

Report the provider's verified state, not the contents of an unverified notification. Retry a report that failed with InternalServerError or a transport failure. Do not retry PluginPaymentNotFoundError or PluginPaymentMismatchError unchanged: the same report is refused again.

Provider notifications

Your Worker serves provider notifications under /payment-webhooks/**. Novinzo exposes that surface publicly per store and connection:

POST <api origin>/plugin-payment-webhooks/<connectionId>/payment-webhooks/<your path>

paymentWebhooksUrl already contains everything up to /payment-webhooks. Append your own path, such as <paymentWebhooksUrl>/acme.

Novinzo forwards a notification to your Worker under these rules:

  1. Only POST is routed. Paths outside /payment-webhooks are refused before reaching your Worker.
  2. The connection must be a plugin payment method, live or retired. It names your plugin and the store.
  3. Your plugin must still be installed on that store. Otherwise the proxy answers 404.
  4. Only content-type, idempotency-key, x-signature and x-timestamp are forwarded from the provider. Novinzo adds x-novinzo-store-id and a fresh x-novinzo-plugin-invocation for the store.

Verify every notification yourself

The route is unauthenticated. Anyone who knows the URL can post to it. Verify the provider's signature over the raw body, or read the payment back from the provider's API, before you report anything.

The header list is closed. If your provider signs under another header name, coordinate that header with Novinzo before you depend on it.

Your response returns to the provider without the blocked response headers. A redirect or an unreachable Worker returns 502. Use the status codes your provider expects for retries.

Forward the inbound invocation token unchanged when you call PluginPaymentReport from the notification handler.

Verifying an HMAC signature

Many providers sign the raw request body with a shared secret. Read the body as text before parsing it, because the signature covers the exact bytes:

const encoder = new TextEncoder();

async function hmacSha256Hex(secret, body) {
  const key = await crypto.subtle.importKey(
    "raw",
    encoder.encode(secret),
    { name: "HMAC", hash: "SHA-256" },
    false,
    ["sign"],
  );
  const signature = await crypto.subtle.sign("HMAC", key, encoder.encode(body));
  return Array.from(new Uint8Array(signature), (byte) => byte.toString(16).padStart(2, "0")).join(
    "",
  );
}

function constantTimeEqual(a, b) {
  if (a.length !== b.length) return false;
  let difference = 0;
  for (let index = 0; index < a.length; index += 1) {
    difference |= a.charCodeAt(index) ^ b.charCodeAt(index);
  }
  return difference === 0;
}

export async function verifiedBody(request, secret) {
  const body = await request.text();
  const received = request.headers.get("x-signature")?.trim().toLowerCase() ?? "";
  const expected = await hmacSha256Hex(secret, body);
  return constantTimeEqual(expected, received) ? body : null;
}

Look up the store's secret with the trusted x-novinzo-store-id header. Follow your provider's documentation for the exact signing scheme and timestamp tolerance.

Failure handling

SituationResult
CreateHostedPayment fails, times out or is malformedNo payment is recorded. The buyer sees that your method could not open its page.
ChargeSavedMethod fails, times out or is malformedThe outcome is unknown. Novinzo asks again under the same key.
CreateHostedPayment answers RefusedNo payment is recorded. Novinzo may show your message to the buyer.
CancelHostedPayment fails or times outThe payment and checkout stay open.
ReconcileHostedPayments fails or times outThe payments are offered again on a later pass.
A notification never arrivesThe next reconcile pass offers the payment while it is open and recent.

Never answer Created, a successful cancel, or a succeeded report on an assumption. Each one can complete or end a buyer's checkout.

Next steps

On this page