Skip to content
SaaSFunnelsHelp

Developers

Payment actions

Connect your backend so Funnels can save cards, take one-time payments and start subscriptions in your app.

On this page

When a customer accepts an Offer that takes payment, SaaSFunnels asks your backend to do it. Your backend creates the Stripe payment, the Funnel shows Stripe's card form, and your backend reports the result. SaaSFunnels never charges a card itself and never treats a browser success screen as a payment.

Connecting Stripe imports your products and prices. It doesn't set this up; you need both.

What you build

One HTTPS endpoint on your server that:

  1. Answers a signed connection check and says which payment types it supports.
  2. Accepts signed payment requests and runs each one exactly once.
  3. Sends a signed result back to SaaSFunnels when the payment finishes.

Setup checks three payment types before you create Funnels that take payment: saving a card without charging (setup_only), a one-time purchase (one_time_purchase) and a new subscription (new_subscription).

Connect it

  1. Generate two different random secrets, each at least 32 characters: a signing secret and a completion secret. Store them only in your server's environment.
  2. Deploy your endpoint.
  3. In Finish setup → Connect Stripe → Let Funnels take payments in your app, click Connect payment backend.
  4. Enter the Payment endpoint, Signing secret and Completion secret, then click Save payment connection.
  5. Click Check payment connection. All three payment types and your Stripe products and prices must pass.

SaaSFunnels re-checks the connection automatically, so keep the endpoint available. Changing the endpoint, secrets or Stripe account needs a fresh check.

Signing

Every request and response between SaaSFunnels and your endpoint carries these headers:

HeaderValue
x-saasfunnels-customer-action-versionProtocol version, usually 1
x-saasfunnels-customer-action-timestampISO-8601 time
x-saasfunnels-customer-action-nonceA unique value, 16–160 characters
x-saasfunnels-customer-action-signaturev1= and a lowercase hex HMAC-SHA256

Payment requests also carry x-saasfunnels-customer-action-idempotency-key, equal to providerIdempotencyKey in the body.

Sign this string, joined with newlines, using the signing secret (or the completion secret for results you send):

Text
saasfunnels-customer-action-v1
<purpose>
<timestamp>
<nonce>
<raw JSON body>
MessagePurpose
Connection check we send / you answerhandshake_request / handshake_response
Payment request we send / you answerdispatch_request / dispatch_response
Result you sendcompletion
Payment check we send / you answerpayment_reconciliation_request / payment_reconciliation_response
JavaScript
import { createHmac, timingSafeEqual } from "node:crypto";

function sign(secret, purpose, timestamp, nonce, rawBody) {
  const input = ["saasfunnels-customer-action-v1", purpose, timestamp, nonce, rawBody].join("\n");
  return "v1=" + createHmac("sha256", secret).update(input, "utf8").digest("hex");
}

function verify(req, rawBody, secret, purpose) {
  const expected = sign(secret, purpose,
    req.headers["x-saasfunnels-customer-action-timestamp"],
    req.headers["x-saasfunnels-customer-action-nonce"], rawBody);
  const given = req.headers["x-saasfunnels-customer-action-signature"] ?? "";
  return given.length === expected.length &&
    timingSafeEqual(Buffer.from(given), Buffer.from(expected));
}

Verify the raw body before parsing it. Reject timestamps more than five minutes off and nonces you've seen before. SaaSFunnels waits five seconds for each response.

Connection check

We send type: "saasfunnels.customer_action.handshake" with a challenge, connectionId and workspaceId. Reply 200 with the same values, status: "ready", type: "saasfunnels.customer_action.handshake_ack" and a paymentCapabilities object naming only the modes you've built:

JSON
{
  "paymentCapabilities": {
    "connectedAccountReferenceHash": "<SHA-256 of JSON.stringify(your connected Stripe account ID)>",
    "connectionRevision": 0,
    "livemode": false,
    "modes": ["setup_only", "one_time_purchase", "new_subscription"]
  }
}

Use the connection revision from the x-saasfunnels-customer-action-connection-revision header; the first one is 0. Match livemode to the Stripe environment. A reply without paymentCapabilities turns payments off.

Payment requests

A request (type: "saasfunnels.customer_action.execute") names the account, the exact operation and amount, and a providerIdempotencyKey. Your backend should:

  1. Check the signature, and that the account and user may make this purchase.
  2. Save the providerIdempotencyKey with a unique constraint. If it's already there, return your earlier reply and do nothing else.
  3. Create the Stripe PaymentIntent or SetupIntent with automatic_payment_methods.allow_redirects set to never.
  4. Reply 202 with state: "accepted" and a continuation holding the intent's client secret, so the Funnel can show the card form. Reply state: "rejected" if you won't do it.

Accepting a request is not a payment. The Funnel waits until the payment is confirmed.

Results

When the payment finishes, POST a signed result to:

Text
https://app.saasfunnels.com/api/funnels/v1/runtime/actions/customer-complete

Set outcome to succeeded, failed, unknown or reversed. If delivery fails, retry with the same body and completionId and a fresh nonce, timestamp and signature. A 2xx reply means we have it.

After a succeeded result, SaaSFunnels makes a separate signed check against your endpoint and compares the amount, currency and Stripe state before it counts the payment.

If a request times out, don't run the payment again. Look it up by providerIdempotencyKey, check Stripe, and send the result you find.

Stripe payment outcomes

Your app's own Stripe webhook reports what happened. Reuse your existing billing webhook if you have one. Handle:

Stripe eventsFor
setup_intent.succeeded, setup_intent.canceled, setup_intent.setup_failedSaving a card
payment_intent.succeeded, payment_intent.canceled, payment_intent.payment_failedOne-time purchases
invoice.payment_succeeded, invoice.payment_failedA new subscription's first invoice
charge.refundedRefunds

Verify each webhook with that endpoint's own Stripe signing secret, which is different from both SaaSFunnels secrets. Ignore duplicate Stripe event IDs.

Before going live, check:

  • Your app's Stripe keys belong to the same Stripe account you connected to SaaSFunnels, in the same test or live mode.
  • Success, a declined card, a duplicate request, a retried result and a refund all work with Stripe test cards.

What's next