Skip to content
Intents Checkout plugins

Base44

Crypto payments in a Base44 app with three backend functions and one prompt, set up in test mode first.

Base44’s payment menu offers its own providers only, so Intents Checkout goes in as three backend functions that call the API with your secret key. Your app needs a Base44 plan that includes backend functions. The customer pays on the intents.fi hosted page, in any supported token on any supported chain, and you receive USDC or USDT in your own wallet.

Function What it does
intentsCreatePayment Creates an invoice for an order from the order’s own total and returns the payment page URL
intentsWebhook Receives signed invoice.* webhooks and updates the order. The only thing that marks it paid
intentsSyncPayment Asks the API for the order’s payment, for the page the customer comes back to
  1. In the dashboard, check your settlement asset and address, and copy your test API key (ik_test_…).
  2. In the Base44 editor, Dashboard → Secrets → Add Secret: INTENTS_SECRET_KEY, the test key.
  3. Paste the prompt below into the Base44 AI chat. It adds the payment fields to your Order entity, the three functions, a Pay with crypto button and a confirmation page. If your order entity or its total field has another name, say so in the chat; the names are constants at the top of each function.
  4. Publish the app, then add a webhook endpoint for your test key, subscribed to the invoice.* events, at https://<your app's domain>/functions/intentsWebhook, on the dashboard’s Webhooks page or with the API:
curl
curl https://api.intents.fi/v0/webhooks \
-X POST \
-H 'authorization: Bearer $INTENTS_SECRET_KEY' \
-H 'content-type: application/json' \
-d '{
"url": "https://northwood.example/hooks/intents"
}'
TypeScript
const response = await fetch("https://api.intents.fi/v0/webhooks", {
method: "POST",
headers: {
authorization: `Bearer ${process.env.INTENTS_SECRET_KEY}`,
"content-type": "application/json",
},
body: JSON.stringify({
"url": "https://northwood.example/hooks/intents"
}),
});
if (!response.ok) {
const { error } = await response.json();
throw new Error(`${error.code}: ${error.message}`);
}
const data = await response.json();
Python
import os
import httpx
response = httpx.post(
"https://api.intents.fi/v0/webhooks",
headers={"authorization": f"Bearer {os.environ['INTENTS_SECRET_KEY']}"},
json={
"url": "https://northwood.example/hooks/intents"
},
)
response.raise_for_status()
data = response.json()
  1. Add the whsec_… secret it returns as a second Base44 secret, INTENTS_WEBHOOK_SECRET.
  2. Place an order and press Pay with crypto. A test invoice’s hosted page has a Complete the test payment button. Press it, and you come back to the confirmation page with the order marked paid.

Go live once your account is reviewed: replace INTENTS_SECRET_KEY with your ik_live_ key, add the same webhook URL for the live key, and replace INTENTS_WEBHOOK_SECRET with the live endpoint’s secret. Test and live payments never share a reference, so an order started in test mode gets a new live payment.

