Class: Dodopayments::Models::Discount

Inherits:
Internal::Type::BaseModel show all
Defined in:
lib/dodopayments/models/discount.rb,
sig/dodopayments/models/discount.rbs

Overview

See Also:

  • Dodopayments::Resources::Discounts#create

Defined Under Namespace

Modules: CustomerEligibility Classes: CurrencyOption

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Internal::Type::BaseModel

==, #==, #[], coerce, #deconstruct_keys, #deep_to_h, dump, fields, hash, #hash, inherited, inspect, #inspect, known_fields, optional, recursively_to_h, required, #to_h, #to_json, #to_s, to_sorbet_type, #to_yaml

Methods included from Internal::Type::Converter

#coerce, coerce, #dump, dump, #inspect, inspect, meta_info, new_coerce_state, type_info

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(amount:, business_id:, code:, created_at:, customer_eligibility:, discount_id:, metadata:, preserve_on_plan_change:, restricted_to:, times_used:, type:, currency_options: nil, expires_at: nil, name: nil, per_customer_usage_limit: nil, starts_at: nil, subscription_cycles: nil, usage_limit: nil) ⇒ Object

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

Parameters:

  • amount (Integer)

    The discount amount in basis points (e.g., 540 => 5.4%).

  • business_id (String)

    The business this discount belongs to.

  • code (String)

    The discount code (up to 16 chars).

  • created_at (Time)

    Timestamp when the discount is created

  • customer_eligibility (Symbol, Dodopayments::Models::Discount::CustomerEligibility)

    Who may redeem this discount code.

  • discount_id (String)

    The unique discount ID

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

    Arbitrary key-value metadata. Values can be string, integer, number, or boolean.

  • preserve_on_plan_change (Boolean)

    Whether this discount should be preserved when a subscription changes plans.

  • restricted_to (Array<String>)

    List of product IDs to which this discount is restricted.

  • times_used (Integer)

    How many times this discount has been used.

  • type (Symbol, Dodopayments::Models::DiscountType)

    The type of discount (percentage or flat).

  • currency_options (Array<Dodopayments::Models::Discount::CurrencyOption>) (defaults to: nil)

    Per-currency options (flat deduction / percentage cap + minimum subtotal).

  • expires_at (Time, nil) (defaults to: nil)

    Optional date/time after which discount is expired.

  • name (String, nil) (defaults to: nil)

    Name for the Discount

  • per_customer_usage_limit (Integer, nil) (defaults to: nil)

    Maximum number of times a single customer may redeem this discount, if any.

  • starts_at (Time, nil) (defaults to: nil)

    Optional date/time before which the discount is not yet active. NULL = active im

  • subscription_cycles (Integer, nil) (defaults to: nil)

    Number of subscription billing cycles this discount is valid for.

  • usage_limit (Integer, nil) (defaults to: nil)

    Usage limit for this discount, if any.



# File 'lib/dodopayments/models/discount.rb', line 121

Instance Attribute Details

#amountInteger

The discount amount in basis points (e.g., 540 => 5.4%).

Parameters:

  • value (Integer)

Returns:

  • (Integer)


11
# File 'lib/dodopayments/models/discount.rb', line 11

required :amount, Integer

#business_idString

The business this discount belongs to.

Parameters:

  • value (String)

Returns:

  • (String)


17
# File 'lib/dodopayments/models/discount.rb', line 17

required :business_id, String

#codeString

The discount code (up to 16 chars).

Parameters:

  • value (String)

Returns:

  • (String)


23
# File 'lib/dodopayments/models/discount.rb', line 23

required :code, String

#created_atTime

Timestamp when the discount is created

Parameters:

  • value (Time)

Returns:

  • (Time)


29
# File 'lib/dodopayments/models/discount.rb', line 29

required :created_at, Time

#currency_optionsArray<Dodopayments::Models::Discount::CurrencyOption>?

Per-currency options (flat deduction / percentage cap + minimum subtotal). Empty for discounts without any configured currency options.



79
80
# File 'lib/dodopayments/models/discount.rb', line 79

