> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crossmint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Manage Subscriptions

> Subscribe to a plan, change it, or cancel it in the user's account at a merchant

An agent checkout can sign in to the user's account at a merchant and change a subscription: subscribe to a plan, change the plan, or cancel it. Write the change in the task. A browser profile keeps the user signed in for the next checkout.

<video className="w-full rounded-xl" autoPlay muted loop playsInline src="https://mintcdn.com/crossmint/eLFFFOlQTcnBWJ-s/images/agents/checkouts/subscription.mp4?fit=max&auto=format&n=eLFFFOlQTcnBWJ-s&q=85&s=da91def1c733a08fd6da7254667d4838" data-path="images/agents/checkouts/subscription.mp4" />

## Prerequisites

* **Agent Checkouts integration** — complete the [quickstart](/agents/agent-checkouts-quickstart).
* **Browser profile and sign-in** — a subscription belongs to the user's account at the merchant. See [Sign In to Stores](/agents/checkouts/merchant-sessions).
* **Server key** — a production key with `agent-checkouts.create`, `agent-checkouts.read`, `agent-checkouts.update`, and `agent-checkouts.cancel`.

## Change a Subscription

<Steps>
  <Step title="Write the change in the task">
    Name the plan and the change. To keep the user in control, tell the checkout to ask before it confirms the change.

    ```typescript theme={null}
    const response = await fetch("https://www.crossmint.com/api/unstable/agent-checkouts", {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            "X-API-KEY": process.env.CROSSMINT_SERVER_API_KEY!,
            "x-crossmint-user-id": "YOUR_USER_ID",
        },
        body: JSON.stringify({
            request: {
                startUrl: "https://streaming.example.com/account",
                task: "Sign in, open the subscription settings, and cancel the Premium plan. Before you confirm the cancellation, ask me to confirm. Then tell me the date when my access ends.",
            },
            browser: { profileId: "YOUR_BROWSER_PROFILE_ID" },
            constraints: { maxCost: { amount: "0.01", currency: "USD" } },
        }),
    });
    if (!response.ok) {
        throw new Error(`Could not start checkout: ${response.status}`);
    }
    const { runId } = await response.json();
    ```

    `constraints.maxCost` is required. A cancellation does not pay, so a very low cap makes sure that the checkout cannot buy anything.
  </Step>

  <Step title="Answer the sign-in and the confirmation">
    [Follow the checkout](/agents/checkouts/follow-run). It can ask for a sign-in, a one-time code, or your user's confirmation. Collect passwords and codes with `CrossmintProtectedInput`. See [Answer Questions](/agents/checkouts/buyer-inputs).
  </Step>

  <Step title="Show the result">
    When the checkout ends, read `result.summary`. It says what changed and when the change takes effect. Show it to your user.
  </Step>
</Steps>

## Subscribe to a Plan

To start a subscription, write the plan and the billing period in the task, for example "Subscribe to the monthly Premium plan". Set `maxCost` to the first charge. Then answer the payment request with an order intent. See [Pay for a Checkout](/agents/checkouts/payments).

When a merchant offers a one-time purchase and a subscription for the same product, for example "Subscribe and save", say in the task which one to choose.

<Note>Subscriptions depend on the card rail. Mastercard Agent Pay and the encrypted card support them. Visa Intelligent Commerce does not support subscriptions yet; support is coming.</Note>

## Common Gotchas

<AccordionGroup>
  <Accordion title="Later charges of a subscription">
    The order intent pays the first charge of a new subscription. The merchant charges later renewals with the card details that it keeps. This works with Mastercard Agent Pay and the encrypted card. Visa Intelligent Commerce does not support subscriptions yet, so a renewal on a Visa credential can fail. Before you offer subscriptions, test a renewal at the merchant.
  </Accordion>

  <Accordion title="The checkout cannot find the subscription">
    The user must be signed in to the account that has the subscription. Attach the same `browser.profileId` that the user signed in with, or tell the checkout which account to sign in to.
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={3}>
  <Card title="Sign In to Stores" icon="user-lock" href="/agents/checkouts/merchant-sessions">
    Keep the user signed in at a merchant
  </Card>

  <Card title="Answer Questions" icon="keyboard" href="/agents/checkouts/buyer-inputs">
    Collect sign-in details and confirmations
  </Card>

  <Card title="Create a Checkout" icon="brackets-curly" href="/api-reference/agent-checkouts/create-agent-checkout">
    Review the complete create request schema
  </Card>
</CardGroup>
