Class: Upay::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/upay/token.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Token

Returns a new instance of Token.



53
54
55
56
57
# File 'lib/upay/token.rb', line 53

def initialize(args = {})
  args.each do |k,v|
    instance_variable_set("@#{k}", v) unless v.nil?
  end
end

Instance Method Details

#codeObject



13
# File 'lib/upay/token.rb', line 13

def code; @code end

#code=(code) ⇒ Object



14
15
16
# File 'lib/upay/token.rb', line 14

def code=(code); 
  @code = code 
end

#createObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/upay/token.rb', line 59

def create
  data = {}
  data["creditCardToken"] = self.to_hash
  response = Requestor.new.request( PAYMENTS_API_URL, "CREATE_TOKEN", data)
  self.code = response["response"]["code"]
  self.error = response["response"]["error"]

  if response["response"]["error"] == nil
    self.creditCardTokenId = response["response"]["creditCardToken"]["creditCardTokenId"]
  end

  response
end

#creditCardTokenIdObject



43
# File 'lib/upay/token.rb', line 43

def creditCardTokenId; @creditCardTokenId end

#creditCardTokenId=(creditCardTokenId) ⇒ Object



44
45
46
# File 'lib/upay/token.rb', line 44

def creditCardTokenId=(creditCardTokenId); 
  @creditCardTokenId = creditCardTokenId 
end

#destroyObject



73
74
75
76
# File 'lib/upay/token.rb', line 73

def destroy
  data = {:removeCreditCardToken => { :payerId => self.payerId, :creditCardTokenId => self.creditCardTokenId}}
  response = Requestor.new.request( PAYMENTS_API_URL, "REMOVE_TOKEN", data)
end

#errorObject



18
# File 'lib/upay/token.rb', line 18

def error; @error end

#error=(error) ⇒ Object



19
20
21
# File 'lib/upay/token.rb', line 19

def error=(error); 
  @error = error 
end

#expirationDateObject



38
# File 'lib/upay/token.rb', line 38

def expirationDate; @expirationDate end

#expirationDate=(expirationDate) ⇒ Object



39
40
41
# File 'lib/upay/token.rb', line 39

def expirationDate=(expirationDate); 
  @expirationDate = expirationDate 
end

#identificationNumberObject



23
# File 'lib/upay/token.rb', line 23

def identificationNumber; @identificationNumber end

#identificationNumber=(identificationNumber) ⇒ Object



24
25
26
# File 'lib/upay/token.rb', line 24

def identificationNumber=(identificationNumber); 
  @identificationNumber = identificationNumber 
end

#nameObject



8
# File 'lib/upay/token.rb', line 8

def name; @name end

#name=(name) ⇒ Object



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

def name=(name); 
  @name = name 
end

#numberObject



33
# File 'lib/upay/token.rb', line 33

def number; @number end

#number=(number) ⇒ Object



34
35
36
# File 'lib/upay/token.rb', line 34

def number=(number); 
  @number = number 
end

#payerIdObject



3
# File 'lib/upay/token.rb', line 3

def payerId; @payerId end

#payerId=(payerId) ⇒ Object



4
5
6
# File 'lib/upay/token.rb', line 4

def payerId=(payerId); 
  @payerId = payerId 
end

#paymentMethodObject



28
# File 'lib/upay/token.rb', line 28

def paymentMethod; @paymentMethod end

#paymentMethod=(paymentMethod) ⇒ Object



29
30
31
# File 'lib/upay/token.rb', line 29

def paymentMethod=(paymentMethod); 
  @paymentMethod = paymentMethod 
end

#showObject



78
79
80
81
# File 'lib/upay/token.rb', line 78

def show
  data = {:removeCreditCardInformation => { :payerId => self.payerId, :creditCardTokenId => self.creditCardTokenId}}
  response = Requestor.new.request( PAYMENTS_API_URL, "GET_TOKENS", data)
end

#to_hashObject



83
84
85
# File 'lib/upay/token.rb', line 83

def to_hash
  self.instance_variables.each_with_object({}) { |var,hash| hash[var.to_s.delete("@")] = self.instance_variable_get(var)}
end

#valid?Boolean

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/upay/token.rb', line 48

def valid?
  validator = TokenValidator.new
  validator.valid?(self) 
end