Class: AdvancedBilling::PaymentMethodCreditCard

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

Overview

PaymentMethodCreditCard Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(card_brand:, masked_card_number:, type:, card_expiration: SKIP, last_four: SKIP, additional_properties: {}) ⇒ PaymentMethodCreditCard

Returns a new instance of PaymentMethodCreditCard.



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

def initialize(card_brand:, masked_card_number:, type:,
               card_expiration: SKIP, last_four: SKIP,
               additional_properties: {})
  @card_brand = card_brand
  @card_expiration = card_expiration unless card_expiration == SKIP
  @last_four = last_four unless last_four == SKIP
  @masked_card_number = masked_card_number
  @type = type

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

Instance Attribute Details

#card_brandString

TODO: Write general description for this method

Returns:

  • (String)


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

def card_brand
  @card_brand
end

#card_expirationString

TODO: Write general description for this method

Returns:

  • (String)


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

def card_expiration
  @card_expiration
end

#last_fourString

TODO: Write general description for this method

Returns:

  • (String)


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

def last_four
  @last_four
end

#masked_card_numberString

TODO: Write general description for this method

Returns:

  • (String)


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

def masked_card_number
  @masked_card_number
end

#typeInvoiceEventPaymentMethod

TODO: Write general description for this method



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

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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/payment_method_credit_card.rb', line 74

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  card_brand = hash.key?('card_brand') ? hash['card_brand'] : nil
  masked_card_number =
    hash.key?('masked_card_number') ? hash['masked_card_number'] : nil
  type = hash.key?('type') ? hash['type'] : nil
  card_expiration =
    hash.key?('card_expiration') ? hash['card_expiration'] : SKIP
  last_four = hash.key?('last_four') ? hash['last_four'] : SKIP

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

  # Create object from extracted values.
  PaymentMethodCreditCard.new(card_brand: card_brand,
                              masked_card_number: masked_card_number,
                              type: type,
                              card_expiration: card_expiration,
                              last_four: last_four,
                              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/payment_method_credit_card.rb', line 33

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['card_brand'] = 'card_brand'
  @_hash['card_expiration'] = 'card_expiration'
  @_hash['last_four'] = 'last_four'
  @_hash['masked_card_number'] = 'masked_card_number'
  @_hash['type'] = 'type'
  @_hash
end

.nullablesObject

An array for nullable fields



52
53
54
55
56
# File 'lib/advanced_billing/models/payment_method_credit_card.rb', line 52

def self.nullables
  %w[
    last_four
  ]
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    card_expiration
    last_four
  ]
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
# File 'lib/advanced_billing/models/payment_method_credit_card.rb', line 100

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.card_brand,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.masked_card_number,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.type,
                              ->(val) { InvoiceEventPaymentMethod.validate(val) })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['card_brand'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['masked_card_number'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['type'],
                            ->(val) { InvoiceEventPaymentMethod.validate(val) })
  )
end