Skip to main content
This function and all other functions in this graphql sdk are deprecated. Please migrate to the new rest api.
This operation is only available on the server.

Required Permissions

  • invoice:create
  • member:basic:read (optional)
  • plan:basic:read (optional)

Usage

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

const result = await whopSdk.invoices.createInvoice({
	// Whether or not to charge the customer a buyer fee.
	chargeBuyerFee: true,

	// The method of collection for this invoice. If using charge_automatically, you must provide a payment_token.
	collectionMethod:
		"charge_automatically" /* Valid values: charge_automatically | send_invoice */ /* Required! */,

	// The company ID to create this invoice for.
	companyId: "biz_XXXXXXXX",

	// The name of the customer to create this invoice for. This is required if you
	// want to create an invoice for a customer who does not have a member of your company yet.
	customerName: "some string",

	// The date the invoice is due, if applicable.
	dueDate: 1716931200 /* Required! */,

	// The email address to create this invoice for. This is required if you want to
	// create an invoice for a user who does not have a member of your company yet.
	emailAddress: "some string",

	// The member ID to create this invoice for. Include this if you want to create
	// an invoice for an existing member. If you do not have a member ID, you must
	// provide an email_address and customer_name.
	memberId: "xxxxxxxxxxx",

	// The payment method ID to use for this invoice. If using charge_automatically, you must provide a payment_method_id.
	paymentMethodId: "xxxxxxxxxxx",

	// The payment token ID to use for this invoice. If using charge_automatically, you must provide a payment_token.
	paymentTokenId: "xxxxxxxxxxx",

	// The properties of the plan to create for this invoice.
	plan: {
		// The interval at which the plan charges (renewal plans).
		billingPeriod: 10,

		// 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,

		// An additional amount charged upon first purchase. Use only if a one time
		// payment OR you want to charge an additional amount on top of the renewal
		// price. Provided as a number in dollars. Eg: 10.43 for $10.43
		initialPrice: "some string",

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

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

		// 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. Use only if a
		// recurring payment. Provided as a number in dollars. Eg: 10.43 for $10.43
		renewalPrice: "some string",

		// The number of units available for purchase.
		stock: 10,

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

		// Limits/doesn't limit the number of units available for purchase.
		unlimitedStock: true,

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

	// The properties of the product to create for this invoice. Include this if you want to create an invoice for a new product.
	product: {
		// The ID of the product tax code to apply to this product.
		productTaxCodeId: "xxxxxxxxxxx",

		// The title of the product.
		title: "some string" /* Required! */,
	},

	// The product ID to create this invoice for. Include this if you want to create an invoice for an existing product.
	productId: "xxxxxxxxxxx",
});

Example output

const result = {
	// The invoice that was created for this invoice.
	invoice: {
		// The ID of the invoice.
		id: "xxxxxxxxxxx",

		// The date the invoice was created.
		createdAt: 1716931200,

		// The status of the invoice.
		status: "open" /* Valid values: open | paid | past_due | void */,

		// The number of the invoice.
		number: "some string",

		// The date the invoice is due.
		dueDate: 1716931200,

		// The plan that the invoice was created for.
		currentPlan: {
			// The internal ID of the plan.
			id: "xxxxxxxxxxx",

			// The formatted price (including currency) for the plan.
			formattedPrice: "some string",

			// The respective currency identifier for the plan.
			baseCurrency:
				"aed" /* Valid values: aed | all | amd | ape | ars | aud | bam | bgn | bhd | bob | brl | bsd | btc | cad | chf | clp | cny | 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 */,
		},

		// The member that the invoice was created for.
		member: {
			// The internal ID of the user account for the member.
			id: "xxxxxxxxxxx",

			// The digital mailing address of the member.
			email: "some string",

			// The written name of the member.
			name: "some string",

			// The whop username of the member.
			username: "some string",
		},

		// The email address that the invoice was created for.
		emailAddress: "some string",

		// A signed token that allows fetching the invoice data publically without being authenticated.
		fetchInvoiceToken: "some string",
	},

	// The ID of the checkout job that was created for this invoice.
	checkoutJobId: "xxxxxxxxxxx",
};