optional :currency_options,
-> { Dodopayments::Internal::Type::ArrayOf[Dodopayments::Discount::CurrencyOption] }

#customer_eligibilitySymbol, Dodopayments::Models::Discount::CustomerEligibility

Who may redeem this discount code.

Parameters:

  • value (Dodopayments::Models::Discount::customer_eligibility)

Returns:



35
# File 'lib/dodopayments/models/discount.rb', line 35

required :customer_eligibility, enum: -> { Dodopayments::Discount::CustomerEligibility }

#discount_idString

The unique discount ID

Parameters:

  • value (String)

Returns:

  • (String)


41
# File 'lib/dodopayments/models/discount.rb', line 41

required :discount_id, String

#expires_atTime?

Optional date/time after which discount is expired.

Parameters:

  • value (Time, nil)

Returns:

  • (Time, nil)


86
# File 'lib/dodopayments/models/discount.rb', line 86

optional :expires_at, Time, nil?: true

#metadataHash{Symbol=>String, Float, Boolean}

Arbitrary key-value metadata. Values can be string, integer, number, or boolean.

Parameters:

  • value (Dodopayments::Models::metadata)

Returns:

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


47
# File 'lib/dodopayments/models/discount.rb', line 47

required :metadata, -> { Dodopayments::Internal::Type::HashOf[union: Dodopayments::MetadataItem] }

#nameString?

Name for the Discount

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


92
# File 'lib/dodopayments/models/discount.rb', line 92

optional :name, String, nil?: true

#per_customer_usage_limitInteger?

Maximum number of times a single customer may redeem this discount, if any.

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer, nil)


98
# File 'lib/dodopayments/models/discount.rb', line 98

optional :per_customer_usage_limit, Integer, nil?: true

#preserve_on_plan_changeBoolean

Whether this discount should be preserved when a subscription changes plans. Default: false (discount is removed on plan change)

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


54
# File 'lib/dodopayments/models/discount.rb', line 54

required :preserve_on_plan_change, Dodopayments::Internal::Type::Boolean

#restricted_toArray<String>

List of product IDs to which this discount is restricted.

Parameters:

  • value (::Array[String])

Returns:

  • (Array<String>)


60
# File 'lib/dodopayments/models/discount.rb', line 60

required :restricted_to, Dodopayments::Internal::Type::ArrayOf[String]

#starts_atTime?

Optional date/time before which the discount is not yet active. NULL = active immediately.

Parameters:

  • value (Time, nil)

Returns:

  • (Time, nil)


105
# File 'lib/dodopayments/models/discount.rb', line 105

optional :starts_at, Time, nil?: true

#subscription_cyclesInteger?

Number of subscription billing cycles this discount is valid for. If not provided, the discount will be applied indefinitely to all recurring payments related to the subscription.

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer, nil)


113
# File 'lib/dodopayments/models/discount.rb', line 113

optional :subscription_cycles, Integer, nil?: true

#times_usedInteger

How many times this discount has been used.

Parameters:

  • value (Integer)

Returns:

  • (Integer)


66
# File 'lib/dodopayments/models/discount.rb', line 66

required :times_used, Integer

#typeSymbol, Dodopayments::Models::DiscountType

The type of discount (percentage or flat).

Parameters:

  • value (Dodopayments::Models::discount_type)

Returns:



72
# File 'lib/dodopayments/models/discount.rb', line 72

required :type, enum: -> { Dodopayments::DiscountType }

#usage_limitInteger?

Usage limit for this discount, if any.

Parameters:

  • value (Integer, nil)

Returns:

  • (Integer, nil)


119
# File 'lib/dodopayments/models/discount.rb', line 119

optional :usage_limit, Integer, nil?: true

Class Method Details

.valuesArray<Symbol>

Returns:

  • (Array<Symbol>)


# File 'lib/dodopayments/models/discount.rb', line 172

Instance Method Details

#to_hash{

Returns:

  • ({)


87
# File 'sig/dodopayments/models/discount.rbs', line 87

def to_hash: -> {