# Create Checkout — Polar

> Create a checkout session for one or more products. See the documentation

- Key: `polar-create-checkout`
- Type: Action (Write)
- Version: 0.0.2
- App: Polar (`polar`) — https://pipedream.com/apps/polar.md
- This page (HTML): https://pipedream.com/apps/polar/actions/create-checkout
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/polar/actions/create-checkout/create-checkout.mjs

## Description

Create a checkout session for one or more products. [See the documentation](https://polar.sh/docs/api-reference/checkouts/create-session)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `products` | `string[]` | Yes | List of product IDs available to select at checkout. Example: ["prod_123", "prod_456"]. The first product is selected by default. Options are loaded from the connected account. |
| `prices` | `object` | No | Optional mapping of product IDs to ad-hoc prices to create for those products. Example: { "prod_123": [{ "amountType": "fixed", "priceAmount": 1000, "priceCurrency": "usd" }] }. |
| `amount` | `integer` | No | Custom checkout amount in cents for products using custom pricing. Example: 1000 for $10.00. |
| `seats` | `integer` | No | Number of seats for seat-based pricing. Required for seat-based products. |
| `trialInterval` | `string` | No | Interval unit for the trial period. |
| `trialIntervalCount` | `integer` | No | Number of interval units for the trial period. Example: 14 with a trial interval of day. |
| `allowTrial` | `boolean` | No | Whether to enable the trial period for the checkout session. If false, the trial is disabled even if the selected product has one configured. |
| `discountId` | `string` | No | Select a discount or provide a custom Discount ID (UUID). |
| `customerId` | `string` | No | Select a customer or provide a custom Customer ID (UUID). Search by name, email, or Customer ID (UUID). Options are loaded from the connected account. |
| `customerEmail` | `string` | No | Pre-fill the customer's email address in the checkout form. |
| `customerName` | `string` | No | Pre-fill the customer's name in the checkout form. |
| `customerIpAddress` | `string` | No | Pre-fill the customer's IP address for the checkout session. |
| `customerBillingName` | `string` | No | Pre-fill the billing name for the checkout session. |
| `customerBillingAddress` | `object` | No | Pre-fill the customer's billing address. Example: { "line1": "123 Main St", "city": "New York", "state": "NY", "postalCode": "10001", "country": "US" }. |
| `customerTaxId` | `string` | No | Pre-fill the customer's tax ID for the checkout session. |
| `customerMetadata` | `object` | No | Additional key-value data copied to the created customer. Example: { "crmId": "cust_123" }. |
| `isBusinessCustomer` | `boolean` | No | Whether the customer is a business. If true, the customer must provide their full billing address and billing name. |
| `externalCustomerId` | `string` | No | Customer ID from your system. Example: crm_cust_98765. If a matching Polar customer exists, the order is linked to it. |
| `successUrl` | `string` | No | URL where the customer will be redirected after a successful payment. You can include checkout_id={CHECKOUT_ID}. |
| `returnUrl` | `string` | No | URL used by the checkout back button. |
| `embedOrigin` | `string` | No | Origin of the page embedding the checkout session, used to allow Polar's iframe to communicate with the parent page. |
| `locale` | `string` | No | Locale to use for the checkout session. Example: en-US. |
| `currency` | `string` | No | Presentment currency for the checkout session. |
| `subscriptionId` | `string` | No | ID of a subscription to upgrade. It must be on free pricing. Use the List Subscriptions action to discover options. |
| `allowDiscountCodes` | `boolean` | No | Whether customers can apply discount codes during checkout. |
| `requireBillingAddress` | `boolean` | No | Whether customers must fill their full billing address. |
| `metadata` | `object` | No | Additional key-value data copied to the resulting order or subscription. Example: { "orderId": "12345", "campaignId": "summer-sale" }. |
| `customFieldData` | `object` | No | Key-value object storing custom field values. Example: { "company_size": "50-100" }. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "polar",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "polar-create-checkout",
  arguments: {
    products: ["Products"],
    prices: "Prices",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "polar-create-checkout",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    polar: { authProvisionId: "apn_xxxxxxx" },
    products: ["Products"],
    prices: "Prices",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "polar-create-checkout",
    "configured_props": {
      "polar": { "authProvisionId": "apn_xxxxxxx" },
      "products": ["Products"],
      "prices": "Prices"
    }
  }'
```

---

- App: https://pipedream.com/apps/polar.md · All apps: https://pipedream.com/apps
