Developers
Payment actions
Connect your backend so Funnels can save cards, take one-time payments and start subscriptions in your app.
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:
- Answers a signed connection check and says which payment types it supports.
- Accepts signed payment requests and runs each one exactly once.
- 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
- 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.
- Deploy your endpoint.
- In Finish setup → Connect Stripe → Let Funnels take payments in your app, click Connect payment backend.
- Enter the Payment endpoint, Signing secret and Completion secret, then click Save payment connection.
- 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:
| Header | Value |
|---|---|
x-saasfunnels-customer-action-version | Protocol version, usually 1 |
x-saasfunnels-customer-action-timestamp | ISO-8601 time |
x-saasfunnels-customer-action-nonce | A unique value, 16–160 characters |
x-saasfunnels-customer-action-signature | v1= 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):
saasfunnels-customer-action-v1
<purpose>
<timestamp>
<nonce>
<raw JSON body>| Message | Purpose |
|---|---|
| Connection check we send / you answer | handshake_request / handshake_response |
| Payment request we send / you answer | dispatch_request / dispatch_response |
| Result you send | completion |
| Payment check we send / you answer | payment_reconciliation_request / payment_reconciliation_response |
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:
{
"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:
- Check the signature, and that the account and user may make this purchase.
- Save the
providerIdempotencyKeywith a unique constraint. If it's already there, return your earlier reply and do nothing else. - Create the Stripe PaymentIntent or SetupIntent with
automatic_payment_methods.allow_redirectsset tonever. - Reply
202withstate: "accepted"and acontinuationholding the intent's client secret, so the Funnel can show the card form. Replystate: "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:
https://app.saasfunnels.com/api/funnels/v1/runtime/actions/customer-completeSet 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 events | For |
|---|---|
setup_intent.succeeded, setup_intent.canceled, setup_intent.setup_failed | Saving a card |
payment_intent.succeeded, payment_intent.canceled, payment_intent.payment_failed | One-time purchases |
invoice.payment_succeeded, invoice.payment_failed | A new subscription's first invoice |
charge.refunded | Refunds |
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.