Add crypto payments to this app with Intents Checkout. Use exactly the code below; do not
rewrite the payment logic.
1. Order entity: add these fields (keep the existing ones). If orders live in an entity with
another name, or the total is in another field, change ORDER_ENTITY and AMOUNT_FIELD at the
top of the shared block in all three functions, identically (and DESCRIPTION_FIELD, the
order's title, in intentsCreatePayment).
- total_usd: number (the order total in USD) — skip if the order already has a USD total
- payment_status: string, default "unpaid"
(unpaid, awaiting_payment, payment_processing, payment_expired, needs_review, paid)
- intents_invoice_id: string
- intents_mode: string
- intents_attempt: number
- intents_paid_invoice_id: string
- paid_at: string (date-time)
Only backend functions may set payment_status and the intents_* fields. Never set them from
the frontend.
2. Backend functions, each in its own file, exactly as written:
base44/functions/intentsCreatePayment/entry.ts
```ts
import { createClientFromRequest } from "npm:@base44/sdk";
/**
* intentsCreatePayment: a Base44 backend function. Starts a crypto payment for one order and
* returns the intents.fi hosted payment page to send the customer to.
*
* Frontend:
* const { data } = await base44.functions.invoke("intentsCreatePayment", { orderId, returnPath: "/order-confirmation" });
* window.location.href = data.url;
*
* The price is read from the order record here, on the server, never from the request: a customer
* can send any body they like. Secrets (Dashboard → Secrets): INTENTS_SECRET_KEY (ik_test_… first,
* ik_live_… once your account is live). Optional: APP_URL, your app's public https address.
*/
const API = Deno.env.get("INTENTS_API_URL") ?? "https://api.intents.fi";
const DESCRIPTION_FIELD = "title"; // optional; shown on the payment page
const PAYABLE = new Set(["open", "processing", "underpaid"]);
async function intents<T>(method: string, path: string, key: string, body?: unknown): Promise<T> {
const res = await fetch(`${API}${path}`, {
method,
headers: { authorization: `Bearer ${key}`, "content-type": "application/json" },
body: body === undefined ? undefined : JSON.stringify(body),
});
const json = await res.json().catch(() => ({}));
if (!res.ok)
throw new Error(json?.error?.message ?? `intents.fi ${method} ${path}: ${res.status}`);
return json as T;
}
// --- intents.fi shared block: identical in all three functions ---
// Change these if your order entity or its fields have other names.
const ORDER_ENTITY = "Order";
const AMOUNT_FIELD = "total_usd"; // the order total in USD, e.g. 49 or "49.00"
type Invoice = {
id: string;
status: string;
mode: string;
amount: string;
url: string;
needsReview?: boolean;
metadata?: Record<string, unknown>;
};
type OrderRecord = Record<string, unknown> & { id: string };
type Orders = { update(id: string, data: Record<string, unknown>): Promise<unknown> };
/** "49", 49 or 49.5 → "49.00" / "49.50"; anything else → null. */
function usd(value: unknown): string | null {
const s = typeof value === "number" ? value.toFixed(2) : String(value ?? "").trim();
if (!/^\d{1,15}(\.\d{1,2})?$/.test(s) || Number(s) <= 0) return null;
const [whole, cents = ""] = s.split(".");
return `${whole}.${cents.padEnd(2, "0")}`;
}
/**
* Write what an intents.fi invoice says onto its order. The only place an order becomes paid.
* `invoice` is the API's own invoice (a verified webhook's `data`, or GET /v0/invoices/{id}).
* Safe to call any number of times, in any order: a paid order is never changed again.
*/
async function applyInvoice(orders: Orders, order: OrderRecord, invoice: Invoice): Promise<string> {
if (order.payment_status === "paid") return "paid";
if (invoice.metadata?.base44_order_id !== order.id || invoice.mode !== order.intents_mode) {
return String(order.payment_status ?? "unpaid"); // not this order's payment
}
const current = invoice.id === order.intents_invoice_id;
let next: Record<string, unknown> | null = null;
if (invoice.status === "paid") {
// Paid on the order's current payment, for the order's current total: paid. Anything else
// (a replaced payment, a changed total) is real money a person must look at.
next =
current && invoice.amount === usd(order[AMOUNT_FIELD])
? {
payment_status: "paid",
paid_at: new Date().toISOString(),
intents_paid_invoice_id: invoice.id,
}
: { payment_status: "needs_review", intents_paid_invoice_id: invoice.id };
} else if (!current) {
return String(order.payment_status ?? "unpaid");
} else if (invoice.needsReview) {
next = { payment_status: "needs_review" };
} else if (invoice.status === "processing" || invoice.status === "underpaid") {
next = { payment_status: "payment_processing" };
} else if (invoice.status === "expired" || invoice.status === "canceled") {
next = { payment_status: "payment_expired" };
}
if (next && next.payment_status !== order.payment_status) await orders.update(order.id, next);
return String(next?.payment_status ?? order.payment_status ?? "unpaid");
}
// --- end of shared block ---
Deno.serve(async (req) => {
try {
const key = Deno.env.get("INTENTS_SECRET_KEY");
if (!key?.startsWith("ik_test_") && !key?.startsWith("ik_live_")) {
return Response.json(
{ error: "Set the INTENTS_SECRET_KEY secret (ik_test_… or ik_live_…)" },
{ status: 500 },
);
}
const mode = key.startsWith("ik_live_") ? "live" : "test";
const { orderId, returnPath } = (await req.json().catch(() => ({}))) as {
orderId?: string;
returnPath?: string;
};
if (!orderId) return Response.json({ error: "orderId is required" }, { status: 400 });
const base44 = createClientFromRequest(req);
const orders = base44.asServiceRole.entities[ORDER_ENTITY];
const order = (await orders.get(orderId).catch(() => null)) as OrderRecord | null;
if (!order) return Response.json({ error: "order not found" }, { status: 404 });
if (order.payment_status === "paid") {
return Response.json({ error: "this order is already paid" }, { status: 409 });
}
const amount = usd(order[AMOUNT_FIELD]);
if (!amount)
return Response.json({ error: `order.${AMOUNT_FIELD} is not a USD amount` }, { status: 400 });
// Reuse the order's current payment while it can still be paid, so a double click or a reload
// never opens a second one.
const sameMode = Boolean(order.intents_invoice_id) && order.intents_mode === mode;
if (sameMode) {
const id = encodeURIComponent(String(order.intents_invoice_id));
const current = await intents<Invoice>("GET", `/v0/invoices/${id}`, key);
if (current.status === "paid") {
// Paid, but the webhook has not landed yet: record it now and never charge twice.
const status = await applyInvoice(orders, order, current);
return Response.json(
{ error: "this order's payment is complete", status },
{ status: 409 },
);
}
if (PAYABLE.has(current.status) && current.amount === amount) {
return Response.json({ url: current.url, invoiceId: current.id });
}
if (current.status === "open") {
// The total changed since: retire the old payment before opening a new one.
await intents("POST", `/v0/invoices/${id}/cancel`, key).catch(() => {});
} else if (PAYABLE.has(current.status)) {
return Response.json(
{ error: "a payment for this order is already on its way" },
{ status: 409 },
);
}
}
// `reference` is the API's idempotency key: one per order and attempt, so a retried request
// returns the same invoice, and an expired one is replaced by `-r2`, `-r3`…
const attempt = sameMode ? (Number(order.intents_attempt) || 1) + 1 : 1;
const reference = `base44-${orderId}${attempt > 1 ? `-r${attempt}` : ""}-${mode}`;
const origin = (Deno.env.get("APP_URL") ?? req.headers.get("origin") ?? "").replace(/\/+$/, "");
const path =
typeof returnPath === "string" && /^\/(?![/\\])/.test(returnPath) ? returnPath : "/";
const back = /^https:\/\/[^/]+$/.test(origin)
? `${origin}${path}${path.includes("?") ? "&" : "?"}orderId=${encodeURIComponent(orderId)}`
: undefined;
const invoice = await intents<Invoice>("POST", "/v0/invoices", key, {
amount,
currency: "USD",
reference,
description: String(order[DESCRIPTION_FIELD] || `Order ${orderId}`).slice(0, 500),
...(back ? { successUrl: back, cancelUrl: back } : {}),
metadata: { base44_order_id: orderId },
});
await orders.update(orderId, {
intents_invoice_id: invoice.id,
intents_mode: mode,
intents_attempt: attempt,
payment_status: "awaiting_payment",
});
return Response.json({ url: invoice.url, invoiceId: invoice.id });
} catch (error) {
return Response.json({ error: (error as Error).message }, { status: 502 });
}
});
```
base44/functions/intentsWebhook/entry.ts
```ts
import { createClientFromRequest } from "npm:@base44/sdk";
/**
* intentsWebhook: a Base44 backend function, and the URL you register as a webhook endpoint in
* the intents.fi dashboard: https://<your app>/functions/intentsWebhook, events `invoice.*`.
*
* It checks the X-Intents-Signature header against the raw body before trusting a byte of it, then
* writes the invoice onto its order. Deliveries can repeat and arrive out of order; that is fine.
* Secret (Dashboard → Secrets): INTENTS_WEBHOOK_SECRET, the whsec_… shown when you add the endpoint.
*/
const TOLERANCE_SECONDS = 300;
/** `t=<unix seconds>,v1=<hex HMAC-SHA256(secret, t + "." + body)>`, within five minutes. */
async function verify(body: string, header: string | null, secret: string): Promise<boolean> {
const parts = Object.fromEntries((header ?? "").split(",").map((p) => p.trim().split("=", 2)));
const t = Number(parts.t);
const v1 = String(parts.v1 ?? "").toLowerCase();
if (!Number.isInteger(t) || !/^[0-9a-f]{64}$/.test(v1)) return false;
if (Math.abs(Date.now() / 1000 - t) > TOLERANCE_SECONDS) return false;
const key = await crypto.subtle.importKey(
"raw",
new TextEncoder().encode(secret),
{ name: "HMAC", hash: "SHA-256" },
false,
["sign"],
);
const mac = new Uint8Array(
await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`${t}.${body}`)),
);
const expected = Array.from(mac, (b) => b.toString(16).padStart(2, "0")).join("");
let diff = 0;
for (let i = 0; i < expected.length; i++) diff |= expected.charCodeAt(i) ^ v1.charCodeAt(i);
return diff === 0;
}
// --- intents.fi shared block: identical in all three functions ---
// Change these if your order entity or its fields have other names.
const ORDER_ENTITY = "Order";
const AMOUNT_FIELD = "total_usd"; // the order total in USD, e.g. 49 or "49.00"
type Invoice = {
id: string;
status: string;
mode: string;
amount: string;
url: string;
needsReview?: boolean;
metadata?: Record<string, unknown>;
};
type OrderRecord = Record<string, unknown> & { id: string };
type Orders = { update(id: string, data: Record<string, unknown>): Promise<unknown> };
/** "49", 49 or 49.5 → "49.00" / "49.50"; anything else → null. */
function usd(value: unknown): string | null {
const s = typeof value === "number" ? value.toFixed(2) : String(value ?? "").trim();
if (!/^\d{1,15}(\.\d{1,2})?$/.test(s) || Number(s) <= 0) return null;
const [whole, cents = ""] = s.split(".");
return `${whole}.${cents.padEnd(2, "0")}`;
}
/**
* Write what an intents.fi invoice says onto its order. The only place an order becomes paid.
* `invoice` is the API's own invoice (a verified webhook's `data`, or GET /v0/invoices/{id}).
* Safe to call any number of times, in any order: a paid order is never changed again.
*/
async function applyInvoice(orders: Orders, order: OrderRecord, invoice: Invoice): Promise<string> {
if (order.payment_status === "paid") return "paid";
if (invoice.metadata?.base44_order_id !== order.id || invoice.mode !== order.intents_mode) {
return String(order.payment_status ?? "unpaid"); // not this order's payment
}
const current = invoice.id === order.intents_invoice_id;
let next: Record<string, unknown> | null = null;
if (invoice.status === "paid") {
// Paid on the order's current payment, for the order's current total: paid. Anything else
// (a replaced payment, a changed total) is real money a person must look at.
next =
current && invoice.amount === usd(order[AMOUNT_FIELD])
? {
payment_status: "paid",
paid_at: new Date().toISOString(),
intents_paid_invoice_id: invoice.id,
}
: { payment_status: "needs_review", intents_paid_invoice_id: invoice.id };
} else if (!current) {
return String(order.payment_status ?? "unpaid");
} else if (invoice.needsReview) {
next = { payment_status: "needs_review" };
} else if (invoice.status === "processing" || invoice.status === "underpaid") {
next = { payment_status: "payment_processing" };
} else if (invoice.status === "expired" || invoice.status === "canceled") {
next = { payment_status: "payment_expired" };
}
if (next && next.payment_status !== order.payment_status) await orders.update(order.id, next);
return String(next?.payment_status ?? order.payment_status ?? "unpaid");
}
// --- end of shared block ---
Deno.serve(async (req) => {
const secret = Deno.env.get("INTENTS_WEBHOOK_SECRET");
if (!secret)
return Response.json({ error: "Set the INTENTS_WEBHOOK_SECRET secret" }, { status: 500 });
// Read the body as text: the signature covers these exact bytes.
const body = await req.text();
if (!(await verify(body, req.headers.get("x-intents-signature"), secret))) {
return Response.json({ error: "bad signature" }, { status: 400 });
}
const event = JSON.parse(body) as { type?: string; data?: Invoice };
const orderId = event.data?.metadata?.base44_order_id;
if (!event.data || typeof orderId !== "string") return new Response(null, { status: 204 }); // not from this app
// A webhook has no signed-in user, so the service role reads and writes the order.
const base44 = createClientFromRequest(req);
const orders = base44.asServiceRole.entities[ORDER_ENTITY];
const order = (await orders.get(orderId).catch(() => null)) as OrderRecord | null;
if (!order) return new Response(null, { status: 204 });
// `data.status` is the truth; `type` is only why we were woken.
await applyInvoice(orders, order, event.data);
return new Response(null, { status: 204 });
});
```
base44/functions/intentsSyncPayment/entry.ts
```ts
import { createClientFromRequest } from "npm:@base44/sdk";
/**
* intentsSyncPayment: a Base44 backend function. Asks intents.fi for an order's payment and
* writes the answer onto the order. Call it from the page the customer returns to, so the page
* is right even before the webhook lands:
* const { data } = await base44.functions.invoke("intentsSyncPayment", { orderId });
* // data.payment_status: "paid", "payment_processing", "awaiting_payment", "payment_expired"…
*
* It reads the invoice from the API with your secret key, so nothing the browser sends can mark an
* order paid. Secret: INTENTS_SECRET_KEY, as for intentsCreatePayment.
*/
const API = Deno.env.get("INTENTS_API_URL") ?? "https://api.intents.fi";
// --- intents.fi shared block: identical in all three functions ---
// Change these if your order entity or its fields have other names.
const ORDER_ENTITY = "Order";
const AMOUNT_FIELD = "total_usd"; // the order total in USD, e.g. 49 or "49.00"
type Invoice = {
id: string;
status: string;
mode: string;
amount: string;
url: string;
needsReview?: boolean;
metadata?: Record<string, unknown>;
};
type OrderRecord = Record<string, unknown> & { id: string };
type Orders = { update(id: string, data: Record<string, unknown>): Promise<unknown> };
/** "49", 49 or 49.5 → "49.00" / "49.50"; anything else → null. */
function usd(value: unknown): string | null {
const s = typeof value === "number" ? value.toFixed(2) : String(value ?? "").trim();
if (!/^\d{1,15}(\.\d{1,2})?$/.test(s) || Number(s) <= 0) return null;
const [whole, cents = ""] = s.split(".");
return `${whole}.${cents.padEnd(2, "0")}`;
}
/**
* Write what an intents.fi invoice says onto its order. The only place an order becomes paid.
* `invoice` is the API's own invoice (a verified webhook's `data`, or GET /v0/invoices/{id}).
* Safe to call any number of times, in any order: a paid order is never changed again.
*/
async function applyInvoice(orders: Orders, order: OrderRecord, invoice: Invoice): Promise<string> {
if (order.payment_status === "paid") return "paid";
if (invoice.metadata?.base44_order_id !== order.id || invoice.mode !== order.intents_mode) {
return String(order.payment_status ?? "unpaid"); // not this order's payment
}
const current = invoice.id === order.intents_invoice_id;
let next: Record<string, unknown> | null = null;
if (invoice.status === "paid") {
// Paid on the order's current payment, for the order's current total: paid. Anything else
// (a replaced payment, a changed total) is real money a person must look at.
next =
current && invoice.amount === usd(order[AMOUNT_FIELD])
? {
payment_status: "paid",
paid_at: new Date().toISOString(),
intents_paid_invoice_id: invoice.id,
}
: { payment_status: "needs_review", intents_paid_invoice_id: invoice.id };
} else if (!current) {
return String(order.payment_status ?? "unpaid");
} else if (invoice.needsReview) {
next = { payment_status: "needs_review" };
} else if (invoice.status === "processing" || invoice.status === "underpaid") {
next = { payment_status: "payment_processing" };
} else if (invoice.status === "expired" || invoice.status === "canceled") {
next = { payment_status: "payment_expired" };
}
if (next && next.payment_status !== order.payment_status) await orders.update(order.id, next);
return String(next?.payment_status ?? order.payment_status ?? "unpaid");
}
// --- end of shared block ---
Deno.serve(async (req) => {
try {
const key = Deno.env.get("INTENTS_SECRET_KEY");
if (!key) return Response.json({ error: "Set the INTENTS_SECRET_KEY secret" }, { status: 500 });
const { orderId } = (await req.json().catch(() => ({}))) as { orderId?: string };
if (!orderId) return Response.json({ error: "orderId is required" }, { status: 400 });
const base44 = createClientFromRequest(req);
const orders = base44.asServiceRole.entities[ORDER_ENTITY];
const order = (await orders.get(orderId).catch(() => null)) as OrderRecord | null;
if (!order) return Response.json({ error: "order not found" }, { status: 404 });
if (!order.intents_invoice_id || order.payment_status === "paid") {
return Response.json({ payment_status: order.payment_status ?? "unpaid" });
}
const id = encodeURIComponent(String(order.intents_invoice_id));
const res = await fetch(`${API}/v0/invoices/${id}`, {
headers: { authorization: `Bearer ${key}` },
});
if (!res.ok)
return Response.json(
{ error: `intents.fi GET /v0/invoices: ${res.status}` },
{ status: 502 },
);
const payment_status = await applyInvoice(orders, order, (await res.json()) as Invoice);
return Response.json({ payment_status });
} catch (error) {
return Response.json({ error: (error as Error).message }, { status: 502 });
}
});
```
3. Secrets: INTENTS_SECRET_KEY (ask me for it; it starts with ik_test_) and later
INTENTS_WEBHOOK_SECRET (starts with whsec_).
4. Frontend:
- On the checkout or order page, a "Pay with crypto" button that creates the order first if it
does not exist yet, then runs
const { data } = await base44.functions.invoke("intentsCreatePayment", { orderId: order.id, returnPath: "/order-confirmation" });
and sends the browser to data.url. Show data.error if there is one.
- An /order-confirmation page that reads orderId from the URL, calls
base44.functions.invoke("intentsSyncPayment", { orderId }) on load and every 5 seconds until
payment_status is "paid" or "payment_expired", and shows: paid → "Payment received",
awaiting_payment or payment_processing → "Waiting for your payment to confirm",
payment_expired → "This payment expired" with a "Try again" button that calls
intentsCreatePayment again, needs_review → "We're checking your payment".
- Treat an order as paid only when payment_status is "paid".
  1. Pay with crypto calls intentsCreatePayment with the order ID. The function reads the order’s total_usd itself, creates an invoice with reference = base44-<order id>-test (or -live) and metadata.base44_order_id, saves the invoice ID on the order and returns the hosted page URL. A second click while the payment can still be paid returns the same page.
  2. The customer pays on the hosted page and comes back to /order-confirmation?orderId=…. The return URL is built from your app’s own origin (or the optional APP_URL secret), never from the request.
  3. intents.fi sends signed webhooks to intentsWebhook. It checks X-Intents-Signature against the raw body (and rejects anything older than five minutes) before it reads a byte, then writes the invoice onto its order. intentsSyncPayment writes the same thing from GET /v0/invoices/{id}, so the confirmation page is right even before the webhook lands.

If an invoice expires or is cancelled, the next Pay with crypto creates a new one (-r2, then -r3). If the order total changed while its invoice was still open, the old invoice is cancelled first.

Invoice payment_status
open awaiting_payment
processing, underpaid payment_processing
paid, on the order’s current invoice, for its current total paid, with paid_at
paid, on a replaced invoice or for a different total needs_review
needsReview set needs_review
expired, canceled payment_expired

A paid order never changes again. Deliveries can repeat and arrive out of order; the functions read data.status, not the event type, so a late invoice.expired after invoice.paid changes nothing. Look at a needs_review order in the dashboard and fulfil it by hand if the payment is right.

  • USD only. total_usd is the price in USD; nothing is converted.
  • No refund button. A failed payment is returned to the customer automatically; refund a completed one from your own wallet.
  • Subscriptions are not covered: each order is one payment.