Class: WhopSDK::Resources::PromoCodes

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

Overview

Promo codes

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ PromoCodes

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 PromoCodes.

Parameters:



168
169
170
# File 'lib/whop_sdk/resources/promo_codes.rb', line 168

def initialize(client:)
  @client = client
end

Instance Method Details

#create(amount_off:, base_currency:, code:, company_id:, new_users_only:, promo_duration_months:, promo_type:, churned_users_only: nil, existing_memberships_only: nil, expires_at: nil, one_per_customer: nil, plan_ids: nil, product_id: nil, stock: nil, unlimited_stock: nil, request_options: {}) ⇒ WhopSDK::Models::PromoCode

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

Create a new promo code that applies a discount at checkout. Can be scoped to specific products or plans.

Required permissions:

  • ‘promo_code:create`

  • ‘access_pass:basic:read`

unlimited_

Parameters:

  • amount_off (Float)

    The discount amount. When promo_type is percentage, this is the percent off (e.g

  • base_currency (Symbol, WhopSDK::Models::Currency)

    The three-letter ISO currency code for the promo code discount.

  • code (String)

    The alphanumeric code customers enter at checkout to apply the discount.

  • company_id (String)

    The unique identifier of the company to create this promo code for.

  • new_users_only (Boolean)

    Whether to restrict this promo code to only users who have never purchased from

  • promo_duration_months (Integer)

    The number of billing months the discount remains active. For example, 3 means t

  • promo_type (Symbol, WhopSDK::Models::PromoType)

    The discount type, either percentage or flat_amount.

  • churned_users_only (Boolean, nil)

    Whether to restrict this promo code to only users who have previously churned fr

  • existing_memberships_only (Boolean, nil)

    Whether this promo code can only be applied to existing memberships, such as for

  • expires_at (Time, nil)

    The datetime when the promo code expires and can no longer be used. Null means i

  • one_per_customer (Boolean, nil)

    Whether each customer can only use this promo code once.

  • plan_ids (Array<String>, nil)

    The identifiers of plans this promo code applies to. When product_id is also pro

  • product_id (String, nil)

    The identifier of the product to scope this promo code to. When provided, the pr

  • stock (Integer, nil)

    The maximum number of times this promo code can be used. Ignored when

  • unlimited_stock (Boolean, nil)

    Whether the promo code can be used an unlimited number of times.

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

Returns:

See Also:



56
57
58
59
60
61
62
63
64
65
# File 'lib/whop_sdk/resources/promo_codes.rb', line 56

def create(params)
  parsed, options = WhopSDK::PromoCodeCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "promo_codes",
    body: parsed,
    model: WhopSDK::PromoCode,
    options: options
  )
end

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

Archive a promo code, preventing it from being used in future checkouts. Existing memberships are not affected.

Required permissions:

  • ‘promo_code:delete`

Parameters:

  • id (String)

    The unique identifier of the promo code to archive.

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

Returns:

  • (Boolean)

See Also:



156
157
158
159
160
161
162
163
# File 'lib/whop_sdk/resources/promo_codes.rb', line 156

def delete(id, params = {})
  @client.request(
    method: :delete,
    path: ["promo_codes/%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, first: nil, last: nil, plan_ids: nil, product_ids: nil, status: nil, request_options: {}) ⇒ WhopSDK::Internal::CursorPage<WhopSDK::Models::PromoCodeListResponse>

Returns a paginated list of promo codes belonging to a company, with optional filtering by product, plan, and status.

Required permissions:

  • ‘promo_code:basic:read`

  • ‘access_pass:basic:read`

Parameters:

  • company_id (String)

    The unique identifier of the company to list promo codes 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 promo codes created after this timestamp.

  • created_before (Time, nil)

    Only return promo codes created before this timestamp.

  • first (Integer, nil)

    Returns the first n elements from the list.

  • last (Integer, nil)

    Returns the last n elements from the list.

  • plan_ids (Array<String>, nil)

    Filter to only promo codes scoped to these plan identifiers.

  • product_ids (Array<String>, nil)

    Filter to only promo codes scoped to these product identifiers.

  • status (Symbol, WhopSDK::Models::PromoCodeStatus, nil)

    Statuses for promo codes

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

Returns:

See Also:



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/whop_sdk/resources/promo_codes.rb', line 127

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

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

Retrieves the details of an existing promo code.

Required permissions:

  • ‘promo_code:basic:read`

  • ‘access_pass:basic:read`

Parameters:

  • id (String)

    The unique identifier of the promo code.

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

Returns:

See Also:



83
84
85
86
87
88
89
90
# File 'lib/whop_sdk/resources/promo_codes.rb', line 83

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