diff --git a/fsp-onboarding-api.yaml b/fsp-onboarding-api.yaml index 539f073..59f0e2a 100644 --- a/fsp-onboarding-api.yaml +++ b/fsp-onboarding-api.yaml @@ -9,18 +9,23 @@ info: - `GET` returns the fields the merchant fills in on the terminal. The Merchant API serves them to the terminal through - `GET /v1/terminals/onboard` in `merchant-pos-api.yaml`. + `GET /v1/terminals/{serialNumber}/onboard` in `merchant-pos-api.yaml`. - `POST` validates the values the merchant entered. The Merchant API sends - them from `POST /v1/terminals/onboard`, with the terminal's `merchantId` - added. + them from `POST /v1/terminals/{serialNumber}/onboard`, with the + terminal's `merchantId` added. The FSP owns the fields and the validation rules. + After the FSP accepts the values, the Merchant API gives the terminal an + API key and lets it take payments for the merchant. The Merchant API does + not verify the merchant itself. The FSP decides which proof to ask for, for + example a second factor, and limits the number of attempts. + ## One URL Both operations are served on one URL. The Merchant API holds that full - URL in its `fsp.onboarding_api` setting and calls it as is: `GET` for the - fields, `POST` for validation. The path below is where the testnet wallet + URL in its `fsp.onboarding_api` setting: `GET` for the fields, with + `merchantId` in the query, and `POST` for validation. The path below is where the testnet wallet backend serves it. ## Authentication @@ -38,10 +43,18 @@ paths: summary: Get the onboarding fields description: > Returns the fields the merchant fills in on the terminal, with their - metadata and validation rules. + metadata and validation rules. The fields may differ per merchant. tags: - onboarding security: [] + parameters: + - name: merchantId + in: query + required: true + description: The terminal's merchant in the Merchant API. The FSP may ignore it. + schema: + type: string + example: 7c1f4f9a-4b8e-4c7e-9c2a-2c5d4f2a1b3e responses: '200': description: The onboarding fields. @@ -131,7 +144,6 @@ components: summary: Values entered on the terminal value: merchantId: 7c1f4f9a-4b8e-4c7e-9c2a-2c5d4f2a1b3e - terminalSerialNumber: SN-AB12-9931 merchantCategoryCode: "5411" contactEmail: me@interledger.org diff --git a/merchant-api.yaml b/merchant-api.yaml index 4694288..759c7d7 100644 --- a/merchant-api.yaml +++ b/merchant-api.yaml @@ -397,9 +397,11 @@ paths: This call only creates the terminal *record* (serial number, manufacturer, model, EMV kernel). The supplied manufacturer/model must already be registered via `POST /v1/manufacturer-models`. - The device does the onboarding with `POST /v1/terminals/onboard` - (see `merchant-pos-api.yaml`). The onboarding submits the merchant - data. The API then links the device to its merchant. + The terminal is created `PROVISIONED`. The device does the onboarding + with `POST /v1/terminals/{serialNumber}/onboard` (see + `merchant-pos-api.yaml`). The onboarding submits the merchant data. The + API then links the device to its merchant, gives it its API key and + makes the terminal `ACTIVE`. The terminal's `serialNumber` must be unique within the system. requestBody: @@ -481,13 +483,17 @@ paths: Status transitions are validated: - | From | Allowed transitions | - |-----------|-----------------------| - | `ACTIVE` | `SUSPENDED`, `REVOKED` | - | `SUSPENDED` | `ACTIVE`, `REVOKED` | - | `REVOKED` | *(terminal state)* | - - Invalid transitions return `409 Conflict`. + | From | Allowed transitions | + |---------------|------------------------| + | `PROVISIONED` | `REVOKED` | + | `ACTIVE` | `SUSPENDED`, `REVOKED` | + | `SUSPENDED` | `ACTIVE`, `REVOKED` | + | `REVOKED` | *(terminal state)* | + + Invalid transitions return `409 Conflict`. Only onboarding makes a + `PROVISIONED` terminal `ACTIVE`, and only + `POST /v1/terminals/{terminalId}/reset` makes a terminal `PROVISIONED` + again. A `REVOKED` terminal's API key stops working. tags: - terminal requestBody: @@ -518,7 +524,7 @@ paths: tags: - terminal description: | - Soft-delete a terminal. The associated certificate is revoked + Soft-delete a terminal. Its API key is revoked and the device will no longer be able to authenticate. Historical records are preserved for audit purposes. responses: @@ -531,6 +537,36 @@ paths: '500': $ref: '#/components/responses/InternalError' + /v1/terminals/{terminalId}/reset: + parameters: + - $ref: '#/components/parameters/TerminalId' + post: + summary: Reset terminal + operationId: resetTerminal + tags: + - terminal + description: | + Return an `ACTIVE` or `SUSPENDED` terminal to `PROVISIONED` and revoke + its API key, so that the device can be onboarded again. Use it when the + key is lost or leaked. + + A terminal in another status returns `409 Conflict`. + responses: + '200': + description: Terminal reset; returns the new representation. + content: + application/json: + schema: + $ref: '#/components/schemas/Terminal' + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + '409': + $ref: '#/components/responses/Conflict' + '500': + $ref: '#/components/responses/InternalError' + /v1/webhooks/open-payments: post: summary: Receive Open Payments notification @@ -1187,7 +1223,7 @@ components: |-------------|----------------------------------------------------------| | `ACTIVE` | Terminal is operational and may transact. | | `SUSPENDED` | Temporarily disabled; can be reactivated. | - | `REVOKED` | Permanently disabled; certificate is revoked. Terminal state. | + | `REVOKED` | Permanently disabled; API key is revoked. Terminal state. | enum: [ACTIVE, SUSPENDED, REVOKED] example: SUSPENDED @@ -1224,8 +1260,16 @@ components: status: type: string x-go-type: string - description: Current lifecycle status of the terminal. - enum: [ACTIVE, SUSPENDED, REVOKED] + description: | + Current lifecycle status of the terminal. + + | Value | Meaning | + |---------------|------------------------------------------------| + | `PROVISIONED` | Registered, not onboarded; has no API key. | + | `ACTIVE` | Onboarded and may take payments. | + | `SUSPENDED` | Temporarily may not take payments; keeps its API key. | + | `REVOKED` | Permanently disabled; API key is revoked. | + enum: [PROVISIONED, ACTIVE, SUSPENDED, REVOKED] example: ACTIVE createdAt: type: string diff --git a/merchant-pos-api.yaml b/merchant-pos-api.yaml index 41afc57..a322127 100644 --- a/merchant-pos-api.yaml +++ b/merchant-pos-api.yaml @@ -7,7 +7,8 @@ info: that POS terminals call: - **Onboarding** — the terminal gets the onboarding form and submits the - merchant data. The API then links the terminal to its merchant. + merchant data. The API then links the terminal to its merchant and + returns the terminal's API key. - **Authorization** — the terminal sends the kernel output of a card transaction. The API returns the result of the issuer. - **Finalization** — the terminal sends its final decision on an approved @@ -22,6 +23,11 @@ info: terminal in the `X-API-Key` header. The onboarding endpoints require no authentication. A terminal has no API key before onboarding. + A successful onboarding returns the API key once. An API key belongs to + one terminal, and a terminal has at most one. The key stops working when + the terminal is reset, revoked or deleted. A terminal that lost its key is + reset by an operator and onboarded again. + ## Conventions * All requests and responses use `application/json` (UTF-8) unless @@ -46,14 +52,17 @@ tags: Authorize and finalize card transactions from a POS device. paths: - /v1/terminals/onboard: + /v1/terminals/{serialNumber}/onboard: + parameters: + - $ref: '#/components/parameters/SerialNumber' get: operationId: getTerminalOnboardingDefinition summary: Retrieve the terminal onboarding form definition description: > Returns the set of fields, their metadata and validation rules required - for a terminal to render the onboarding form. Public endpoint; no - authentication required. + for a terminal to render the onboarding form. The FSP chooses the fields + for the merchant of the terminal. Public endpoint; no authentication + required. tags: - pos-onboarding responses: @@ -66,6 +75,12 @@ paths: examples: default: $ref: '#/components/examples/OnboardingFormDefinitionExample' + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + '409': + $ref: '#/components/responses/Conflict' '500': $ref: '#/components/responses/InternalError' '502': @@ -75,9 +90,10 @@ paths: summary: Submit onboarding data and link a terminal to a merchant description: > Submits merchant data collected on the terminal, validates it against the - onboarding field model, verifies it via FSP and links the device - identified by terminalSerialNumber to the resolved merchant. This - endpoint requires no authentication. + onboarding field model, verifies it via FSP and links the terminal with + this serial number to its merchant. The terminal becomes `ACTIVE` and + the response carries its API key. This endpoint requires no + authentication. tags: - pos-onboarding requestBody: @@ -92,7 +108,8 @@ paths: responses: '200': description: > - Onboarding verified and terminal linked + Onboarding verified and terminal linked. The only response that + carries the API key. content: application/json: schema: @@ -119,7 +136,12 @@ paths: operationId: authorizeTransaction tags: - pos-authorization - description: Authorize a transaction for a POS device. + description: | + Authorize a transaction for a POS device. + + Only an `ACTIVE` terminal can authorize; another terminal with a valid + API key gets `403`. The API returns `404` when `terminalId` is unknown + or is not the terminal of the API key. security: - ApiKeyAuth: [] requestBody: @@ -145,6 +167,10 @@ paths: $ref: '#/components/responses/BadRequest' '401': $ref: '#/components/responses/Unauthorized' + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/TransactionConflict' '500': @@ -165,9 +191,12 @@ paths: Repeating the outcome a transaction was finalized with returns the same `200` again. The API returns `404` when the `requestId` is - unknown or belongs to another terminal, and `409` when the + unknown or belongs to another terminal, or when `terminalId` is not + the terminal of the API key, and `409` when the transaction is not in a state the outcome can apply to (see `TransactionConflict`). Problem `type` identifies each case. + + A terminal that was suspended after `/authorize` can still finalize. security: - ApiKeyAuth: [] parameters: @@ -218,12 +247,24 @@ paths: $ref: '#/components/responses/PaymentBadGateway' components: + parameters: + SerialNumber: + name: serialNumber + in: path + required: true + description: Hardware serial number of the terminal, percent-encoded. + schema: + type: string + minLength: 1 + maxLength: 128 + example: SN-AB12-9931 + securitySchemes: ApiKeyAuth: type: apiKey in: header name: X-API-Key - description: The API key of the POS terminal. + description: The API key that the terminal received at onboarding. responses: BadRequest: @@ -274,6 +315,22 @@ components: detail: Authentication credentials are invalid or expired. instance: 07cf97fa-7c93-4d22-8ad5-eba4116672e6 + Forbidden: + description: The API key is valid, but the terminal is not `ACTIVE`. + content: + application/problem+json: + schema: + $ref: '#/components/schemas/Problem' + examples: + terminalNotActive: + summary: Terminal is not active + value: + type: about:blank + title: Forbidden + status: 403 + detail: terminal is not active + instance: 07cf97fa-7c93-4d22-8ad5-eba4116672e6 + NotFound: description: Resource not found. content: @@ -366,19 +423,19 @@ components: instance: 07cf97fa-7c93-4d22-8ad5-eba4116672e6 Conflict: - description: The definition token is expired, a newer form definition replaces it, or the terminal is not awaiting onboarding. + description: The definition token does not match the current form definition, or the terminal is not awaiting onboarding. content: application/problem+json: schema: $ref: '#/components/schemas/Problem' examples: - definitionExpired: - summary: Definition token is expired + definitionChanged: + summary: Form definition has changed value: type: about:blank title: Conflict status: 409 - detail: definition token expired + detail: onboarding form has changed instance: 07cf97fa-7c93-4d22-8ad5-eba4116672e6 terminalNotOnboardable: summary: Terminal is not awaiting onboarding @@ -441,14 +498,16 @@ components: OnboardingResultExample: summary: Terminal linked value: - status: ONBOARDED + status: ACTIVE + terminalId: 9d2f7c10-5e3a-4b1f-8c2d-6e7f8a9b0c1d serialNumber: SN-AB12-9931 merchantId: 7c1f4f9a-4b8e-4c7e-9c2a-2c5d4f2a1b3e + apiKey: ilfpos_EXAMPLE-not-a-real-key-0000000000000000000 linkedAt: "2026-06-01T10:15:30Z" OnboardingSubmissionExample: summary: Example submission value: - definitionToken: "eyJhbGciOiJIUzI1NiJ9.eyJoIjoiOWYyYzhhMSIsImV4cCI6MTc4MDM0NjQwMH0.q8Xr2bV1nKpZ" + definitionToken: "9f2c8a1e4b7d03c6a5e8f1b2d4c7a0e3b6f9c2d5a8e1b4f7c0a3d6e9b2c5f8a1" data: businessName: Interledger Foundation legalEntityName: Interledger Foundation @@ -469,7 +528,7 @@ components: summary: Example onboarding form definition value: version: "2026-06-01" - definitionToken: "eyJhbGciOiJIUzI1NiJ9.eyJoIjoiOWYyYzhhMSIsImV4cCI6MTc4MDM0NjQwMH0.q8Xr2bV1nKpZ" + definitionToken: "9f2c8a1e4b7d03c6a5e8f1b2d4c7a0e3b6f9c2d5a8e1b4f7c0a3d6e9b2c5f8a1" title: Merchant onboarding fields: - key: businessName @@ -524,12 +583,18 @@ components: schemas: OnboardingResult: type: object - required: [status, serialNumber, merchantId] + required: [status, terminalId, serialNumber, merchantId, apiKey] properties: status: type: string - description: Outcome of the onboarding submission; `ONBOARDED` when the terminal was successfully linked to the merchant. - example: ONBOARDED + description: Outcome of the onboarding submission; `ACTIVE` when the terminal was successfully linked to the merchant and can take payments. + example: ACTIVE + terminalId: + type: string + format: uuid + x-go-type: string + description: Server-issued terminal identifier. The terminal sends it in its transaction requests. + example: 9d2f7c10-5e3a-4b1f-8c2d-6e7f8a9b0c1d serialNumber: type: string example: SN-AB12-9931 @@ -537,6 +602,14 @@ components: type: string description: Identifier of the merchant the terminal is now linked to. example: 7c1f4f9a-4b8e-4c7e-9c2a-2c5d4f2a1b3e + apiKey: + type: string + x-oapi-codegen-extra-tags: + sensitive: credential + description: > + The API key of the terminal, for the `X-API-Key` header. It is + returned only here and cannot be read again. Opaque; do not parse. + example: ilfpos_EXAMPLE-not-a-real-key-0000000000000000000 linkedAt: type: string format: date-time @@ -548,31 +621,23 @@ components: properties: definitionToken: type: string - x-oapi-codegen-extra-tags: - sensitive: credential + minLength: 1 description: > - The `definitionToken` from `GET /v1/terminals/onboard`, for the form - that the terminal shows. The API verifies the signature and the - expiry of the token. The API then validates `data` against the field - set of the token. If the token is missing or not valid, the API - returns 400. If the token is expired or replaced, the API returns - 409. Get the definition again, then submit again. - example: "eyJhbGciOiJIUzI1NiJ9.eyJoIjoiOWYyYzhhMSIsImV4cCI6MTc4MDM0NjQwMH0.q8Xr2bV1nKpZ" + The `definitionToken` from + `GET /v1/terminals/{serialNumber}/onboard`, for the form + that the terminal shows. If the token is missing, the API returns + 400. If it does not match the current form definition for this + terminal, the API returns 409. Get the definition again, then + submit again. + example: "9f2c8a1e4b7d03c6a5e8f1b2d4c7a0e3b6f9c2d5a8e1b4f7c0a3d6e9b2c5f8a1" data: type: object x-oapi-codegen-extra-tags: sensitive: dynamic description: > Map of submitted values keyed by FieldDefinition.key. - Additional properties are the field values. - properties: - terminalSerialNumber: - type: string - description: Hardware serial number identifying the terminal. - example: SN-AB12-9931 additionalProperties: true example: - terminalSerialNumber: SN-AB12-9931 businessName: Interledger Foundation legalEntityName: Interledger Foundation registrationNumber: "12345678" @@ -686,17 +751,13 @@ components: example: "2026-06-01" definitionToken: type: string - x-oapi-codegen-extra-tags: - sensitive: credential description: > - Opaque, server-signed token representing this exact form definition - (it embeds a hash of the served field set plus an expiry). The - terminal must send this value unchanged in its - `POST /v1/terminals/onboard` request. The API uses the value to - validate the submitted data against the same field set. The token - is stateless: the backend verifies its signature - and hash without any stored session. Treat as opaque — do not parse. - example: "eyJhbGciOiJIUzI1NiJ9.eyJoIjoiOWYyYzhhMSIsImV4cCI6MTc4MDM0NjQwMH0.q8Xr2bV1nKpZ" + Opaque value that identifies this exact form definition. It is not + a secret and does not expire. The terminal must send this value + unchanged in its `POST /v1/terminals/{serialNumber}/onboard` + request, so that the API can check that the terminal submits the + form that is current. Treat as opaque — do not parse. + example: "9f2c8a1e4b7d03c6a5e8f1b2d4c7a0e3b6f9c2d5a8e1b4f7c0a3d6e9b2c5f8a1" title: type: string description: Optional human-readable form title. @@ -731,7 +792,7 @@ components: type: string format: uuid x-go-type: string - description: Server-issued terminal identifier. + description: Server-issued terminal identifier. Must be the terminal of the API key. example: 9d2f7c10-5e3a-4b1f-8c2d-6e7f8a9b0c1d requestId: type: string @@ -944,8 +1005,8 @@ components: format: uuid x-go-type: string description: | - Server-issued terminal identifier. Must be the terminal that sent - `/v1/transactions/authorize`. + Server-issued terminal identifier. Must be the terminal of the API + key, and the one that sent `/v1/transactions/authorize`. example: 9d2f7c10-5e3a-4b1f-8c2d-6e7f8a9b0c1d outcome: $ref: '#/components/schemas/FinalizeOutcome'