Class: AdvancedBilling::ApplyPaymentEventData

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

Overview

Example schema for an ‘apply_payment` event

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(consolidation_level:, memo:, original_amount:, applied_amount:, transaction_time:, payment_method:, transaction_id: SKIP, parent_invoice_number: SKIP, remaining_prepayment_amount: SKIP, prepayment: SKIP, external: SKIP, additional_properties: {}) ⇒ ApplyPaymentEventData

Returns a new instance of ApplyPaymentEventData.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 102

def initialize(consolidation_level:, memo:, original_amount:,
               applied_amount:, transaction_time:, payment_method:,
               transaction_id: SKIP, parent_invoice_number: SKIP,
               remaining_prepayment_amount: SKIP, prepayment: SKIP,
               external: SKIP, additional_properties: {})
  @consolidation_level = consolidation_level
  @memo = memo
  @original_amount = original_amount
  @applied_amount = applied_amount
  @transaction_time = transaction_time
  @payment_method = payment_method
  @transaction_id = transaction_id unless transaction_id == SKIP
  @parent_invoice_number = parent_invoice_number unless parent_invoice_number == SKIP
  unless remaining_prepayment_amount == SKIP
    @remaining_prepayment_amount =
      remaining_prepayment_amount
  end
  @prepayment = prepayment unless prepayment == SKIP
  @external = external unless external == SKIP

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

Instance Attribute Details

#applied_amountString

The amount of the payment applied to this invoice. Incoming payments can be split amongst several invoices, which will result in a ‘applied_amount` less than the `original_amount`. Example: A $100.99 payment, of which $40.11 is applied to this invoice, will have an `applied_amount` of `“40.11”`.

Returns:

  • (String)


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

def applied_amount
  @applied_amount
end

#consolidation_levelInvoiceConsolidationLevel

TODO: Write general description for this method



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

def consolidation_level
  @consolidation_level
end

#externalTrueClass | FalseClass

The Chargify id of the original payment

Returns:

  • (TrueClass | FalseClass)


64
65
66
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 64

def external
  @external
end

#memoString

The payment memo

Returns:

  • (String)


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

def memo
  @memo
end

#original_amountString

The full, original amount of the payment transaction as a string in full units. Incoming payments can be split amongst several invoices, which will result in a ‘applied_amount` less than the `original_amount`. Example: A $100.99 payment, of which $40.11 is applied to this invoice, will have an `original_amount` of `“100.99”`.

Returns:

  • (String)


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

def original_amount
  @original_amount
end

#parent_invoice_numberInteger

The Chargify id of the original payment

Returns:

  • (Integer)


52
53
54
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 52

def parent_invoice_number
  @parent_invoice_number
end

#payment_methodObject

A nested data structure detailing the method of payment

Returns:

  • (Object)


44
45
46
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 44

def payment_method
  @payment_method
end

#prepaymentTrueClass | FalseClass

The Chargify id of the original payment

Returns:

  • (TrueClass | FalseClass)


60
61
62
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 60

def prepayment
  @prepayment
end

#remaining_prepayment_amountString

The Chargify id of the original payment

Returns:

  • (String)


56
57
58
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 56

def remaining_prepayment_amount
  @remaining_prepayment_amount
end

#transaction_idInteger

The Chargify id of the original payment

Returns:

  • (Integer)


48
49
50
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 48

def transaction_id
  @transaction_id
end

#transaction_timeDateTime

The time the payment was applied, in ISO 8601 format, i.e. “2019-06-07T17:20:06Z”

Returns:

  • (DateTime)


40
41
42
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 40

def transaction_time
  @transaction_time
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



129
130
131
132
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
171
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 129

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  consolidation_level =
    hash.key?('consolidation_level') ? hash['consolidation_level'] : nil
  memo = hash.key?('memo') ? hash['memo'] : nil
  original_amount =
    hash.key?('original_amount') ? hash['original_amount'] : nil
  applied_amount =
    hash.key?('applied_amount') ? hash['applied_amount'] : nil
  transaction_time = if hash.key?('transaction_time')
                       (DateTimeHelper.from_rfc3339(hash['transaction_time']) if hash['transaction_time'])
                     end
  payment_method = hash.key?('payment_method') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:InvoiceEventPayment), hash['payment_method']
  ) : nil
  transaction_id =
    hash.key?('transaction_id') ? hash['transaction_id'] : SKIP
  parent_invoice_number =
    hash.key?('parent_invoice_number') ? hash['parent_invoice_number'] : SKIP
  remaining_prepayment_amount =
    hash.key?('remaining_prepayment_amount') ? hash['remaining_prepayment_amount'] : SKIP
  prepayment = hash.key?('prepayment') ? hash['prepayment'] : SKIP
  external = hash.key?('external') ? hash['external'] : SKIP

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

  # Create object from extracted values.
  ApplyPaymentEventData.new(consolidation_level: consolidation_level,
                            memo: memo,
                            original_amount: original_amount,
                            applied_amount: applied_amount,
                            transaction_time: transaction_time,
                            payment_method: payment_method,
                            transaction_id: transaction_id,
                            parent_invoice_number: parent_invoice_number,
                            remaining_prepayment_amount: remaining_prepayment_amount,
                            prepayment: prepayment,
                            external: external,
                            additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 67

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['consolidation_level'] = 'consolidation_level'
  @_hash['memo'] = 'memo'
  @_hash['original_amount'] = 'original_amount'
  @_hash['applied_amount'] = 'applied_amount'
  @_hash['transaction_time'] = 'transaction_time'
  @_hash['payment_method'] = 'payment_method'
  @_hash['transaction_id'] = 'transaction_id'
  @_hash['parent_invoice_number'] = 'parent_invoice_number'
  @_hash['remaining_prepayment_amount'] = 'remaining_prepayment_amount'
  @_hash['prepayment'] = 'prepayment'
  @_hash['external'] = 'external'
  @_hash
end

.nullablesObject

An array for nullable fields



95
96
97
98
99
100
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 95

def self.nullables
  %w[
    parent_invoice_number
    remaining_prepayment_amount
  ]
end

.optionalsObject

An array for optional fields



84
85
86
87
88
89
90
91
92
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 84

def self.optionals
  %w[
    transaction_id
    parent_invoice_number
    remaining_prepayment_amount
    prepayment
    external
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



179
180
181
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
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 179

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.consolidation_level,
                            ->(val) { InvoiceConsolidationLevel.validate(val) }) and
        APIHelper.valid_type?(value.memo,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.original_amount,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.applied_amount,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.transaction_time,
                              ->(val) { val.instance_of? DateTime }) and
        UnionTypeLookUp.get(:InvoiceEventPayment)
                       .validate(value.payment_method)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['consolidation_level'],
                          ->(val) { InvoiceConsolidationLevel.validate(val) }) and
      APIHelper.valid_type?(value['memo'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['original_amount'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['applied_amount'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['transaction_time'],
                            ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:InvoiceEventPayment)
                     .validate(value['payment_method'])
  )
end

Instance Method Details

#to_custom_transaction_timeObject



173
174
175
# File 'lib/advanced_billing/models/apply_payment_event_data.rb', line 173

def to_custom_transaction_time
  DateTimeHelper.to_rfc3339(transaction_time)
end