Class: Upay::CreditCard

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

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ CreditCard

Returns a new instance of CreditCard.



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

def initialize(args = {})
  reload(args)
end

Instance Method Details

#addressObject



58
# File 'lib/upay/credit_card.rb', line 58

def address; @address end

#address=(address) ⇒ Object



59
60
61
# File 'lib/upay/credit_card.rb', line 59

def address=(address);
  @address = address
end

#allObject



110
111
112
113
# File 'lib/upay/credit_card.rb', line 110

def all
  url = "rest/v4.3/creditCards/"
  Requestor.new.get(url, {:creditCardId => ""})
end

#create(customerID) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/upay/credit_card.rb', line 73

def create(customerID)
  url = "rest/v4.3/customers/#{customerID}/creditCards"
  data = {
    :type => self.type, 
    :expMonth => self.expMonth, 
    :expYear => self.expYear, 
    :name => self.name,
    :number => self.number
  }
  request = Requestor.new.post(url, data)
  self.creditCardId = request["token"]
  self.token = request["token"]
end

#creditCardIdObject



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

def creditCardId; @creditCardId end

#creditCardId=(creditCardId) ⇒ Object



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

def creditCardId=(creditCardId);
  @creditCardId = creditCardId
end

#delete(customerID, creditCardId) ⇒ Object



115
116
117
118
# File 'lib/upay/credit_card.rb', line 115

def delete(customerID, creditCardId)
  url = "rest/v4.3/customers/#{customerID}/creditCards/#{creditCardId}"
  Requestor.new.delete(url, {})
end

#documentObject



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

def document; @document end

#document=(document) ⇒ Object



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

def document=(document);
  @document = document
end

#expMonthObject



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

def expMonth; @expMonth end

#expMonth=(expMonth) ⇒ Object



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

def expMonth=(expMonth);
  @expMonth = expMonth
end

#expYearObject



48
# File 'lib/upay/credit_card.rb', line 48

def expYear; @expYear end

#expYear=(expYear) ⇒ Object



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

def expYear=(expYear);
  @expYear = expYear
end

#nameObject



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

def name; @name end

#name=(name) ⇒ Object



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

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

#numberObject



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

def number; @number end

#number=(number) ⇒ Object



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

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

#reload(args = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/upay/credit_card.rb', line 8

def reload(args = {})
  args.each do |k,v|
    case k
    when "token"
      instance_variable_set("@#{k}", v)
      instance_variable_set("@creditCardId", v)
    when "creditCardId"
      instance_variable_set("@#{k}", v)
      instance_variable_set("@token", v)
    else
      instance_variable_set("@#{k}", v)
    end
  end
end

#showObject



99
100
101
102
103
104
105
106
107
108
# File 'lib/upay/credit_card.rb', line 99

def show
  begin
    unless self.creditCardId.nil?
      url = "rest/v4.3/creditCards/#{self.creditCardId}"
      Requestor.new.get(url, {:creditCardId => self.creditCardId})
    else
      raise "creditCardId cannot be blank"
    end
  end
end

#tokenObject



63
# File 'lib/upay/credit_card.rb', line 63

def token; @token end

#token=(token) ⇒ Object



64
65
66
# File 'lib/upay/credit_card.rb', line 64

def token=(token);
  @token = token
end

#typeObject



53
# File 'lib/upay/credit_card.rb', line 53

def type; @type end

#type=(type) ⇒ Object



54
55
56
# File 'lib/upay/credit_card.rb', line 54

def type=(type);
  @type = type
end

#updateObject



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/upay/credit_card.rb', line 87

def update
  url = "rest/v4.3/creditCards/#{self.creditCardId}"
  data = {
    :type => self.type, 
    :expMonth => self.expMonth, 
    :expYear => self.expYear, 
    :name => self.name,
    :number => self.number
  }
  Requestor.new.put(url, data)
end

#valid?Boolean

Returns:

  • (Boolean)


68
69
70
71
# File 'lib/upay/credit_card.rb', line 68

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