Class: AdvancedBilling::Event

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

Overview

Event Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(id:, key:, message:, subscription_id:, customer_id:, created_at:, event_specific_data:, additional_properties: {}) ⇒ Event

Returns a new instance of Event.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/advanced_billing/models/event.rb', line 128

def initialize(id:, key:, message:, subscription_id:, customer_id:,
               created_at:, event_specific_data:, additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @id = id
  @key = key
  @message = message
  @subscription_id = subscription_id
  @customer_id = customer_id
  @created_at = created_at
  @event_specific_data = event_specific_data
end

Instance Attribute Details

#created_atDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


35
36
37
# File 'lib/advanced_billing/models/event.rb', line 35

def created_at
  @created_at
end

#customer_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


31
32
33
# File 'lib/advanced_billing/models/event.rb', line 31

def customer_id
  @customer_id
end

#event_specific_dataObject

The schema varies based on the event key. The key-to-event data mapping is as follows:

  • ‘subscription_product_change` - SubscriptionProductChange

  • ‘subscription_state_change` - SubscriptionStateChange

  • ‘signup_success`, `delayed_signup_creation_success`, `payment_success`,

‘payment_failure`, `renewal_success`, `renewal_failure`, `chargeback_lost`, `chargeback_accepted`, `chargeback_closed` - PaymentRelatedEvents

  • ‘refund_success` - RefundSuccess

  • ‘component_allocation_change` - ComponentAllocationChange

  • ‘metered_usage` - MeteredUsage

  • ‘prepaid_usage` - PrepaidUsage

  • ‘dunning_step_reached` - DunningStepReached

  • ‘invoice_issued` - InvoiceIssued

  • ‘pending_cancellation_change` - PendingCancellationChange

  • ‘prepaid_subscription_balance_changed` -

PrepaidSubscriptionBalanceChanged

  • ‘subscription_group_signup_success` and

‘subscription_group_signup_failure` - SubscriptionGroupSignupEventData

  • ‘proforma_invoice_issued` - ProformaInvoiceIssued

  • ‘subscription_prepayment_account_balance_changed` -

PrepaymentAccountBalanceChanged

  • ‘payment_collection_method_changed` - PaymentCollectionMethodChanged

  • ‘subscription_service_credit_account_balance_changed` -

CreditAccountBalanceChanged

  • ‘item_price_point_changed` - ItemPricePointChanged

  • ‘custom_field_value_change` - CustomFieldValueChange

  • The rest, that is ‘delayed_signup_creation_failure`,

‘billing_date_change`, `expiration_date_change`, `expiring_card`, `customer_update`, `customer_create`, `customer_delete`, `upgrade_downgrade_success`, `upgrade_downgrade_failure`, `statement_closed`, `statement_settled`, `subscription_card_update`, `subscription_group_card_update`, `subscription_bank_account_update`, `refund_failure`, `upcoming_renewal_notice`, `trial_end_notice`, `direct_debit_payment_paid_out`, `direct_debit_payment_rejected`, `direct_debit_payment_pending`, `pending_payment_created`, `pending_payment_failed`, `pending_payment_completed`, don’t have event_specific_data defined, ‘renewal_success_recreated`, `renewal_failure_recreated`, `payment_success_recreated`, `payment_failure_recreated`, `subscription_deletion`, `subscription_group_bank_account_update`, `subscription_paypal_account_update`, `subscription_group_paypal_account_update`, `subscription_customer_change`, `account_transaction_changed`, `go_cardless_payment_paid_out`, `go_cardless_payment_rejected`, `go_cardless_payment_pending`, `stripe_direct_debit_payment_paid_out`, `stripe_direct_debit_payment_rejected`, `stripe_direct_debit_payment_pending`, `maxio_payments_direct_debit_payment_paid_out`, `maxio_payments_direct_debit_payment_rejected`, `maxio_payments_direct_debit_payment_pending`, `invoice_in_collections_canceled`, `subscription_added_to_group`, `subscription_removed_from_group`, `chargeback_opened`, `chargeback_lost`, `chargeback_accepted`, `chargeback_closed`, `chargeback_won`, `payment_collection_method_changed`, `component_billing_date_changed`, `subscription_term_renewal_scheduled`, `subscription_term_renewal_pending`, `subscription_term_renewal_activated`, `subscription_term_renewal_removed`

they map to ‘null` instead.

Returns:

  • (Object)


99
100
101
# File 'lib/advanced_billing/models/event.rb', line 99

def event_specific_data
  @event_specific_data
end

#idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


15
16
17
# File 'lib/advanced_billing/models/event.rb', line 15

def id
  @id
end

#keyEventKey

TODO: Write general description for this method

Returns:



19
20
21
# File 'lib/advanced_billing/models/event.rb', line 19

def key
  @key
end

#messageString

TODO: Write general description for this method

Returns:

  • (String)


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

def message
  @message
end

#subscription_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


27
28
29
# File 'lib/advanced_billing/models/event.rb', line 27

def subscription_id
  @subscription_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
171
172
173
174
# File 'lib/advanced_billing/models/event.rb', line 145

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  key = hash.key?('key') ? hash['key'] : nil
  message = hash.key?('message') ? hash['message'] : nil
  subscription_id =
    hash.key?('subscription_id') ? hash['subscription_id'] : nil
  customer_id = hash.key?('customer_id') ? hash['customer_id'] : nil
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               end
  event_specific_data = hash.key?('event_specific_data') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:EventEventSpecificData), hash['event_specific_data']
  ) : nil

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.
  Event.new(id: id,
            key: key,
            message: message,
            subscription_id: subscription_id,
            customer_id: customer_id,
            created_at: created_at,
            event_specific_data: event_specific_data,
            additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/advanced_billing/models/event.rb', line 102

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['key'] = 'key'
  @_hash['message'] = 'message'
  @_hash['subscription_id'] = 'subscription_id'
  @_hash['customer_id'] = 'customer_id'
  @_hash['created_at'] = 'created_at'
  @_hash['event_specific_data'] = 'event_specific_data'
  @_hash
end

.nullablesObject

An array for nullable fields



120
121
122
123
124
125
126
# File 'lib/advanced_billing/models/event.rb', line 120

def self.nullables
  %w[
    subscription_id
    customer_id
    event_specific_data
  ]
end

.optionalsObject

An array for optional fields



115
116
117
# File 'lib/advanced_billing/models/event.rb', line 115

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Event | Hash)

    value against the validation is performed.



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/advanced_billing/models/event.rb', line 182

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.id,
                            ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.key,
                              ->(val) { EventKey.validate(val) }) and
        APIHelper.valid_type?(value.message,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.subscription_id,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.customer_id,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.created_at,
                              ->(val) { val.instance_of? DateTime }) and
        UnionTypeLookUp.get(:EventEventSpecificData)
                       .validate(value.event_specific_data)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['id'],
                          ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['key'],
                            ->(val) { EventKey.validate(val) }) and
      APIHelper.valid_type?(value['message'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['subscription_id'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['customer_id'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['created_at'],
                            ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:EventEventSpecificData)
                     .validate(value['event_specific_data'])
  )
end

Instance Method Details

#to_custom_created_atObject



176
177
178
# File 'lib/advanced_billing/models/event.rb', line 176

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end