Class: WhopSDK::Resources::PromoCodes

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

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:



162
163
164
# File 'lib/whop_sdk/resources/promo_codes.rb', line 162

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 for a product or plan

Required permissions:

  • ‘promo_code:create`

  • ‘access_pass:basic:read`

Parameters:

  • amount_off (Float)

    The amount off (% or flat amount) for the promo.

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

    The monetary currency of the promo code.

  • code (String)

    The specific code used to apply the promo at checkout.

  • company_id (String)

    The id of the company to create the promo code for.

  • new_users_only (Boolean)

    Restricts promo use to only users who have never purchased from the company befo

  • promo_duration_months (Integer)

    The number of months this promo code is applied and valid for.

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

    The type (% or flat amount) of the promo.

  • churned_users_only (Boolean, nil)

    Restricts promo use to only users who have churned from the company before.

  • existing_memberships_only (Boolean, nil)

    Whether this promo code is for existing memberships only (cancelations)

  • expires_at (Time, nil)

    The date/time of when the promo expires.

  • one_per_customer (Boolean, nil)

    Restricts promo use to only be applied once per customer.

  • plan_ids (Array<String>, nil)

    The IDs of the plans that the promo code applies to. If product_id is provided,

  • product_id (String, nil)

    The product to lock the promo code to, if any. If provided will filter out any p

  • stock (Integer, nil)

    The quantity limit on the number of uses.

  • unlimited_stock (Boolean, nil)

    Whether or not the promo code should have unlimited stock.

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

Returns:

See Also:



53
54
55
56
57
58
59
60
61
62
# File 'lib/whop_sdk/resources/promo_codes.rb', line 53

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 further use

Required permissions:

  • ‘promo_code:delete`

Parameters:

  • id (String)

    The internal ID of the promo code to archive.

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

Returns:

  • (Boolean)

See Also:



150
151
152
153
154
155
156
157
# File 'lib/whop_sdk/resources/promo_codes.rb', line 150

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>

Lists promo codes for a company

Required permissions:

  • ‘promo_code:basic:read`

  • ‘access_pass:basic:read`

Parameters:

  • company_id (String)

    The ID 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)

    The minimum creation date to filter by

  • created_before (Time, nil)

    The maximum creation date to filter by

  • 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 promo codes by plan ID(s)

  • product_ids (Array<String>, nil)

    Filter promo codes by product ID(s)

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

    Statuses for promo codes

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

Returns:

See Also:



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/whop_sdk/resources/promo_codes.rb', line 123

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

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

Retrieves a promo code by ID

Required permissions:

  • ‘promo_code:basic:read`

  • ‘access_pass:basic:read`

Parameters:

  • id (String)

    The ID of the promo code to retrieve

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

Returns:

See Also:



80
81
82
83
84
85
86
87
# File 'lib/whop_sdk/resources/promo_codes.rb', line 80

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