Class: Zoop::Token

Inherits:
Model show all
Defined in:
lib/zoop/resources/token.rb

Constant Summary

Constants inherited from ZoopObject

ZoopObject::RESOURCES

Instance Attribute Summary

Attributes inherited from ZoopObject

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

class_name, create, find_by_id, #save, underscored_class_name, #update, #url

Methods inherited from ZoopObject

#==, #[]=, convert, #empty?, #initialize, #respond_to?, #to_hash, #to_s, #unsaved_attributes

Constructor Details

This class inherits a constructor from Zoop::ZoopObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Zoop::ZoopObject

Class Method Details

.url(*params) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/zoop/resources/token.rb', line 24

def url(*params)
  case params.first
  when TrueClass then '/cards/tokens'
  when FalseClass then '/bank_accounts/tokens'
  else super(*params)
  end
end

Instance Method Details

#associate(customer_id) ⇒ Object

Raises:



13
14
15
16
# File 'lib/zoop/resources/token.rb', line 13

def associate(customer_id)
  raise RequestError.new('Invalid Token ID') unless id.present?
  payment_method.class.associate(customer: customer_id.to_s, token: id.to_s)
end

#createObject



4
5
6
7
# File 'lib/zoop/resources/token.rb', line 4

def create
  @custom_url = self.class.url(self.card_number.present?)
  super
end

#destroyObject

Raises:

  • (NotImplementedError)


9
10
11
# File 'lib/zoop/resources/token.rb', line 9

def destroy
  raise NotImplementedError
end

#payment_methodObject



18
19
20
# File 'lib/zoop/resources/token.rb', line 18

def payment_method
  self.card || self.
end