Class: Pago::V2026_04::Models::DiscountPercentageCreate

Inherits:
Model
  • Object
show all
Defined in:
lib/pago/v2026_04/models.rb,
sig/pago/v2026_04/generated.rbs

Overview

Schema to create a percentage discount.

Constant Summary collapse

JSON_KEYS =

Returns:

  • (Hash[Symbol, String])
{
  metadata: "metadata",
  name: "name",
  code: "code",
  starts_at: "starts_at",
  ends_at: "ends_at",
  max_redemptions: "max_redemptions",
  products: "products",
  organization_id: "organization_id",
  type: "type",
  duration: "duration",
  duration_in_months: "duration_in_months",
  basis_points: "basis_points"
}.freeze
REQUIRED_KEYS =

Returns:

  • (Array[String])
["name", "duration", "basis_points"].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#==, #[], #field_set?, #hash, #inspect, json_keys, required_json_keys, #to_json, #to_json_hash, wrap_raw

Constructor Details

#initialize(metadata: ::Pago::UNSET, name:, code: ::Pago::UNSET, starts_at: ::Pago::UNSET, ends_at: ::Pago::UNSET, max_redemptions: ::Pago::UNSET, products: ::Pago::UNSET, organization_id: ::Pago::UNSET, type: ::Pago::UNSET, duration:, duration_in_months: ::Pago::UNSET, basis_points:) ⇒ DiscountPercentageCreate

Returns a new instance of DiscountPercentageCreate.

Parameters:

  • metadata: (Hash[String, untyped], nil) (defaults to: ::Pago::UNSET)
  • name: (String)
  • code: (String, nil) (defaults to: ::Pago::UNSET)
  • starts_at: (String, nil) (defaults to: ::Pago::UNSET)
  • ends_at: (String, nil) (defaults to: ::Pago::UNSET)
  • max_redemptions: (Integer, nil) (defaults to: ::Pago::UNSET)
  • products: (Array[String], nil) (defaults to: ::Pago::UNSET)
  • organization_id: (String, nil) (defaults to: ::Pago::UNSET)
  • type: (String, nil) (defaults to: ::Pago::UNSET)
  • duration: (String)
  • duration_in_months: (Integer, nil) (defaults to: ::Pago::UNSET)
  • basis_points: (Integer)


23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
# File 'lib/pago/v2026_04/models.rb', line 23213

def initialize(
  metadata: ::Pago::UNSET,
  name:,
  code: ::Pago::UNSET,
  starts_at: ::Pago::UNSET,
  ends_at: ::Pago::UNSET,
  max_redemptions: ::Pago::UNSET,
  products: ::Pago::UNSET,
  organization_id: ::Pago::UNSET,
  type: ::Pago::UNSET,
  duration:,
  duration_in_months: ::Pago::UNSET,
  basis_points:
)
  super()
  assign(:metadata, )
  assign(:name, name)
  assign(:code, code)
  assign(:starts_at, starts_at)
  assign(:ends_at, ends_at)
  assign(:max_redemptions, max_redemptions)
  assign(:products, products)
  assign(:organization_id, organization_id)
  assign(:type, type)
  assign(:duration, duration)
  assign(:duration_in_months, duration_in_months)
  assign(:basis_points, basis_points)
end

Instance Attribute Details

#basis_pointsInteger (readonly)

Discount percentage in basis points.

A basis point is 1/100th of a percent. For example, to create a 25.5% discount, set this to 2550.

Returns:

  • (Integer)


23211
23212
23213
# File 'lib/pago/v2026_04/models.rb', line 23211

def basis_points
  @basis_points
end

#codeString? (readonly)

Code customers can use to apply the discount during checkout. Must be between 3 and 256 characters long and contain only alphanumeric characters.If not provided, the discount can only be applied via the API.

Returns:

  • (String, nil)


23170
23171
23172
# File 'lib/pago/v2026_04/models.rb', line 23170

def code
  @code
end

#durationString (readonly)

Returns:

  • (String)


23195
23196
23197
# File 'lib/pago/v2026_04/models.rb', line 23195

def duration
  @duration
end

