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:



150
151
152
# File 'lib/stigg/resources/v1/coupons.rb', line 150

def initialize(client:)
  @client = client
end

Instance Method Details

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

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

Parameters:

  • id (String)

    The unique identifier of the entity

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

Returns:

See Also:



110
111
112
113
114
115
116
117
# File 'lib/stigg/resources/v1/coupons.rb', line 110

def archive_coupon(id, params = {})
  @client.request(
    method: :post,
    path: ["api/v1/coupons/%1$s/archive", id],
    model: Stigg::V1::Coupon,
    options: params[:request_options]
  )
end

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

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

Parameters:

  • id (String)

    The unique identifier for the entity

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

    Fixed amount discounts in different currencies

  • description (String, nil)

    Description of the coupon

  • duration_in_months (Integer, nil)

    Duration of the coupon validity in months

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

    Metadata associated with the entity

  • name (String)

    Name of the coupon

  • percent_off (Float, nil)

    Percentage discount off the original price

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

Returns:

See Also:



32
33
34
35
36
37
38
39
40
41
# File 'lib/stigg/resources/v1/coupons.rb', line 32

def create(params)
  parsed, options = Stigg::V1::CouponCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "api/v1/coupons",
    body: parsed,
    model: Stigg::V1::Coupon,
    options: options
  )
end

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

Retrieves a paginated list of coupons in the environment.

Parameters:

  • id (String)

    Filter by entity ID

  • after (String)

    Return items that come after this cursor

  • before (String)

    Return items that come before this cursor

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

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

  • limit (Integer)

    Maximum number of items to return

  • status (String)

    Filter by coupon status. Supports comma-separated values for multiple statuses

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

    Filter by coupon type (FIXED or PERCENTAGE)

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

Returns:

See Also:



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/stigg/resources/v1/coupons.rb', line 86

def list(params = {})
  parsed, options = Stigg::V1::CouponListParams.dump_request(params)
  query = Stigg::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "api/v1/coupons",
    query: query.transform_keys(created_at: "createdAt"),
    page: Stigg::Internal::MyCursorIDPage,
    model: Stigg::Models::V1::CouponListResponse,
    options: options
  )
end

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

Retrieves a coupon by its unique identifier.

Parameters:

  • id (String)

    The unique identifier of the entity

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

Returns:

See Also:



54
55
56
57
58
59
60
61
# File 'lib/stigg/resources/v1/coupons.rb', line 54

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["api/v1/coupons/%1$s", id],
    model: Stigg::V1::Coupon,
    options: params[:request_options]
  )
end

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

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

Parameters:

  • id (String)

    The unique identifier of the entity

  • description (String, nil)

    Description of the coupon

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

    Metadata associated with the entity

  • name (String)

    Name of the coupon

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

Returns:

See Also:



136
137
138
139
140
141
142
143
144
145
# File 'lib/stigg/resources/v1/coupons.rb', line 136

def update_coupon(id, params = {})
  parsed, options = Stigg::V1::CouponUpdateCouponParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["api/v1/coupons/%1$s", id],
    body: parsed,
    model: Stigg::V1::Coupon,
    options: options
  )
end