Skip to documentation content

Square API usage

Prepare Square Order context with the HTTP API; signed Square events supply payment confirmation.

On this page

Keep Carden outside Square execution

Carden does not execute the provider operation

Carden prepares factual context; optional observations record what the merchant saw in Square.

  1. Prepare

    Request an Order fragment

    Use an inline invoice or an exact linked QuickBooks selector.

  2. Order

    Create the Square Order

    Add actual location and provider idempotency before CreateOrder.

  3. Pay

    Create the Payment

    Use the merchant payment source, order_id, amount, and separate idempotency.

  4. Confirm

    Receive signed Square events

    Carden verifies each webhook and records actual payment, refund, and dispute state.

Call the Carden API from a trusted server process with a Square-integration key. Square access tokens and payment idempotency remain in the merchant's Square code. Carden stores only the webhook subscription's signature key, encrypted, to verify deliveries; it cannot call Square.

Prepare a linked invoice for Square

Send POST /api/v1/square/order-enrichment/from-invoice from your backend with any HTTP client. A linked-invoice service needs invoices:read and enrichment:write. The request accepts the same exact invoice selector, amount, currency, expected revision, and preparation idempotency used by the stored-invoice model.

Prepare a linked invoice for Square

POST /api/v1/square/order-enrichment/from-invoice HTTP/1.1
Host: www.cardenpay.com
Authorization: Bearer <CARDEN_API_KEY>
Content-Type: application/json
Accept: application/json

{
  "invoiceId": "<INVOICE_ID>",
  "amountMinor": 11300,
  "currency": "usd",
  "expectedRevision": "<INVOICE_REVISION>",
  "idempotencyKey": "square_prepare_attempt_1042_1"
}

The response returns a Square Order fragment in data plus immutable preparation metadata, with a diagnostic x-carden-request-id header. Save preparation.id, merge only the data fragment, and add provider-owned location and idempotency fields yourself.

Prepare a payment automatically (HTTP API)

POST /api/v1/square/payment-preparations/from-invoice accepts the same invoice selector, exact full amount, currency, optional expectedRevision, and idempotency key, and chooses enhanced or ordinary mode itself. Enhanced mode returns the validated Square Order fragment. Ordinary mode returns null enrichment plus the optimization issues that prevented a faithful Order, such as fractional quantities or more than 200 lines; financial, source, and freshness problems still reject the request.

Prepare a Square payment automatically

POST /api/v1/square/payment-preparations/from-invoice HTTP/1.1
Host: www.cardenpay.com
Authorization: Bearer <CARDEN_API_KEY>
Content-Type: application/json
Accept: application/json

{
  "invoiceId": "<INVOICE_ID>",
  "amountMinor": 11300,
  "currency": "usd",
  "idempotencyKey": "prepare_attempt_1042_1"
}

  • Enhanced: merge data.enrichment into CreateOrder with your location_id and idempotency_key, then pass the returned order_id to CreatePayment.
  • Ordinary: create the payment exactly as you do today. Carden attempted no enhanced-data optimization and establishes no savings or fee for it.
  • Both modes: charge preparation.amountMinor in preparation.currency unchanged, and set CreatePayment reference_id to preparation.id so signed Square events link the payment to its invoice.

Optional Square payment observations

Carden confirms Square payments from signed webhook events once the subscription is set up. The report API remains available for an optional merchant observation, for example when webhooks are not yet configured; a report does not verify Square payment state or establish qualification or savings.

If reporting an observation, use the actual Square payment state with stable eventId and attemptId, lowercase currency, cumulative amounts, actual occurrence time, and factual provider references when known.

Submit an optional Square payment observation

POST /api/v1/square/payment-reports HTTP/1.1
Host: www.cardenpay.com
Authorization: Bearer <CARDEN_API_KEY>
Content-Type: application/json
Accept: application/json

{
  "eventId": "square_attempt_1042_captured_1",
  "attemptId": "square_attempt_1042_1",
  "paymentId": "<SQUARE_PAYMENT_ID>",
  "orderId": "<SQUARE_ORDER_ID>",
  "locationId": "<SQUARE_LOCATION_ID>",
  "status": "captured",
  "currency": "usd",
  "amountMinor": 11300,
  "capturedAmountMinor": 11300,
  "refundedAmountMinor": 0,
  "occurredAt": "2026-01-01T12:00:00.000Z",
  "enrichmentRequestId": "<PREPARATION_ID>",
  "invoiceReference": "INV-1042",
  "source": "api"
}

Understand the endpoint boundary

EndpointResponsibility
POST /api/v1/square/order-enrichmentValidate an inline CanonicalInvoice and return a mergeable Square Order fragment.
POST /api/v1/square/order-enrichment/from-invoiceRead one authorized linked invoice and return enrichment plus immutable preparation metadata.
POST /api/v1/square/payment-preparations/from-invoiceChoose enhanced or ordinary mode for one linked invoice and return the matching envelope.
POST /api/v1/square/payment-reportsValidate and record one immutable normalized Square observation.

None of these endpoints accept Square credentials or call CreateOrder or CreatePayment. Each request authenticates with a Square-integration Carden key and returns the v1 response envelope.

Test errors and recovery

  • Reject a Carden key issued for Stripe or QuickBooks even if its scope names match.
  • Correct factual 400 and 422 request failures without inventing source or provider data.
  • Reconcile 409 identity or cumulative-amount conflicts instead of blind retry.
  • Retry safe preparation or immutable reporting after 408, 429, 5xx, timeout, or connection failures.
  • Exercise ambiguous Square transport outcomes and out-of-order provider events without an extra payment.