Class: WhopSDK::Resources::Plans

Inherits:
Object
  • Object
show all
Defined in:
lib/whop_sdk/resources/plans.rb

Overview

Plans

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Plans

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Plans.

Parameters:



256
257
258
# File 'lib/whop_sdk/resources/plans.rb', line 256

def initialize(client:)
  @client = client
end

Instance Method Details

#create(company_id:, product_id:, billing_period: nil, checkout_styling: nil, currency: nil, custom_fields: nil, description: nil, expiration_days: nil, image: nil, initial_price: nil, internal_notes: nil, legacy_payment_method_controls: nil, override_tax_type: nil, payment_method_configuration: nil, plan_type: nil, release_method: nil, renewal_price: nil, split_pay_required_payments: nil, stock: nil, title: nil, trial_period_days: nil, unlimited_stock: nil, visibility: nil, request_options: {}) ⇒ WhopSDK::Models::Plan

Some parameter documentations has been truncated, see Models::PlanCreateParams for more details.

Create a new pricing plan for a product. The plan defines the billing interval, price, and availability for customers.

Required permissions:

  • ‘plan:create`

  • ‘access_pass:basic:read`

  • ‘plan:basic:read`

Parameters:

  • company_id (String)

    The unique identifier of the company to create this plan for.

  • product_id (String)

    The unique identifier of the product to attach this plan to.

  • billing_period (Integer, nil)

    The number of days between recurring charges. For example, 30 for monthly or 365

  • checkout_styling (WhopSDK::Models::PlanCreateParams::CheckoutStyling, nil)

    Checkout styling overrides for this plan. Pass null to inherit from the company

  • currency (Symbol, WhopSDK::Models::Currency, nil)

    The available currencies on the platform

  • custom_fields (Array<WhopSDK::Models::PlanCreateParams::CustomField>, nil)

    An array of custom field definitions to collect from customers at checkout.

  • description (String, nil)

    A text description of the plan displayed to customers on the product page.

  • expiration_days (Integer, nil)

    The number of days until the membership expires and access is revoked. Used for

  • image (WhopSDK::Models::PlanCreateParams::Image, nil)

    An image displayed on the product page to represent this plan.

  • initial_price (Float, nil)

    The amount charged on the first purchase. For one-time plans, this is the full p

  • internal_notes (String, nil)

    Private notes visible only to the business owner. Not shown to customers.

  • legacy_payment_method_controls (Boolean, nil)

    Whether this plan uses legacy payment method controls.

  • override_tax_type (Symbol, WhopSDK::Models::TaxType, nil)

    Whether or not the tax is included in a plan’s price (or if it hasn’t been set u

  • payment_method_configuration (WhopSDK::Models::PlanCreateParams::PaymentMethodConfiguration, nil)

    Explicit payment method configuration for the plan. When not provided, the compa

  • plan_type (Symbol, WhopSDK::Models::PlanType, nil)

    The type of plan that can be attached to a product

  • release_method (Symbol, WhopSDK::Models::ReleaseMethod, nil)

    The methods of how a plan can be released.

  • renewal_price (Float, nil)

    The amount charged each billing period for recurring plans. Provided in the plan

  • split_pay_required_payments (Integer, nil)

    The number of installment payments required before the subscription pauses.

  • stock (Integer, nil)

    The maximum number of units available for purchase. Ignored when unlimited_stock

  • title (String, nil)

    The display name of the plan shown to customers on the product page.

  • trial_period_days (Integer, nil)

    The number of free trial days before the first charge on a recurring plan.

  • unlimited_stock (Boolean, nil)

    Whether the plan has unlimited stock. When true, the stock field is ignored. Def

  • visibility (Symbol, WhopSDK::Models::Visibility, nil)

    Visibility of a resource

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



72
73
74
75
# File 'lib/whop_sdk/resources/plans.rb', line 72

def create(params)
  parsed, options = WhopSDK::PlanCreateParams.dump_request(params)
  @client.request(method: :post, path: "plans", body: parsed, model: WhopSDK::Plan, options: options)
end

#delete(id, request_options: {}) ⇒ Boolean

Permanently delete a plan from a product. Existing memberships on this plan will not be affected.

Required permissions:

  • ‘plan:delete`

Parameters:

  • id (String)

    The unique identifier of the plan to delete.

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (Boolean)

See Also:



244
245
246
247
248
249
250
251
# File 'lib/whop_sdk/resources/plans.rb', line 244

def delete(id, params = {})
  @client.request(
    method: :delete,
    path: ["plans/%1$s", id],
    model: WhopSDK::Internal::Type::Boolean,
    options: params[:request_options]
  )
end

#list(company_id:, after: nil, before: nil, created_after: nil, created_before: nil, direction: nil, first: nil, last: nil, order: nil, plan_types: nil, product_ids: nil, release_methods: nil, visibilities: nil, request_options: {}) ⇒ WhopSDK::Internal::CursorPage<WhopSDK::Models::PlanListResponse>

Returns a paginated list of plans belonging to a company, with optional filtering by visibility, type, release method, and product.

