Class: AdvancedBilling::FailedPaymentEventData

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

Overview

Example schema for an ‘failed_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(amount_in_cents:, applied_amount:, payment_method:, transaction_id:, memo: SKIP, additional_properties: {}) ⇒ FailedPaymentEventData

Returns a new instance of FailedPaymentEventData.



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/advanced_billing/models/failed_payment_event_data.rb', line 57

def initialize(amount_in_cents:, applied_amount:, payment_method:,
               transaction_id:, memo: SKIP, additional_properties: {})
  @amount_in_cents = amount_in_cents
  @applied_amount = applied_amount
  @memo = memo unless memo == SKIP
  @payment_method = payment_method
  @transaction_id = transaction_id

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

Instance Attribute Details

#amount_in_centsInteger

The monetary value of the payment, expressed in cents.

Returns:

  • (Integer)


14
15
16
# File 'lib/advanced_billing/models/failed_payment_event_data.rb', line 14

def amount_in_cents
  @amount_in_cents
end

#applied_amountInteger

The monetary value of the payment, expressed in dollars.

Returns:

  • (Integer)


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

def applied_amount
  @applied_amount
end

#memoString

The memo passed when the payment was created.

Returns:

  • (String)


22
23
24
# File 'lib/advanced_billing/models/failed_payment_event_data.rb', line 22

def memo
  @memo
end

#payment_methodInvoicePaymentMethodType

The memo passed when the payment was created.



26
27
28
# File 'lib/advanced_billing/models/failed_payment_event_data.rb', line 26

def payment_method
  @payment_method
end

#transaction_idInteger

The transaction ID of the failed payment.

Returns:

  • (Integer)


30
31
32
# File 'lib/advanced_billing/models/failed_payment_event_data.rb', line 30

def transaction_id
  @transaction_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/advanced_billing/models/failed_payment_event_data.rb', line 72

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount_in_cents =
    hash.key?('amount_in_cents') ? hash['amount_in_cents'] : nil
  applied_amount =
    hash.key?('applied_amount') ? hash['applied_amount'] : nil
  payment_method =
    hash.key?('payment_method') ? hash['payment_method'] : nil
  transaction_id =
    hash.key?('transaction_id') ? hash['transaction_id'] : nil
  memo = hash.key?('memo') ? hash['memo'] : SKIP

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

  # Create object from extracted values.
  FailedPaymentEventData.new(amount_in_cents: amount_in_cents,
                             applied_amount: applied_amount,
                             payment_method: payment_method,
                             transaction_id: transaction_id,
                             memo: memo,
                             additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



33
34
35
36
37
38
39
40
41
# File 'lib/advanced_billing/models/failed_payment_event_data.rb', line 33

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['amount_in_cents'] = 'amount_in_cents'
  @_hash['applied_amount'] = 'applied_amount'
  @_hash['memo'] = 'memo'
  @_hash['payment_method'] = 'payment_method'
  @_hash['transaction_id'] = 'transaction_id'
  @_hash
end

.nullablesObject

An array for nullable fields



51
52
53
54
55
# File 'lib/advanced_billing/models/failed_payment_event_data.rb', line 51

def self.nullables
  %w[
    memo
  ]
end

.optionalsObject

An array for optional fields



44
45
46
47
48
# File 'lib/advanced_billing/models/failed_payment_event_data.rb', line 44

def self.optionals
  %w[
    memo
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



100
101
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/failed_payment_event_data.rb', line 100

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.amount_in_cents,
                            ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.applied_amount,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.payment_method,
                              ->(val) { InvoicePaymentMethodType.validate(val) }) and
        APIHelper.valid_type?(value.transaction_id,
                              ->(val) { val.instance_of? Integer })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['amount_in_cents'],
                          ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['applied_amount'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['payment_method'],
                            ->(val) { InvoicePaymentMethodType.validate(val) }) and
      APIHelper.valid_type?(value['transaction_id'],
                            ->(val) { val.instance_of? Integer })
  )
end