# Preview a refund and its access changes

Operation / SDK: `previewRefund` · `preview_refund` · `PreviewRefund`

Quote a full or partial refund and its entitlement action; no refund is made.

Last updated: 2026-11-06

[Web version](https://www.longplayai.com/docs/api/preview-refund)

<a id="request"></a>

## Request

- **Credential**: Server Key with `billing:read`. Call from your backend only.
- **SDK**: JavaScript `createLongplayServer().previewRefund` · Python `preview_refund` · Go `PreviewRefund`
- **Success**: HTTP 200

> 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.

- [Merchant-prepared quotes](https://www.longplayai.com/docs/guides/merchant-execution.md#prepared-terms)

The response shows example data.

**cURL: request.sh**

```bash
curl -X POST "$LONGPLAY_API_URL/api/v1/subscriptions/refunds/preview" \
  -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \
  -H "X-Indiana-Protocol: 0.10" \
  -H "Content-Type: application/json" \
  -d '{
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",
  "requestId": "0f58d1f8-069f-4288-8ec1-4ed10af55b45",
  "invoiceId": "01d9f76a-62d9-4688-8804-b4734805f049",
  "mode": "partial",
  "amountMinor": 100,
  "entitlementAction": "retain"
}'
```

**TypeScript: previewRefund.ts**

```ts
import { createLongplayServer } from "@tinkerlandai/longplay-sdk/server";

const longplay = createLongplayServer({
  baseUrl: process.env.LONGPLAY_API_URL!,
  apiKey: process.env.LONGPLAY_SERVER_KEY!,
  scope: { projectId: process.env.LONGPLAY_PROJECT_ID!, environment: "sandbox" },
});

export async function previewRefund() {
  return longplay.previewRefund({
    customerId: "8b258f8b-4228-40fa-8d24-5b16428e686d",
    requestId: "0f58d1f8-069f-4288-8ec1-4ed10af55b45",
    invoiceId: "01d9f76a-62d9-4688-8804-b4734805f049",
    mode: "partial",
    amountMinor: 100,
    entitlementAction: "retain",
  });
}
```

**Request body: request.json**

```json
{
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",
  "requestId": "0f58d1f8-069f-4288-8ec1-4ed10af55b45",
  "invoiceId": "01d9f76a-62d9-4688-8804-b4734805f049",
  "mode": "partial",
  "amountMinor": 100,
  "entitlementAction": "retain"
}
```

**Response: response.json**

```json
{
  "requestId": "44f5fcb8-6ed8-41b8-818f-7571941c5fd5",
  "scope": {
    "projectId": "df5426d6-b335-403c-8f3e-b0f73d2e3511",
    "environment": "sandbox"
  },
  "quote": {
    "operationId": "a8b14e0c-6576-49a4-812c-7a1587e55255",
    "invoiceId": "01d9f76a-62d9-4688-8804-b4734805f049",
    "providerInvoiceId": "in_1Example",
    "currency": "USD",
    "paidMinor": 1000,
    "refundedMinor": 0,
    "pendingMinor": 0,
    "amountMinor": 1000,
    "mode": "full",
    "entitlementAction": "retain",
    "revokes": {
      "customerProductIds": [],
      "subscriptionIds": []
    },
    "execution": {
      "provider": "stripe",
      "executor": "indiana",
      "accountId": "acct_1Example",
      "invoice": "in_1Example",
      "amountMinor": 1000,
      "currency": "usd",
      "metadata": {
        "indianaRefundId": "a8b14e0c-6576-49a4-812c-7a1587e55255"
      },
      "idempotencyKey": "indiana-refund-a8b14e0c-6576-49a4-812c-7a1587e55255",
      "cancelSubscriptions": []
    },
    "expiresAt": "2099-01-01T00:00:00.000Z"
  }
}
```

<a id="parameters"></a>

## Body parameters

**application/json**

- `requestId` (uuid, required): Business request UUID. Reuse for retries of one operation; generate a new value for a new operation.
- `invoiceId` (uuid, required): invoice ID.
- `mode` (enum, required): Mode; see the allowed values. Values: `"full"`, `"partial"`.
- `amountMinor` (integer, optional): Amount in the currency's minor unit, such as cents. max: 200000000
- `entitlementAction` (enum, required): Keep (`retain`) or revoke (`revoke`) access after the refund. Values: `"retain"`, `"revoke"`.
- `customerId` (uuid, required): The Customer's UUID.

<a id="response"></a>

## Response fields

Every successful response includes `requestId` (this request's ID, for support) and `scope` (App and environment).

**HTTP 200 · application/json**

- `requestId` (uuid, required): UUID the server generated for this HTTP request; include it when reporting a problem. It is not your business requestId.
- `scope` (object, required): The App and environment of this response. Headers only verify scope; they cannot switch key scope.
- `scope.projectId` (string, required): App ID bound to the credential. minLength: 1
- `scope.environment` (enum, required): Separate data scope: sandbox or live. Values: `"sandbox"`, `"live"`.
- `quote` (object, required): Quote.
- `quote.operationId` (uuid, required): Business operation UUID. Subscription execution references operationId from previewAttach; balance refunds reference the original consumption.
- `quote.merchantTerms` (object, optional): Terms the merchant prepared; when present they decide the money and recurring commitment.
- `quote.merchantTerms.request` (object | object | object, required): Original preparation request, proving which selection these terms answer.
- `quote.merchantTerms.request.subject` (object | object | object, required): App, environment and Customer bound to the original preparation request.
- `quote.merchantTerms.request.operationId` (uuid | uuid | uuid, required): Business operation UUID. Subscription execution references operationId from previewAttach; balance refunds reference the original consumption.
- `quote.merchantTerms.request.configurationRevision` (integer | integer | integer, required): Configuration revision bound to the original preparation request.
- `quote.merchantTerms.request.connectionRevision` (integer | integer | integer, required): Merchant connection revision at preparation; a changed connection requires new preparation.
- `quote.merchantTerms.request.expiresAt` (date-time | date-time | date-time, required): Expiry time (ISO 8601, UTC).
- `quote.merchantTerms.request.action` ("purchase" | "subscription_change" | "refund", required): Business action. Target fields and quantity requirements vary by action; see the request structure and example.
- `quote.merchantTerms.request.mode` (enum | enum, optional): Mode; see the allowed values.
- `quote.merchantTerms.request.currency` (string | string | string, required): Currency code supported by the published price.
- `quote.merchantTerms.request.items` (array, optional): List items. minItems: 1 · maxItems: 100
- `quote.merchantTerms.request.offerRefs` (array | array, optional): Merchant offer references included in this selection.
- `quote.merchantTerms.request.merchantSubscriptionId` (string, optional): Merchant subscription reference being changed. minLength: 1 · maxLength: 200
- `quote.merchantTerms.request.change` (object | object | object | object | object | object, optional): The target of the change.
- `quote.merchantTerms.request.timing` (enum, optional): Immediate or end-of-cycle timing, only for supported plan-change actions. Values: `"immediate"`, `"renewal"`.
- `quote.merchantTerms.request.proration` (enum, optional): Proration behavior selected for this plan change. Values: `"none"`, `"create_prorations"`, `"always_invoice"`.
- `quote.merchantTerms.request.merchantInvoiceId` (string, optional): Merchant Invoice reference being refunded. minLength: 1 · maxLength: 200
- `quote.merchantTerms.request.amountMinor` (integer, optional): Amount in the currency's minor unit, such as cents. max: 200000000
- `quote.merchantTerms.request.entitlementAction` (enum, optional): Keep (`retain`) or revoke (`revoke`) access after the refund. Values: `"retain"`, `"revoke"`.
- `quote.merchantTerms.requestDigest` (string, required): Canonical digest of the original preparation request. pattern: ^[a-f0-9]{64}$
- `quote.merchantTerms.merchantQuoteId` (string, required): Merchant reference of this quote. minLength: 1 · maxLength: 200
- `quote.merchantTerms.quoteTermsDigest` (string, required): Canonical digest of these terms; confirmation binds it and later terms cannot replace it. pattern: ^[a-f0-9]{64}$
- `quote.merchantTerms.termsVersion` (string, required): Merchant terms version. minLength: 1 · maxLength: 200
- `quote.merchantTerms.sourceRevisions` (array, required): Catalog or subscription revisions this quote is based on. maxItems: 100
- `quote.merchantTerms.sourceRevisions.reference` (string, required): Reference of the data source behind the quote. minLength: 1 · maxLength: 200
- `quote.merchantTerms.sourceRevisions.revision` (string, required): Revision of the specific versioned resource; Customer profile updates have no revision. minLength: 1 · maxLength: 200
- `quote.merchantTerms.observedAt` (date-time, required): Timestamp (ISO 8601).
- `quote.merchantTerms.expiresAt` (date-time, required): Expiry time (ISO 8601, UTC).
- `quote.merchantTerms.currency` (string, required): Currency code supported by the published price. pattern: ^[A-Z]{3}$
- `quote.merchantTerms.automaticTax` (boolean, required): Whether the merchant calculates tax automatically; unknown tax is never treated as zero.
- `quote.merchantTerms.lines` (array, required): Line items. maxItems: 100
- `quote.merchantTerms.lines.merchantLineId` (string, required): Stable merchant-native invoice line reference, unique within the invoice. minLength: 1 · maxLength: 200
- `quote.merchantTerms.lines.merchantPriceId` (string | null, required): Merchant price reference of this line; null when none applies.
- `quote.merchantTerms.lines.quantity` (string, required): Quantity as a decimal string, avoiding floating-point error. pattern: ^(0|[1-9]\d{0,11})(\.\d{1,6})?$
- `quote.merchantTerms.lines.subtotalMinor` (integer, required): Amount in the currency's minor unit, such as cents. min: -200000000 · max: 200000000
- `quote.merchantTerms.lines.discountMinor` (integer, required): Amount in the currency's minor unit, such as cents. min: 0 · max: 200000000
- `quote.merchantTerms.lines.taxMinor` (integer | null, required): Amount in the currency's minor unit, such as cents.
- `quote.merchantTerms.lines.totalMinor` (integer | null, required): Amount in the currency's minor unit, such as cents.
- `quote.merchantTerms.subscriptionTerms` (object | null, required): Recurring commitment after this charge; null when not a subscription.
- `quote.merchantTerms.subscriptionTerms.items` (array, required): List items. minItems: 1 · maxItems: 100
- `quote.merchantTerms.subscriptionTerms.trial` (object | null, required): Trial.
- `quote.merchantTerms.subscriptionTerms.discount` (object | null, optional): Discount.
- `quote.merchantTerms.subscriptionTerms.discountExpiresAt` (date-time | null, optional): Timestamp (ISO 8601).
- `quote.merchantTerms.subscriptionTerms.initialAmountMinor` (integer, optional): Amount in the currency's minor unit, such as cents. min: 0 · max: 100000000
- `quote.merchantTerms.subtotalMinor` (integer, required): Amount in the currency's minor unit, such as cents. min: -200000000 · max: 200000000
- `quote.merchantTerms.discountMinor` (integer, required): Amount in the currency's minor unit, such as cents. min: 0 · max: 200000000
- `quote.merchantTerms.nativeDiscountMinor` (integer, optional): Amount in the currency's minor unit, such as cents. min: 0 · max: 200000000
- `quote.merchantTerms.discount` (object | null, optional): Discount.
- `quote.merchantTerms.discount.grantId` (uuid, required): grant ID.
- `quote.merchantTerms.discount.couponId` (uuid, required): Coupon UUID in the current App and environment.
- `quote.merchantTerms.discount.amountMinor` (integer, required): Amount in the currency's minor unit, such as cents. min: 0 · max: 100000000
- `quote.merchantTerms.discount.applicationPolicy` (enum, optional): How this offer combines with native price discounts: replace the native discount, or stack this offer with it. Values: `"replace"`, `"stack_native"`.
- `quote.merchantTerms.discount.applicableProductIds` (array, optional): Merchant-native Product identifiers eligible for this offer in the current App and environment. minItems: 1 · maxItems: 100
- `quote.merchantTerms.discount.terms` (object | object, required): Terms.
- `quote.merchantTerms.discount.duration` (object | object | object, required): Duration.
- `quote.merchantTerms.taxMinor` (integer | null, required): Amount in the currency's minor unit, such as cents.
- `quote.merchantTerms.totalMinor` (integer | null, required): Amount in the currency's minor unit, such as cents.
- `quote.merchantTerms.effectiveAt` (date-time | null, required): Timestamp (ISO 8601).
- `quote.merchantTerms.expectedEffects` (array, required): Native effects the merchant promises, shown for confirmation; not a platform balance. maxItems: 100
- `quote.merchantTerms.expectedEffects.reference` (string, required): Stable reference of this expected effect. minLength: 1 · maxLength: 200
- `quote.merchantTerms.expectedEffects.kind` (enum, required): Kind; see the allowed values. Values: `"grant"`, `"revoke"`, `"change"`.
- `quote.merchantTerms.expectedEffects.description` (string, required): Description. minLength: 1 · maxLength: 1000
- `quote.merchantTerms.expectedEffects.quantity` (string | null, required): Quantity as a decimal string, avoiding floating-point error.
- `quote.merchantTerms.expectedEffects.unit` (string | null, required): Merchant unit of the quantity; null when no quantity applies.
- `quote.merchantTerms.requiredConsents` (array, required): Merchant terms the user must accept before confirmation. maxItems: 20
- `quote.merchantTerms.requiredConsents.reference` (string, required): Stable reference of this required consent. minLength: 1 · maxLength: 200
- `quote.merchantTerms.requiredConsents.version` (string, required): Version number. minLength: 1 · maxLength: 200
- `quote.merchantTerms.requiredConsents.summary` (string, required): Summary of the consent shown to the user. minLength: 1 · maxLength: 1000
- `quote.invoiceId` (uuid, required): invoice ID.
- `quote.providerInvoiceId` (string, required): provider invoice ID. minLength: 1 · maxLength: 200
- `quote.currency` (enum, required): Currency code supported by the published price. Values: `"USD"`, `"EUR"`, `"CNY"`, `"GBP"`, `"JPY"`, `"CAD"`, `"AUD"`, `"NZD"`, `"CHF"`, `"HKD"`, `"SGD"`, `"KRW"`, `"INR"`, `"BRL"`, `"MXN"`, `"TWD"`, `"THB"`, `"IDR"`, `"MYR"`, `"PHP"`, `"VND"`, `"ZAR"`, `"AED"`, `"SAR"`, `"SEK"`, `"NOK"`, `"DKK"`, `"PLN"`, `"CZK"`, `"HUF"`, `"ILS"`, `"TRY"`, `"RON"`.
- `quote.paidMinor` (integer, required): Amount in the currency's minor unit, such as cents. min: 0 · max: 200000000
- `quote.refundedMinor` (integer, required): Amount in the currency's minor unit, such as cents. min: 0 · max: 200000000
- `quote.pendingMinor` (integer, required): Amount in the currency's minor unit, such as cents. min: 0 · max: 200000000
- `quote.amountMinor` (integer, required): Amount in the currency's minor unit, such as cents. max: 200000000
- `quote.mode` (enum, required): Mode; see the allowed values. Values: `"full"`, `"partial"`.
- `quote.entitlementAction` (enum, required): Keep (`retain`) or revoke (`revoke`) access after the refund. Values: `"retain"`, `"revoke"`.
- `quote.revokes` (object, required): What `entitlementAction: "revoke"` ends: the Customer's Products this invoice paid for and the Stripe subscriptions cancelled immediately with the refund. Both lists are empty when `entitlementAction` is `retain`.
- `quote.revokes.customerProductIds` (array, required): IDs of the Customer's Products (the same IDs as `membershipId`) paid for by this invoice that the refund ends: one-time Products immediately, subscription Products when their Stripe subscription is cancelled. maxItems: 100
- `quote.revokes.subscriptionIds` (array, required): subscription IDs. maxItems: 20
- `quote.execution` (object | object, required): Execution details.
- `quote.execution.provider` ("stripe" | "merchant", required): Payment provider; see the allowed values.
- `quote.execution.executor` (enum | "merchant", required): Executor; see the allowed values.
- `quote.execution.accountId` (string, optional): Stripe account ID (`acct_…`). pattern: ^acct_[A-Za-z0-9]+$
- `quote.execution.invoice` (string, optional): Stripe invoice ID (`in_…`). pattern: ^in_[A-Za-z0-9]+$
- `quote.execution.amountMinor` (integer | integer, required): Amount in the currency's minor unit, such as cents.
- `quote.execution.currency` (string | string, required): Currency code supported by the published price.
- `quote.execution.metadata` (object, optional): Custom key-value data.
- `quote.execution.metadata.indianaRefundId` (uuid, required): Refund operation ID (equal to `operationId`) that the Stripe refund must carry unchanged in its metadata, so the refund is matched to this operation.
- `quote.execution.idempotencyKey` (string, optional): Stable business idempotency key. The same key and payload replay the result; do not randomize on retries. pattern: ^indiana-refund-[0-9a-f-]{36}$
- `quote.execution.cancelSubscriptions` (array | array, required): Subscriptions to cancel.
- `quote.execution.operationId` (uuid, optional): Business operation UUID. Subscription execution references operationId from previewAttach; balance refunds reference the original consumption.
- `quote.execution.customerId` (uuid, optional): The Customer's UUID.
- `quote.execution.configurationRevision` (integer, optional): Scan configuration revision. min: 0 · max: 9007199254740991
- `quote.execution.connectionRevision` (integer, optional): Merchant connection revision frozen with this instruction, used to check that the original operation still uses the same connection configuration. min: 0 · max: 9007199254740991
- `quote.execution.expiresAt` (date-time, optional): Expiry time (ISO 8601, UTC).
- `quote.execution.type` ("refund", optional): Kind of original merchant instruction: purchase, subscription change or refund. It selects the frozen commercial parameters.
- `quote.execution.invoiceId` (uuid, optional): invoice ID.
- `quote.execution.merchantInvoiceId` (string, optional): Stable merchant-native Invoice reference for this refund. minLength: 1 · maxLength: 200
- `quote.execution.mode` (enum, optional): Mode; see the allowed values. Values: `"full"`, `"partial"`.
- `quote.execution.entitlementAction` (enum, optional): Keep (`retain`) or revoke (`revoke`) access after the refund. Values: `"retain"`, `"revoke"`.
- `quote.expiresAt` (date-time, required): Expiry time (ISO 8601, UTC).

<a id="errors"></a>

## Errors

Failures return an error object; handle them by `error.code` and `error.recovery`. The table lists the errors that follow from this operation's credential, scope and idempotency fields; depending on the request it can also return `NOT_FOUND` (a referenced resource doesn't exist), `NOT_CONFIGURED` (a required integration isn't connected) or `PAYLOAD_TOO_LARGE`. Some refusals, such as insufficient balance, are not errors but a `reason` in a successful response.

**Possible errors**

| code | HTTP | When | recovery |
| --- | --- | --- | --- |
| `INVALID_REQUEST` | 400 | The request doesn't match this page's parameters. A missing or malformed protocol header returns `UNSUPPORTED_PROTOCOL_VERSION` or `INVALID_PROTOCOL_VERSION` instead. | `fix_request` |
| `UNAUTHENTICATED` | 401 | The credential is missing, invalid, expired or revoked. | `authenticate` |
| `FORBIDDEN` | 403 | The credential lacks `billing:read`. | `check_permissions` |
| `SCOPE_MISMATCH` | 403 | `X-Indiana-Project` or `X-Indiana-Environment` doesn't match the credential's App and environment. | `check_scope` |
| `CONFLICT` | 409 | The same `requestId` was sent with different input (`reason: IDEMPOTENCY_CONFLICT`). | `resolve_conflict` |
| `RATE_LIMITED` | 429 | Too many requests; wait for `Retry-After` and retry the same request. | `retry_same_request` |
| `SERVICE_UNAVAILABLE` | 503 | The service is temporarily unavailable; retry the same request. | `retry_same_request` |
| `INTERNAL_ERROR` | 500 | The outcome is unknown; read the original operation or replay the original ID and input. | `recover_operation` |

- [Error codes and recovery](https://www.longplayai.com/docs/api/errors.md)
- [Request conventions](https://www.longplayai.com/docs/api.md)
- [All operations](https://www.longplayai.com/docs/api/operations.md#invoices)