Required permissions:

  • ‘plan:basic:read`

Parameters:

  • company_id (String)

    The unique identifier of the company to list plans for.

  • after (String, nil)

    Returns the elements in the list that come after the specified cursor.

  • before (String, nil)

    Returns the elements in the list that come before the specified cursor.

  • created_after (Time, nil)

    Only return plans created after this timestamp.

  • created_before (Time, nil)

    Only return plans created before this timestamp.

  • direction (Symbol, WhopSDK::Models::Direction, nil)

    The direction of the sort.

  • first (Integer, nil)

    Returns the first n elements from the list.

  • last (Integer, nil)

    Returns the last n elements from the list.

  • order (Symbol, WhopSDK::Models::PlanListParams::Order, nil)

    The ways a relation of Plans can be ordered

  • plan_types (Array<Symbol, WhopSDK::Models::PlanType>, nil)

    Filter to only plans matching these billing types.

  • product_ids (Array<String>, nil)

    Filter to only plans belonging to these product identifiers.

  • release_methods (Array<Symbol, WhopSDK::Models::ReleaseMethod>, nil)

    Filter to only plans matching these release methods.

  • visibilities (Array<Symbol, WhopSDK::Models::VisibilityFilter>, nil)

    Filter to only plans matching these visibility states.

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/whop_sdk/resources/plans.rb', line 215

def list(params)
  parsed, options = WhopSDK::PlanListParams.dump_request(params)
  query = WhopSDK::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "plans",
    query: query,
    page: WhopSDK::Internal::CursorPage,
    model: WhopSDK::Models::PlanListResponse,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ WhopSDK::Models::Plan

Retrieves the details of an existing plan.

Required permissions:

  • ‘plan:basic:read`

Parameters:

  • id (String)

    The unique identifier of the plan.

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



92
93
94
95
96
97
98
99
# File 'lib/whop_sdk/resources/plans.rb', line 92

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["plans/%1$s", id],
    model: WhopSDK::Plan,
    options: params[:request_options]
  )
end

#update(id, billing_period: nil, checkout_styling: nil, currency: nil, custom_fields: nil, description: nil, expiration_days: nil, image: nil, initial_price: nil, internal_notes: nil, legacy_payment_method_controls: nil, offer_cancel_discount: nil, override_tax_type: nil, payment_method_configuration: nil, renewal_price: nil, stock: nil, strike_through_initial_price: nil, strike_through_renewal_price: nil, title: nil, trial_period_days: nil, unlimited_stock: nil, visibility: nil, request_options: {}) ⇒ WhopSDK::Models::Plan

Some parameter documentations has been truncated, see Models::PlanUpdateParams for more details.

Update a plan’s pricing, billing interval, visibility, stock, and other settings.

Required permissions:

  • ‘plan:update`

  • ‘access_pass:basic:read`

  • ‘plan:basic:read`

Parameters:

  • id (String)

    The unique identifier of the plan to update.

  • billing_period (Integer, nil)

    The number of days between recurring charges. For example, 30 for monthly or 365

  • checkout_styling (WhopSDK::Models::PlanUpdateParams::CheckoutStyling, nil)

    Checkout styling overrides for this plan. Pass null to remove all overrides and

  • currency (Symbol, WhopSDK::Models::Currency, nil)

    The available currencies on the platform

  • custom_fields (Array<WhopSDK::Models::PlanUpdateParams::CustomField>, nil)

    An array of custom field definitions to collect from customers at checkout.

  • description (String, nil)

    A text description of the plan displayed to customers on the product page.

  • expiration_days (Integer, nil)

    The number of days until the membership expires and access is revoked. For examp

  • image (WhopSDK::Models::PlanUpdateParams::Image, nil)

    An image displayed on the product page to represent this plan.

  • initial_price (Float, nil)

    The amount charged on the first purchase. Provided in the plan’s currency (e.g.,

  • internal_notes (String, nil)

    Private notes visible only to the business owner. Not shown to customers.

  • legacy_payment_method_controls (Boolean, nil)

    Whether this plan uses legacy payment method controls.

  • offer_cancel_discount (Boolean, nil)

    Whether to offer a retention discount when a customer attempts to cancel.

  • override_tax_type (Symbol, WhopSDK::Models::TaxType, nil)

    Whether or not the tax is included in a plan’s price (or if it hasn’t been set u

  • payment_method_configuration (WhopSDK::Models::PlanUpdateParams::PaymentMethodConfiguration, nil)

    Explicit payment method configuration for the plan. Sending null removes any cus

  • renewal_price (Float, nil)

    The amount charged each billing period for recurring plans. Provided in the plan

  • stock (Integer, nil)

    The maximum number of units available for purchase. Ignored when unlimited_stock

  • strike_through_initial_price (Float, nil)

    A comparison price displayed with a strikethrough for the initial price. Provide

  • strike_through_renewal_price (Float, nil)

    A comparison price displayed with a strikethrough for the renewal price. Provide

  • title (String, nil)

    The display name of the plan shown to customers on the product page.

  • trial_period_days (Integer, nil)

    The number of free trial days before the first charge on a recurring plan.

  • unlimited_stock (Boolean, nil)

    Whether the plan has unlimited stock. When true, the stock field is ignored.

  • visibility (Symbol, WhopSDK::Models::Visibility, nil)

    Visibility of a resource

  • request_options (WhopSDK::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



164
165
166
167
168
169
170
171
172
173
# File 'lib/whop_sdk/resources/plans.rb', line 164

def update(id, params = {})
  parsed, options = WhopSDK::PlanUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["plans/%1$s", id],
    body: parsed,
    model: WhopSDK::Plan,
    options: options
  )
end