Factuarea APIDevelopers

Storefront

The anonymous shopper lane — publishable credential, origin scoping, catalog, price, availability, cart, order, payment and tracking.

The storefront lane lets a custom-built website sell against Factuarea without Factuarea building the website. Its actor is different from every other surface of the API: the shopper is anonymous to the platform, and the credential the page uses travels inside the JavaScript that shopper downloads.

There is no embeddable checkout and no widget. The site consumes the API, and the fastest way to do that is the browser SDK.

The lane is gated by the storefront_api module (Avanzado plan upwards).

The publishable credential

An integrator credential (fact_live_… / fact_test_…) must NEVER be put in a web page. Its control is an IP allowlist, which a browser cannot satisfy, and it can reach the whole API. The browser SDK refuses one when the client is constructed, before any request is emitted, so a leak fails immediately and visibly in development instead of quietly in production.

The shopper lane has its own credential and it is a different kind of thing:

PropertyWhat it means
Shapesf_pk_ followed by 24 base62 characters. The stored visible prefix is sf_pk_ plus 8.
SecrecyIt is not a secret. It ships inside the bundle the shopper downloads.
ContainmentThe declared origins, and revocation. Nothing else.
ScopesA subset of the shopper lane only. It can never reach the merchant surface.
EnvironmentThere is no live / test split in the prefix.
ExpiryOptional, and evaluated at the door on every request.

There is a cap on how many credentials a company may have active at once, set by its storefront tier.

Expiry

expires_at takes a date text; a number, a boolean, a list or an object is 422 invalid_param_value with param expires_at. Dates after 19 January 2038, such as 2999-01-01, are accepted, and the ceiling is the year 9999 in the time zone of the application (Europe/Madrid): 9999-12-31T22:59:59Z is accepted, and 9999-12-31T23:00:00Z and later are 422 with param expires_at. The value is saved and published as the instant requested, whatever the offset it arrives with (Z, +01:00, +03:00).

Origins are the containment, so they are strict

Every request the credential makes is checked against the origins declared on it. An origin is a scheme and a host with an optional port. No wildcards, no path, no query string, no missing scheme — each of those is refused with 422 naming the field. The comparison is canonical, not textual: scheme and host lowercased, the default port dropped (:443 on https, :80 on http), a non-standard port kept, a lone trailing slash discarded. So https://Tienda.es and https://tienda.es:443 are the same origin. A repeated origin in the list of a credential is 422 invalid_param_value with param allowed_origins.N of the row that repeats it.

A request from an origin that is not declared is refused with storefront_origin_not_allowed — and note what that error says: the credential is fine, the domain is what was rejected. The universal wildcard is never accepted as a declared origin and is never emitted as an allowed-origin header either: the response carries the concrete origin.

Headers

The credential travels in X-Storefront-Key. The preflight only admits Authorization, X-Storefront-Key, Content-Type, Accept, Accept-Language, Idempotency-Key and X-Request-Id, so a client that adds its own version or user-agent header breaks its own preflight. Requests carry no browser credentials: cookies are never sent, and the allow-credentials header is never emitted.

The operations that declare Idempotency-Key are the creation of a session, the creation of an order and the confirmation of the payment. The update of a session, the revalidation, the update of the buyer identity and the checkout of an order declare neither the header nor the 422 idempotency_key_reused.

If a credential is compromised

Rotation has no grace window, and neither does revocation: the old secret stops authenticating the instant you call. Every page still serving it stops working at that moment. So the order is:

Issue a second credential with storefront_keys.create, with the same origins and scopes. The plaintext secret is returned exactly once — store it now, no later call returns it.

Deploy your site with the new secret and confirm it is live.

Revoke the first with storefront_keys.revoke. It is irreversible: there is no reactivation, and a storefront that has to work again needs a new credential. A revoke reason can be recorded with it.

rotate_secret keeps the public id, the name, the origins and the scopes and swaps only the secret — useful for a planned rotation where you control the deployment, not for an incident where the old secret is already out. Only one of two overlapping rotations of the same credential succeeds: the overlapping request is 409 resource_locked, which is retryable and carries no secret, and it changes nothing. A credential of another company that is held answers 404 storefront_key_not_found, never 409.

These management operations belong to the merchant and use the integrator credential, never the publishable one.

The shopper journey

Catalog. List or search the articles the company publishes. You get only what a shopper may see, plus three flags saying whether the article has variants, presentations or options. Categories feed the filter rail.

Selection. A configurable article must first resolve to the concrete thing that will be sold: resolve a selection answers with the resolved target and whether that combination can be offered. It is a read that travels as a POST because a selection does not fit in a query string — nothing is created and no idempotency key is needed.

Price. Resolve the price with the same pricing engine the merchant uses, so the storefront never computes an amount of its own. You get the unit price, currency, unit, quantity, tax and line total. You deliberately do not get which price list won or the breakdown — those are the merchant's business, not the shopper's. There is a bulk form for a whole listing page in one request.

Availability. Read it per item or in bulk. It is a read: it holds nothing, so two shoppers can see the same last unit and only one of them will get it. The figure is what is physically there minus what is already committed, and committed is reserved plus in_delivery_notes: the units that travel in order delivery notes that have not been delivered yet. A unit that is already on a delivery note of an order is no longer offered to the next shopper. The shape of the response does not change, only the value does; loose delivery notes, which come from no order, do not count.

Cart. Open a session. It stores the complete selection line by line and the amounts last resolved by the server, with the moment they were resolved. It requires an Idempotency-Key: retrying with the same key returns the same session instead of opening a second one. Sessions are open, and end as converted or abandoned.

Revalidate before charging. Revalidate re-resolves price and availability of every line and answers, line by line, whether the amount changed and whether there are still units. This is what lets your page say "this went up" or "this ran out" before taking money, instead of discovering it when the order is refused.

