The execution examples on this page use merchant bridge 3 at POST /integrations/indiana. In record_only mode Longplay returns merchant-native instructions; the merchant owns provider credentials, native orders, fulfilment and consumption. The Longplay API uses protocol 0.10 and accepts no older protocol; its protocol is independent of the merchant bridge version.
Configure each App/environment independently. Scope contains no payment-provider account.
Declare only implemented profiles. Trials, discounts, tiers, seats, tax, subscription changes and refunds must match the instruction without dropping terms.
In record_only mode, the merchant must support the merchant bridge v4 operation.prepare command before Longplay can freeze a quote and produce merchantTerms. Submit the matching merchantConfirmation when confirming the quote.
Preparation uses POST /integrations/indiana with the X-Indiana-Merchant-Bridge-Version: 4 header and bridgeVersion: 4 envelope in both directions. Create the receiver's codec with the Server SDK's createMerchantBridgeProtocol({ manifest, authentication }); use decodeRequest to verify signatures, scope and preparation authority, and encodeResponse to sign the response.
This minimal bridge.describe manifest supports purchase quote preparation. Replace the scope identifiers with those of the current App/environment. Declare preparations in capabilities and include only implemented purchase, subscription_change or refund actions in preparationActions.
operation.prepare computes and returns terms for the saved intent in the signed request; it performs no payment, fulfilment or refund. After the user accepts the terms, merchantConfirmation carries the matching quoteTermsDigest and required consent references and versions.
The bridge v3 examples below retain the existing execution and lookup flows. Dispatch preparation requests by version to the v4 codec and preparation handler; copying the v3 handler or changing only its manifest does not implement operation.prepare.
The execution examples below use POST, application/json and X-Indiana-Merchant-Bridge-Version: 3. The strict envelope is bridgeVersion, requestId, scope, command and data; scope contains projectId, environmentId and environment, checked against trusted configuration.
Each HTTP attempt has a new requestId while business identity retains the original operationId. Limits are 16 KiB request and 256 KiB response; refuse redirects and use private, no-store for user responses. A 200/202 carries current facts rather than business completion. The SDK never automatically retries financial execution or opens Checkout.
User commands retain native login and CSRF. authorize binds the native user to the current Customer rather than trusting browser-selected identities. Console/GOP service requests use an environment-bound 32-byte base64url HMAC key kept on backends. A signature grants neither user-session issuance nor arbitrary financial authority.
The signature prefix indiana-merchant-bridge and the path /integrations/indiana are fixed protocol names that keep an earlier internal name for Longplay; use them exactly as shown.
Sign requests and responses separately (response direction is response), with at most 300 seconds clock tolerance. Use signMerchantBridgeMessage / verifyMerchantBridgeMessage and retain old keys for in-flight rotation. Financial commands also require fresh Server SDK operation authority, matching scope, Customer, instruction type and confirmedAt.
session.create, catalog.read, customer.commerce.read and presentation.resolve take {}. presentation.report takes {decisionId,eventId}. purchase.execute, operation.read, subscription.change and refund.execute take {operationId,customerId}. bridge.ping echoes challenge and bridge.describe returns declarations without business writes.
1import { createLongplayServer, createMerchantBridgeHandler, createMerchantBridgeAuthorityResolver, typeLongplayServerOptions, typeMerchantBridgeHandlerOptions, typeMerchantBridgeHandlers } from"@tinkerlandai/longplay-sdk/server";23// Your app provides its configuration, native login/CSRF check and commerce handlers.4typeNative = Required<MerchantBridgeHandlers>;5declare const serverOptions: LongplayServerOptions;6declare const manifest: MerchantBridgeHandlerOptions["manifest"];7declare const authentication: MerchantBridgeHandlerOptions["authentication"];8declare const authorizeNativeCommand: MerchantBridgeHandlerOptions["authorize"];9declare const native: {10 createSession: Native["session.create"];11 readCatalog: Native["catalog.read"];12 readCommerce: Native["customer.commerce.read"];13 resolvePresentation: Native["presentation.resolve"];14 reportPresentation: Native["presentation.report"];15 executePurchase: Native["purchase.execute"];16 readOperation: Native["operation.read"];17 changeSubscription: Native["subscription.change"];18 executeRefund: Native["refund.execute"];19};2021const longplay = createLongplayServer(serverOptions);22exportconstPOST = createMerchantBridgeHandler({23 manifest,24 authentication,25 authorize: authorizeNativeCommand,26 resolveOperationAuthority: createMerchantBridgeAuthorityResolver(longplay),27 handlers: {28"session.create": native.createSession,29"catalog.read": native.readCatalog,30"customer.commerce.read": native.readCommerce,31"presentation.resolve": native.resolvePresentation,32"presentation.report": native.reportPresentation,33"purchase.execute": native.executePurchase,34"operation.read": native.readOperation,35"subscription.change": native.changeSubscription,36"refund.execute": native.executeRefund,37 },38});39// Native handlers durably reserve the original operation before external effects.40// readOperation returns found or not_received and never starts an operation.
The resolver uses readSubscriptionOperation / readSubscriptionUpdate / readRefund and accepts only returned Longplay authority, never permission inferred from browser quotes or local status. Native handlers retain login, CSRF, durable unique execution reservation and provider idempotency; the SDK lookup is not a concurrency lock.
Browser createMerchantBridge uses native login and sends the current Customer's original operation. Call reset() on logout/account switch. Server Keys, HMAC secrets and refund-administration authority stay out of browsers.
Console performs signed Ping, discovery and available catalog reads. Capability/profile declarations establish configuration coverage, not payment, fulfilment, refund or recovery success. Verify user/service authority, same-operation concurrency, unknown results, late facts and scope isolation against the deployed receiver.
After authenticating the native user, the backend calls Longplay createCustomerSession and returns its accessToken/refreshToken pair only to that user. Merchants do not mint Longplay tokens; Customer and Server-Key authority remain separate. Longplay provides accepted targeting and pinned Offering/Paywall; report actual presentation with a stable eventId.
Catalog provider is merchant; merchantPriceId is an opaque native reference. Bind ProductVersion and Price explicitly. Amounts use minor currency units and catalog currency uses three lowercase letters. Credit packs use one_time and creditReset=none; subscriptions use month/year. creditPolicyId identifies native grant/expiry rules without authorizing duplicate grants.
Confirm the original Longplay operation using attach intent=confirm; the receiver cannot infer confirmation from a browser mutation.
Read fresh authority. Initial execution requires confirmedAt, initialExecutionAllowed=true, an unexpired instruction and support for every required profile.
Match operationId, Customer, configuration/connection revisions, Price lines, quantities, amounts, discounts, trial and tax; map the merchant provider on the backend.
A durable unique key covers App, environment, Customer and operationId. Reserve before provider calls and retain the same provider idempotency key; concurrency/redelivery returns the original execution.
operation.read is strictly read-only and returns lookup=found or not_received. found contains the original execution; not_received has execution=null and cannot create an operation or trigger another charge. Report payment, native fulfilment and Longplay recording separately. Checkout belongs only to an unfinished original purchase.
Return current native subscriptions, purchase history and balance tranches. Incomplete history cannot establish first-purchase eligibility. Clear snapshots on account change; the business backend continues authorizing access and consumption. Synchronize facts to Longplay only through trusted backends.
subscription.change and refund.execute use the same fresh authority, original-operation lookup and durable idempotency. Follow cancellation/resumption/plan/seats/quantity/billing-cycle/proration instructions; report scheduled separately from applied. Refunds bind the original Invoice, amount, currency and entitlement policy, including required subscription cancellations.
After a lost response or provider timeout, recover the same operationId. RESULT_UNKNOWN requires retryable=false and recovery=recover_operation. Do not create a new purchase, automatically retry financial effects or infer nonexecution from pending. Closing the page only stops waiting; reconcile and deliver late facts from the original confirmed execution.
Verify native provider results and durably retain normalized facts alongside settlement/recovery, then call recordMerchantEvent with a Server Key holding billing:write. Longplay uses /api/v1/merchant/events/record and current X-Indiana-Protocol rather than the bridge envelope. Merchant records require no Stripe objects or provider secrets.
Original confirmed operation, order and reconciled Invoice/subscription; paid purchases require the full Invoice.
Closed purchase
purchase.closed
failed, expired or canceled without fabricated success.
Subscription
subscription.observed
Monotonic revision, complete items, valid period and hasDiscounts. A null operationId records a native subscription whose items are recurring Prices.
Change
subscription.change.completed
Original operation; scheduled requires scheduledFor while applied has no scheduled time.
Change closed
subscription.change.closed
Original change failed, expired or canceled before applying; keeps the subscription and optional unpaid Invoice reference.
Payment
invoice.paid
Complete Invoice lines, amounts and periods. A renewal names its native subscription; a one-time native payment, such as a credit pack or automatic top-up, uses null.
Refund
refund.updated
Stable refund reference, positive amount, currency and actual state. A native refund uses a null operationId and names its Invoice with merchantInvoiceId; a later failed reverses the accepted refund. Card dispute funds are reported as a native refund under the dispute reference: withdrawn as succeeded, reinstated as failed.
Event set
Purchase
type
purchase.completed
Rule
Original confirmed operation, order and reconciled Invoice/subscription; paid purchases require the full Invoice.
Closed purchase
type
purchase.closed
Rule
failed, expired or canceled without fabricated success.
Subscription
type
subscription.observed
Rule
Monotonic revision, complete items, valid period and hasDiscounts. A null operationId records a native subscription whose items are recurring Prices.
Change
type
subscription.change.completed
Rule
Original operation; scheduled requires scheduledFor while applied has no scheduled time.
Change closed
type
subscription.change.closed
Rule
Original change failed, expired or canceled before applying; keeps the subscription and optional unpaid Invoice reference.
Payment
type
invoice.paid
Rule
Complete Invoice lines, amounts and periods. A renewal names its native subscription; a one-time native payment, such as a credit pack or automatic top-up, uses null.
Refund
type
refund.updated
Rule
Stable refund reference, positive amount, currency and actual state. A native refund uses a null operationId and names its Invoice with merchantInvoiceId; a later failed reverses the accepted refund. Card dispute funds are reported as a native refund under the dispute reference: withdrawn as succeeded, reinstated as failed.
Non-financial results
Scenario
type
Rule
Fulfilment
fulfillment.updated
Native fulfilment progress of an original dispatched operation; an unfinished fulfilment keeps the operation pending.
A native benefit issuance (resource, unit, quantity, expiry), a definite outcome that it was never issued, and its later state; the original issuance is kept.
Auto top-up authorization
authorization.updated
The actual state of a native auto_topup authorization; consent or revocation creates no payment.
Native usage and balance
usage.observed / balance.observed
A native consumption or reversal (a reversal names its recorded original), and a merchant-owned balance reading; neither is spendable in Longplay or replaces an entitlement check.
Coupon redemption
coupon.redeemed
Coupon use that did not go through a Longplay operation: carry grantId plus productVersionId and subscriptionId, or merchandiseId. Accepted in any payment execution mode.
Non-financial results
Fulfilment
type
fulfillment.updated
Rule
Native fulfilment progress of an original dispatched operation; an unfinished fulfilment keeps the operation pending.
A native benefit issuance (resource, unit, quantity, expiry), a definite outcome that it was never issued, and its later state; the original issuance is kept.
Auto top-up authorization
type
authorization.updated
Rule
The actual state of a native auto_topup authorization; consent or revocation creates no payment.
Native usage and balance
type
usage.observed / balance.observed
Rule
A native consumption or reversal (a reversal names its recorded original), and a merchant-owned balance reading; neither is spendable in Longplay or replaces an entitlement check.
Coupon redemption
type
coupon.redeemed
Rule
Coupon use that did not go through a Longplay operation: carry grantId plus productVersionId and subscriptionId, or merchandiseId. Accepted in any payment execution mode.
recordMerchantEvent is the single entry for merchant results. Except coupon.redeemed, these events are accepted only in record_only environments. Non-financial results create no Invoice, revenue, spendable balance or platform usage. They follow the same eventId replay and conflict rules: an identical fact under one revision is a duplicate, and an older revision is stale.
Native facts record real transactions that Longplay did not start. They record money and subscriptions and are never attributed to a Funnel Run. Never send native facts for an order, subscription, Invoice or refund that a Longplay operation created; use that operation's events. A native subscription records subscription facts only, without a holding or balance. Record a subscription before its Invoices, and an Invoice before its refunds. An older observation of the same refund does not change money.
Use an ISO occurredAt observation time. Retries retain both eventId and exact facts. Invoice lines retain Price, quantity, debit/credit amounts, discount, tax and period; sums reconcile with the Invoice and paidMinor equals totalMinor. Native subscriptions include every unique Price item.
A durable outbox delivers at least once with stable event IDs and follows upstream recovery/Retry-After. Retain permanent conflicts for resolution. providerVerified=false records merchant provenance; a receipt substitutes for neither native fulfilment nor Longplay operation completion. Reread actual state on both sides.
1{2"bridgeVersion": 3,3"requestId": "55555555-5555-4555-8555-555555555555",4"command": "purchase.execute",5"scope": {6"projectId": "44444444-4444-4444-8444-444444444444",7"environment": "sandbox",8"environmentId": "eeeeeeee-eeee-4eee-8eee-eeeeeeeeeeee"9 },10"error": {11"code": "MERCHANT_BRIDGE_TERMS_CHANGED",12"message": "The quoted Price no longer matches the native catalog.",13"retryable": false,14"recovery": "refresh_catalog"15 }16}
Preserve structured code, retryable and recovery. Stop dispatch on missing confirmation, scope mismatch, expiry or missing capability and resolve the cause. RESULT_UNKNOWN/RECOVERY_REQUIRED recover only the original operation. Longplay authentication failures indicate backend configuration rather than user logout; retain Longplay's own recording error envelope.