Skip to main content
This operation is only available on the server.

Required Permissions

  • checkout_configuration:create
  • plan:create

Usage

import { whopSdk } from "@/lib/whop-sdk";

const result = await whopSdk.payments.createCheckoutSession({
	// The affiliate code to use for the checkout session
	affiliateCode: "some string",

	// The metadata to use for the checkout session
	metadata: { any: "json" },

	// Pass this object to create a new plan for this checkout session
	plan: {
		// The interval at which the plan charges (renewal plans).
		billingPeriod: 10,

		// The company the plan should be created for.
		companyId: "biz_XXXXXXXX" /* Required! */,

		// The respective currency identifier for the plan.
		currency:
			"aed" /* Valid values: aed | all | amd | ape | ars | aud | bam | bgn | bhd | bob | brl | bsd | btc | cad | chf | clp | cop | crc | czk | dkk | dop | dzd | egp | etb | eth | eur | gbp | ghs | gmd | gtq | gyd | hkd | huf | idr | ils | inr | jmd | jod | jpy | kes | khr | krw | kwd | lkr | mad | mdl | mga | mkd | mnt | mop | mur | mxn | myr | nad | ngn | nok | nzd | omr | pen | php | pkr | pln | pyg | qar | ron | rsd | rub | rwf | sar | sek | sgd | thb | tnd | try | ttd | twd | tzs | usd | uyu | uzs | vnd | xcd | xof | zar */,

		// An array of custom field objects.
		customFields: [
			{
				// The type of the custom field.
				fieldType: "text" /* Valid values: text */ /* Required! */,

				// The ID of the custom field (if being updated)
				id: "xxxxxxxxxxx",

				// The name of the custom field.
				name: "some string" /* Required! */,

				// The order of the field.
				order: 10,

				// The placeholder value of the field.
				placeholder: "some string",

				// Whether or not the field is required.
				required: true,
			},
		],

		// The description of the plan.
		description: "some string",

		// The interval at which the plan charges (expiration plans).
		expirationDays: 10,

		// Whether to force the creation of a new plan even if one with the same attributes already exists.
		forceCreateNewPlan: true,

		// An image for the plan. This will be visible on the product page to customers.
		image: {
			// This ID should be used the first time you upload an attachment. It is the ID
			// of the direct upload that was created when uploading the file to S3 via the
			// mediaDirectUpload mutation.
			directUploadId: "xxxxxxxxxxx",

			// The ID of an existing attachment object. Use this when updating a resource and
			// keeping a subset of the attachments. Don't use this unless you know what you're doing.
			id: "xxxxxxxxxxx",
		},

		// An additional amount charged upon first purchase.
		initialPrice: "some string",

		// A personal description or notes section for the business.
		internalNotes: "some string",

		// An override for tax to specify for this specific plan.
		overrideTaxType:
			"exclusive" /* Valid values: exclusive | inclusive | unspecified */,

		// Indicates if the plan is a one time payment or recurring.
		planType: "one_time" /* Valid values: one_time | renewal */,

		// The product the plan is related to.
		productId: "xxxxxxxxxxx",

		// This is the release method the business uses to sell this plan.
		releaseMethod: "buy_now" /* Valid values: buy_now | waitlist */,

		// The amount the customer is charged every billing period.
		renewalPrice: "some string",

		// The title of the plan. This will be visible on the product page to customers.
		title: "some string",

		// The number of free trial days added before a renewal plan.
		trialPeriodDays: 10,

		// Shows or hides the plan from public/business view.
		visibility:
			"archived" /* Valid values: archived | hidden | quick_link | visible */,
	},

	// The ID of the plan to use for the checkout session
	planId: "xxxxxxxxxxx",

	// The URL to redirect the user to after the checkout session is created
	redirectUrl: "some string",
});

Example output

const result = {
	// The ID of the checkout session
	id: "xxxxxxxxxxx",

	// The ID of the plan to use for the checkout session
	planId: "xxxxxxxxxxx",
};

I