#duration_in_monthsInteger? (readonly)

Number of months the discount should be applied.

Required when duration is repeating. Must be omitted otherwise.

For this to work on yearly pricing, you should multiply this by 12. For example, to apply the discount for 2 years, set this to 24.

Returns:

  • (Integer, nil)


23204
23205
23206
# File 'lib/pago/v2026_04/models.rb', line 23204

def duration_in_months
  @duration_in_months
end

#ends_atString? (readonly)

Optional timestamp after which the discount is no longer redeemable.

Returns:

  • (String, nil)


23178
23179
23180
# File 'lib/pago/v2026_04/models.rb', line 23178

def ends_at
  @ends_at
end

#max_redemptionsInteger? (readonly)

Optional maximum number of times the discount can be redeemed.

Returns:

  • (Integer, nil)


23182
23183
23184
# File 'lib/pago/v2026_04/models.rb', line 23182

def max_redemptions
  @max_redemptions
end

#metadataHash{String => String, Integer, Float, Boolean} (readonly)

Key-value object allowing you to store additional information.

The key must be a string with a maximum length of 40 characters. The value must be either:

  • A string with a maximum length of 500 characters
  • An integer
  • A floating-point number
  • A boolean

You can store up to 50 key-value pairs.

Returns:

  • (Hash{String => String, Integer, Float, Boolean})


23162
23163
23164
# File 'lib/pago/v2026_04/models.rb', line 23162

def 
  @metadata
end

#nameString (readonly)

Name of the discount. Will be displayed to the customer when the discount is applied.

Returns:

  • (String)


23166
23167
23168
# File 'lib/pago/v2026_04/models.rb', line 23166

def name
  @name
end

#organization_idString? (readonly)

The ID of the organization owning the discount. Required unless you use an organization token.

Returns:

  • (String, nil)


23189
23190
23191
# File 'lib/pago/v2026_04/models.rb', line 23189

def organization_id
  @organization_id
end

#productsArray<String>? (readonly)

Returns:

  • (Array<String>, nil)


23185
23186
23187
# File 'lib/pago/v2026_04/models.rb', line 23185

def products
  @products
end

#starts_atString? (readonly)

Optional timestamp after which the discount is redeemable.

Returns:

  • (String, nil)


23174
23175
23176
# File 'lib/pago/v2026_04/models.rb', line 23174

def starts_at
  @starts_at
end

#typeString (readonly)

Returns:

  • (String)


23192
23193
23194
# File 'lib/pago/v2026_04/models.rb', line 23192

def type
  @type
end

Class Method Details

.from_json(data) ⇒ DiscountPercentageCreate?

Parameters:

  • data (Hash, String, nil)

Returns:



23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
# File 'lib/pago/v2026_04/models.rb', line 23244

def self.from_json(data)
  data = ::JSON.parse(data) if data.is_a?(String)
  data = ::Pago::Serde.object(data)
  return nil if data.nil?

  wrap_raw(
    new(
      metadata: (data.key?("metadata") ? data["metadata"] : ::Pago::UNSET),
      name: (data.key?("name") ? data["name"] : ::Pago::UNSET),
      code: (data.key?("code") ? data["code"] : ::Pago::UNSET),
      starts_at: (data.key?("starts_at") ? data["starts_at"] : ::Pago::UNSET),
      ends_at: (data.key?("ends_at") ? data["ends_at"] : ::Pago::UNSET),
      max_redemptions: (data.key?("max_redemptions") ? data["max_redemptions"] : ::Pago::UNSET),
      products: (data.key?("products") ? data["products"] : ::Pago::UNSET),
      organization_id: (data.key?("organization_id") ? data["organization_id"] : ::Pago::UNSET),
      type: (data.key?("type") ? data["type"] : ::Pago::UNSET),
      duration: (data.key?("duration") ? data["duration"] : ::Pago::UNSET),
      duration_in_months: (data.key?("duration_in_months") ? data["duration_in_months"] : ::Pago::UNSET),
      basis_points: (data.key?("basis_points") ? data["basis_points"] : ::Pago::UNSET)
    ),
    data
  )
end