Class: AdvancedBilling::SubscriptionMigrationPreviewOptions

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/subscription_migration_preview_options.rb

Overview

SubscriptionMigrationPreviewOptions Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(product_id: SKIP, product_price_point_id: SKIP, include_trial: false, include_initial_charge: false, include_coupons: true, preserve_period: false, product_handle: SKIP, product_price_point_handle: SKIP, proration: SKIP, proration_date: SKIP, additional_properties: {}) ⇒ SubscriptionMigrationPreviewOptions

Returns a new instance of SubscriptionMigrationPreviewOptions.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 106

def initialize(product_id: SKIP, product_price_point_id: SKIP,
               include_trial: false, include_initial_charge: false,
               include_coupons: true, preserve_period: false,
               product_handle: SKIP, product_price_point_handle: SKIP,
               proration: SKIP, proration_date: SKIP,
               additional_properties: {})
  @product_id = product_id unless product_id == SKIP
  @product_price_point_id = product_price_point_id unless product_price_point_id == SKIP
  @include_trial = include_trial unless include_trial == SKIP
  @include_initial_charge = include_initial_charge unless include_initial_charge == SKIP
  @include_coupons = include_coupons unless include_coupons == SKIP
  @preserve_period = preserve_period unless preserve_period == SKIP
  @product_handle = product_handle unless product_handle == SKIP
  unless product_price_point_handle == SKIP
    @product_price_point_handle =
      product_price_point_handle
  end
  @proration = proration unless proration == SKIP
  @proration_date = proration_date unless proration_date == SKIP

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#include_couponsTrueClass | FalseClass

If ‘true` is sent, any coupons associated with the subscription will be applied to the migration. If `false` is sent, coupons will not be applied. Note: When migrating to a new product family, the coupon cannot migrate.

Returns:

  • (TrueClass | FalseClass)


39
40
41
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 39

def include_coupons
  @include_coupons
end

#include_initial_chargeTrueClass | FalseClass

If ‘true` is sent initial charges will be assessed.

Returns:

  • (TrueClass | FalseClass)


33
34
35
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 33

def include_initial_charge
  @include_initial_charge
end

#include_trialTrueClass | FalseClass

Whether to include the trial period configured for the product price point when starting a new billing period. Note that if preserve_period is set, then include_trial will be ignored.

Returns:

  • (TrueClass | FalseClass)


29
30
31
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 29

def include_trial
  @include_trial
end

#preserve_periodTrueClass | FalseClass

If ‘false` is sent, the subscription’s billing period will be reset to today and the full price of the new product will be charged. If ‘true` is sent, the billing period will not change and a prorated charge will be issued for the new product.

Returns:

  • (TrueClass | FalseClass)


46
47
48
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 46

def preserve_period
  @preserve_period
end

#product_handleString

The handle of the target Product. Either a product_id or product_handle must be present. A Subscription can be migrated to another product for both the current Product Family and another Product Family. Note: Going to another Product Family, components will not be migrated as well.

Returns:

  • (String)


53
54
55
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 53

def product_handle
  @product_handle
end

#product_idInteger

The ID of the target Product. Either a product_id or product_handle must be present. A Subscription can be migrated to another product for both the current Product Family and another Product Family. Note: Going to another Product Family, components will not be migrated as well.

Returns:

  • (Integer)


18
19
20
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 18

def product_id
  @product_id
end

#product_price_point_handleString

The ID or handle of the specified product’s price point. This can be passed to migrate to a non-default price point.

Returns:

  • (String)


58
59
60
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 58

def product_price_point_handle
  @product_price_point_handle
end

#product_price_point_idInteger

The ID of the specified product’s price point. This can be passed to migrate to a non-default price point.

Returns:

  • (Integer)


23
24
25
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 23

def product_price_point_id
  @product_price_point_id
end

#prorationProration

The ID or handle of the specified product’s price point. This can be passed to migrate to a non-default price point.

Returns:



63
64
65
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 63

def proration
  @proration
end

#proration_dateDateTime

The date that the proration is calculated from for the preview

Returns:

  • (DateTime)


67
68
69
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 67

def proration_date
  @proration_date
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 133

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  product_id = hash.key?('product_id') ? hash['product_id'] : SKIP
  product_price_point_id =
    hash.key?('product_price_point_id') ? hash['product_price_point_id'] : SKIP
  include_trial = hash['include_trial'] ||= false
  include_initial_charge = hash['include_initial_charge'] ||= false
  include_coupons = hash['include_coupons'] ||= true
  preserve_period = hash['preserve_period'] ||= false
  product_handle =
    hash.key?('product_handle') ? hash['product_handle'] : SKIP
  product_price_point_handle =
    hash.key?('product_price_point_handle') ? hash['product_price_point_handle'] : SKIP
  proration = Proration.from_hash(hash['proration']) if hash['proration']
  proration_date = if hash.key?('proration_date')
                     (DateTimeHelper.from_rfc3339(hash['proration_date']) if hash['proration_date'])
                   else
                     SKIP
                   end

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  SubscriptionMigrationPreviewOptions.new(product_id: product_id,
                                          product_price_point_id: product_price_point_id,
                                          include_trial: include_trial,
                                          include_initial_charge: include_initial_charge,
                                          include_coupons: include_coupons,
                                          preserve_period: preserve_period,
                                          product_handle: product_handle,
                                          product_price_point_handle: product_price_point_handle,
                                          proration: proration,
                                          proration_date: proration_date,
                                          additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 70

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['product_id'] = 'product_id'
  @_hash['product_price_point_id'] = 'product_price_point_id'
  @_hash['include_trial'] = 'include_trial'
  @_hash['include_initial_charge'] = 'include_initial_charge'
  @_hash['include_coupons'] = 'include_coupons'
  @_hash['preserve_period'] = 'preserve_period'
  @_hash['product_handle'] = 'product_handle'
  @_hash['product_price_point_handle'] = 'product_price_point_handle'
  @_hash['proration'] = 'proration'
  @_hash['proration_date'] = 'proration_date'
  @_hash
end

.nullablesObject

An array for nullable fields



102
103
104
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 102

def self.nullables
  []
end

.optionalsObject

An array for optional fields



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 86

def self.optionals
  %w[
    product_id
    product_price_point_id
    include_trial
    include_initial_charge
    include_coupons
    preserve_period
    product_handle
    product_price_point_handle
    proration
    proration_date
  ]
end

Instance Method Details

#to_custom_proration_dateObject



172
173
174
# File 'lib/advanced_billing/models/subscription_migration_preview_options.rb', line 172

def to_custom_proration_date
  DateTimeHelper.to_rfc3339(proration_date)
end