Class: Spreedly::PaymentMethod

Inherits:
Model
  • Object
show all
Includes:
ErrorsParser
Defined in:
lib/spreedly/payment_methods/payment_method.rb

Direct Known Subclasses

BankAccount, CreditCard, Paypal, Sprel

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ErrorsParser

#errors_from

Methods included from Fields

#field_hash, included, #initialize_fields

Constructor Details

#initialize(xml_doc) ⇒ PaymentMethod

Returns a new instance of PaymentMethod.



12
13
14
15
# File 'lib/spreedly/payment_methods/payment_method.rb', line 12

def initialize(xml_doc)
  super
  @errors = errors_from(xml_doc)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



10
11
12
# File 'lib/spreedly/payment_methods/payment_method.rb', line 10

def errors
  @errors
end

Class Method Details

.new_from(xml_doc) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/spreedly/payment_methods/payment_method.rb', line 17

def self.new_from(xml_doc)
  case xml_doc.at_xpath('.//payment_method_type').inner_text
  when 'credit_card'
    return CreditCard.new(xml_doc)
  when 'paypal'
    return Paypal.new(xml_doc)
  when 'sprel'
    return Sprel.new(xml_doc)
  when 'bank_account'
    return BankAccount.new(xml_doc)
  when 'third_party_token'
    return ThirdPartyToken.new(xml_doc)
  end
end

.new_list_from(xml_doc) ⇒ Object



32
33
34
35
36
37
# File 'lib/spreedly/payment_methods/payment_method.rb', line 32

def self.new_list_from(xml_doc)
  payment_methods = xml_doc.xpath('.//payment_methods/payment_method')
  payment_methods.map do |each|
    self.new_from(each)
  end
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/spreedly/payment_methods/payment_method.rb', line 39

def valid?
  @errors.empty?
end