Class: Stigg::Resources::V1::Coupons

Inherits:
Object
  • Object
show all
Defined in:
lib/stigg/resources/v1/coupons.rb

Overview

Operations related to coupons

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Coupons

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

Parameters:



204
205
206
# File 'lib/stigg/resources/v1/coupons.rb', line 204

def initialize(client:)
  @client = client
end

Instance Method Details

#archive_coupon(id, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon

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

Archives a coupon, preventing it from being applied to new subscriptions.

Parameters:

  • id (String)

    The unique identifier of the entity

  • x_account_id (String)

    Account ID — optional when authenticating with a user JWT (Bearer token); falls

  • x_environment_id (String)

    Environment ID — required when authenticating with a user JWT (Bearer token) on

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

Returns:

See Also:



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/stigg/resources/v1/coupons.rb', line 150

def archive_coupon(id, params = {})
  parsed, options = Stigg::V1::CouponArchiveCouponParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["api/v1/coupons/%1$s/archive", id],
    headers: parsed.transform_keys(
      x_account_id: "x-account-id",
      x_environment_id: "x-environment-id"
    ),
    model: Stigg::V1::Coupon,
    options: options
  )
end

#create(id:, amounts_off:, description:, duration_in_months:, metadata:, name:, percent_off:, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon

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

Creates a new discount coupon with percentage or fixed amount off, applicable to customer subscriptions.

Parameters:

  • id (String)

    Body param: The unique identifier for the entity

  • amounts_off (Array<Stigg::Models::V1::CouponCreateParams::AmountsOff>, nil)

    Body param: Fixed amount discounts in different currencies

  • description (String, nil)

    Body param: Description of the coupon

  • duration_in_months (Integer, nil)

    Body param: Duration of the coupon validity in months

  • metadata (Hash{Symbol=>String}, nil)

    Body param: Metadata associated with the entity

  • name (String)

    Body param: Name of the coupon

  • percent_off (Float, nil)

    Body param: Percentage discount off the original price

  • x_account_id (String)

    Header param: Account ID — optional when authenticating with a user JWT (Bearer

  • x_environment_id (String)

    Header param: Environment ID — required when authenticating with a user JWT (Bea

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

Returns:

See Also:



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/stigg/resources/v1/coupons.rb', line 39

def create(params)
  parsed, options = Stigg::V1::CouponCreateParams.dump_request(params)
  header_params = {x_account_id: "x-account-id", x_environment_id: "x-environment-id"}
  @client.request(
    method: :post,
    path: "api/v1/coupons",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Stigg::V1::Coupon,
    options: options
  )
end

#list(id: nil, after: nil, before: nil, created_at: nil, limit: nil, status: nil, type: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Internal::MyCursorIDPage<Stigg::Models::V1::CouponListResponse>

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

Retrieves a paginated list of coupons in the environment.

Parameters:

  • id (String)

    Query param: Filter by entity ID

  • after (String)

    Query param: Return items that come after this cursor

  • before (String)

    Query param: Return items that come before this cursor

  • created_at (Stigg::Models::V1::CouponListParams::CreatedAt)

    Query param: Filter by creation date using range operators: gt, gte, lt, lte

  • limit (Integer)

    Query param: Maximum number of items to return

  • status (Array<Symbol, Stigg::Models::V1::CouponListParams::Status>)

    Query param: Filter by coupon status. Supports comma-separated values for multip

  • type (Symbol, Stigg::Models::V1::CouponListParams::Type)

    Query param: Filter by coupon type (FIXED or PERCENTAGE)

  • x_account_id (String)

    Header param: Account ID — optional when authenticating with a user JWT (Bearer

  • x_environment_id (String)

    Header param: Environment ID — required when authenticating with a user JWT (Bea

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

Returns:

See Also:



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/stigg/resources/v1/coupons.rb', line 114

def list(params = {})
  query_params = [:id, :after, :before, :created_at, :limit, :status, :type]
  parsed, options = Stigg::V1::CouponListParams.dump_request(params)
  query = Stigg::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :get,
    path: "api/v1/coupons",
    query: query.transform_keys(created_at: "createdAt"),
    headers: parsed.except(*query_params).transform_keys(
      x_account_id: "x-account-id",
      x_environment_id: "x-environment-id"
    ),
    page: Stigg::Internal::MyCursorIDPage,
    model: Stigg::Models::V1::CouponListResponse,
    options: options
  )
end

#retrieve(id, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon

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

Retrieves a coupon by its unique identifier.

Parameters:

  • id (String)

    The unique identifier of the entity

  • x_account_id (String)

    Account ID — optional when authenticating with a user JWT (Bearer token); falls

  • x_environment_id (String)

    Environment ID — required when authenticating with a user JWT (Bearer token) on

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

Returns:

See Also:



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/stigg/resources/v1/coupons.rb', line 70

def retrieve(id, params = {})
  parsed, options = Stigg::V1::CouponRetrieveParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["api/v1/coupons/%1$s", id],
    headers: parsed.transform_keys(
      x_account_id: "x-account-id",
      x_environment_id: "x-environment-id"
    ),
    model: Stigg::V1::Coupon,
    options: options
  )
end

#update_coupon(id, description: nil, metadata: nil, name: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Coupon

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

Updates an existing coupon’s properties such as name, description, and metadata.

Parameters:

  • id (String)

    Path param: The unique identifier of the entity

  • description (String, nil)

    Body param: Description of the coupon

  • metadata (Hash{Symbol=>String}, nil)

    Body param: Metadata associated with the entity

  • name (String)

    Body param: Name of the coupon

  • x_account_id (String)

    Header param: Account ID — optional when authenticating with a user JWT (Bearer

  • x_environment_id (String)

    Header param: Environment ID — required when authenticating with a user JWT (Bea

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

Returns:

See Also:



188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/stigg/resources/v1/coupons.rb', line 188

def update_coupon(id, params = {})
  parsed, options = Stigg::V1::CouponUpdateCouponParams.dump_request(params)
  header_params = {x_account_id: "x-account-id", x_environment_id: "x-environment-id"}
  @client.request(
    method: :patch,
    path: ["api/v1/coupons/%1$s", id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Stigg::V1::Coupon,
    options: options
  )
end