Order. Create it from the session. It is idempotent on two independent axes, kept apart on purpose: the required Idempotency-Key header identifies the request, and the optional external id identifies the order in your own system. The result is an ordinary sales order with channel: storefront, born as a draft and confirmed by its payment — see Sales orders. The request declares marketing_consent, whether the shopper accepts commercial communications; it is required, because it is declared instead of presumed in either direction. The marketing_consent that the response returns is the value saved with the order, not an echo of the request, and the merchant reads the same answer, with the moment it was recorded and the key it came through, on the detail of the order.

Fiscal identity, when it is needed. Complete the buyer identity is the step between a shopper who bought as a private individual and an order that must carry a full invoice. The body is partial: sending just the tax id leaves everything else untouched. It admits an order that is not invoiced yet: a draft, or one that its payment already confirmed.

Payment. Checkout returns the payment address, the instant it stops working and whether the effect was simulated. Amount, currency and gateway account are always the server's, resolved from the order: anything you send in the body is ignored, because accepting it would turn the route into a form for setting your own price.

Confirmation. Confirm the payment with the payment-session identifier the return address carries. It requires an Idempotency-Key and it is the only irreversible operation of the lane: when the payment holds it confirms the order if it is still a draft and then issues its invoice — a fiscal document that consumes correlative numbering and, with the billing register active, is filed with the tax administration. The invoice is dated the day it is issued; when the first day the payment was verified is a different one, that day is declared as the operation date. The payment is recorded first: if invoicing does not complete, the payment stays verified so that the merchant can retry the invoice.

Tracking. Follow the shipment. Seventeen fields always travel, and an order that has not shipped is neither an error nor a not-found: it answers with has_shipment in false, the data fields empty, zero packages and both lists empty. Render absence as absence.

The flat keys (status, carrier, expected_delivery_date, tracking_number, tracking_url, package_count) keep describing the most recent shipment, the one that is moving now. Six more flat keys give the moments of that shipment: prepared_at, handed_over_at, in_transit_at, delivered_at and failed_at (each an ISO 8601 instant, null until it happens) and attempt, the number of the delivery attempt, which is null while none has failed.

An order can leave in several shipments, so shipments[] lists all of them, oldest first and at most the 20 most recent. Each one carries its stage (preparing, handed_over, in_transit, delivered or failed), its status, carrier, tracking data, the same five instants and attempt, and its lines[] with description, quantity and unit. pending[] lists what has not left yet, one entry per order line with a quantity still to ship. Before any shipment exists, order_expected_delivery_date is the delivery date agreed for the whole order, so the shopper can be told something other than "nothing yet".

When the shopper does not come back

The shopper does not have to return from the gateway for the sale to complete. The gateway also notifies Factuarea of the payment on its own, and that notice confirms the payment of the order with the same sequence as confirm-payment: it confirms the draft and issues the invoice. It is a call the gateway makes to Factuarea, not an operation of this API, so there is nothing to call and the shape of the call does not change for your integration.

The events that those payments leave in GET /v1/companies/{company}/integrations/events come out processed or with a discard_reason that already existed: storefront_order_payment, recurring_invoice_overlap or simplified_threshold_exceeded_without_recipient.

The merchant's view of the payment of an order (payment) and the retry of its invoice are functions of the web application: there is no v1 operation and no MCP tool for them. As an integrator you see the payment through the invoice of the order and through the integration events above.

A draft whose payment is already verified cannot be deleted: it is 422 sales_order_not_editable with subcode storefront_payment_verified, as described in Sales orders. A buyer without a contact is served to the generic buyer of the channel.

A payment that a buyer makes on an order that the merchant cancelled, or that was deleted, between the payment link and the confirmation is kept as to be refunded, and nothing is refunded on its own. The activity of the order carries a sales_order.payment_invoice_failed with metadata.code payment_on_cancelled_order or payment_on_deleted_order and a Spanish metadata.message with the amount and what to do. Administrators receive a notice of the category error with entity_type sales_order and data.kind storefront_payment_refund_due, which the notifications list also returns.

With the browser SDK

import { FactuareaStorefront } from "@factuarea/sdk/storefront";

const shop = new FactuareaStorefront({
  publishableKey: "sf_pk_xxxxxxxxxxxxxxxxxxxxxxxx",
  company: "01931b3e-7c4a-7f2e-9a8b-3c5d6e7f8a9b",
});

const page = await shop.products.list({ limit: 24, in_stock: true });
const [first] = page.data as Array<{ id: string }>;

const price = await shop.prices.resolve({ product_id: first.id, quantity: 1 });
const availability = await shop.availability.show({ product_id: first.id });

const session = (await shop.sessions.create({
  lines: [{ product_id: first.id, quantity: 1 }],
})) as { data: { id: string } };

await shop.sessions.revalidate(session.data.id);

The full walk-through, the typed errors and the idempotency behaviour are in the TypeScript SDK page.

Errors worth branching on

CodeStatusWhen
storefront_key_not_found401The credential does not exist.
storefront_key_revoked401It existed and was revoked.
storefront_origin_not_allowed401The domain is not declared on the credential.
storefront_session_expired422The cart lifetime elapsed; open another with the same lines.
storefront_session_already_converted422That cart already became an order.
storefront_session_abandoned422The cart was abandoned and is terminal.
insufficient_available_stock422A line asks for more units than are available.
sales_order_not_payable422The order is not in a state that admits payment.
missing_required_param422A line of the order has an article with no VAT rate and the company has no default sales VAT: param lines.N.vat_rate, and the message tells the shopper to contact the store.

Branch on code, never on message. The full list is the storefront error index.

Where to go next

On this page

Need a hand?Contact support