Skip to content

Latest commit

 

History

History
618 lines (470 loc) · 45 KB

File metadata and controls

618 lines (470 loc) · 45 KB

Checkouts

Overview

Available Operations

  • list - List Checkout Sessions
  • create - Create Checkout Session
  • get - Get Checkout Session
  • update - Update Checkout Session
  • clientGet - Get Checkout Session from Client
  • clientUpdate - Update Checkout Session from Client
  • clientConfirm - Confirm Checkout Session from Client

list

List checkout sessions.

Scopes: checkouts:read checkouts:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.checkouts.list({
    organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
  });

  for await (const page of result) {
    console.log(page);
  }
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { checkoutsList } from "@polar-sh/sdk/funcs/checkoutsList.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await checkoutsList(polar, {
    organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
  });
  if (res.ok) {
    const { value: result } = res;
    for await (const page of result) {
    console.log(page);
  }
  } else {
    console.log("checkoutsList failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.CheckoutsListRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.CheckoutsListResponse>

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

create

Create a checkout session.

Scopes: checkouts:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.checkouts.create({
    customerName: "John Doe",
    customerBillingAddress: {
      country: "US",
    },
    locale: "en",
    products: [
      "<value 1>",
      "<value 2>",
      "<value 3>",
    ],
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { checkoutsCreate } from "@polar-sh/sdk/funcs/checkoutsCreate.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await checkoutsCreate(polar, {
    customerName: "John Doe",
    customerBillingAddress: {
      country: "US",
    },
    locale: "en",
    products: [
      "<value 1>",
      "<value 2>",
      "<value 3>",
    ],
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("checkoutsCreate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request components.CheckoutCreate ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.Checkout>

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

get

Get a checkout session by ID.

Scopes: checkouts:read checkouts:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.checkouts.get({
    id: "<value>",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { checkoutsGet } from "@polar-sh/sdk/funcs/checkoutsGet.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await checkoutsGet(polar, {
    id: "<value>",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("checkoutsGet failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.CheckoutsGetRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.Checkout>

Errors

Error Type Status Code Content Type
errors.ResourceNotFound 404 application/json
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

update

Update a checkout session.

Scopes: checkouts:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.checkouts.update({
    id: "<value>",
    checkoutUpdate: {
      customerName: "John Doe",
      customerBillingAddress: {
        country: "US",
      },
      locale: "en",
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { checkoutsUpdate } from "@polar-sh/sdk/funcs/checkoutsUpdate.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await checkoutsUpdate(polar, {
    id: "<value>",
    checkoutUpdate: {
      customerName: "John Doe",
      customerBillingAddress: {
        country: "US",
      },
      locale: "en",
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("checkoutsUpdate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.CheckoutsUpdateRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.Checkout>

Errors

Error Type Status Code Content Type
errors.AlreadyActiveSubscriptionError 403 application/json
errors.NotOpenCheckout 403 application/json
errors.PaymentNotReady 403 application/json
errors.TrialAlreadyRedeemed 403 application/json
errors.ResourceNotFound 404 application/json
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

clientGet

Get a checkout session by client secret.

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar();

async function run() {
  const result = await polar.checkouts.clientGet({
    clientSecret: "<value>",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { checkoutsClientGet } from "@polar-sh/sdk/funcs/checkoutsClientGet.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore();

async function run() {
  const res = await checkoutsClientGet(polar, {
    clientSecret: "<value>",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("checkoutsClientGet failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.CheckoutsClientGetRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.CheckoutPublic>

Errors

Error Type Status Code Content Type
errors.ResourceNotFound 404 application/json
errors.ExpiredCheckoutError 410 application/json
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

clientUpdate

Update a checkout session by client secret.

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar();

async function run() {
  const result = await polar.checkouts.clientUpdate({
    clientSecret: "<value>",
    checkoutUpdatePublic: {
      customerName: "John Doe",
      customerBillingAddress: {
        country: "US",
      },
      locale: "en",
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { checkoutsClientUpdate } from "@polar-sh/sdk/funcs/checkoutsClientUpdate.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore();

async function run() {
  const res = await checkoutsClientUpdate(polar, {
    clientSecret: "<value>",
    checkoutUpdatePublic: {
      customerName: "John Doe",
      customerBillingAddress: {
        country: "US",
      },
      locale: "en",
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("checkoutsClientUpdate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.CheckoutsClientUpdateRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.CheckoutPublic>

Errors

Error Type Status Code Content Type
errors.AlreadyActiveSubscriptionError 403 application/json
errors.NotOpenCheckout 403 application/json
errors.PaymentNotReady 403 application/json
errors.TrialAlreadyRedeemed 403 application/json
errors.ResourceNotFound 404 application/json
errors.ExpiredCheckoutError 410 application/json
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

clientConfirm

Confirm a checkout session by client secret.

Orders and subscriptions will be processed.

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.checkouts.clientConfirm({
    clientSecret: "<value>",
    checkoutConfirmStripe: {
      customerName: "John Doe",
      customerBillingAddress: {
        country: "US",
      },
      locale: "en",
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { checkoutsClientConfirm } from "@polar-sh/sdk/funcs/checkoutsClientConfirm.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await checkoutsClientConfirm(polar, {
    clientSecret: "<value>",
    checkoutConfirmStripe: {
      customerName: "John Doe",
      customerBillingAddress: {
        country: "US",
      },
      locale: "en",
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("checkoutsClientConfirm failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.CheckoutsClientConfirmRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.CheckoutPublicConfirmed>

Errors

Error Type Status Code Content Type
errors.PaymentError 400 application/json
errors.AlreadyActiveSubscriptionError 403 application/json
errors.NotOpenCheckout 403 application/json
errors.PaymentNotReady 403 application/json
errors.TrialAlreadyRedeemed 403 application/json
errors.ResourceNotFound 404 application/json
errors.ExpiredCheckoutError 410 application/json
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*