Class: Moip::BillingInfo
- Inherits:
-
Model
- Object
- Model
- Moip::BillingInfo
show all
- Defined in:
- lib/moip/models/billing_info.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Model
build, #set_parameters, #validate_response
Instance Attribute Details
#expiration_month ⇒ Object
Returns the value of attribute expiration_month.
3
4
5
|
# File 'lib/moip/models/billing_info.rb', line 3
def expiration_month
@expiration_month
end
|
#expiration_year ⇒ Object
Returns the value of attribute expiration_year.
3
4
5
|
# File 'lib/moip/models/billing_info.rb', line 3
def expiration_year
@expiration_year
end
|
#holder_name ⇒ Object
Returns the value of attribute holder_name.
3
4
5
|
# File 'lib/moip/models/billing_info.rb', line 3
def holder_name
@holder_name
end
|
#number ⇒ Object
Returns the value of attribute number.
3
4
5
|
# File 'lib/moip/models/billing_info.rb', line 3
def number
@number
end
|
Instance Method Details
#attributes ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/moip/models/billing_info.rb', line 62
def attributes
{
"holder_name" => holder_name,
"number" => number,
"expiration_month" => expiration_month,
"expiration_year" => expiration_year
}
end
|
#build_update ⇒ Object
71
72
73
|
# File 'lib/moip/models/billing_info.rb', line 71
def build_update
{ :credit_card => self.serializable_hash }
end
|
#patterns ⇒ Object
pattens validates kind of cards where is invalid in some cases like: E.g.: 4444 5555 4444 6666, 1111 8888 4444 5555, 5555 6666 9999 7777 has 10000 combinations
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/moip/models/billing_info.rb', line 44
def patterns
@@patterns ||= []
if @@patterns.size == 0
for i in 0..9
for j in 0..9
for k in 0..9
for l in 0..9
@@patterns << Regexp.new("[#{i}]{4}[#{j}]{4}[#{k}]{4}[#{l}]{4}")
end
end
end
end
end
@@patterns
end
|
#to_hash ⇒ Object
80
81
82
|
# File 'lib/moip/models/billing_info.rb', line 80
def to_hash
{ :credit_card => self.serializable_hash }
end
|
#to_json ⇒ Object
75
76
77
78
|
# File 'lib/moip/models/billing_info.rb', line 75
def to_json
hash = { :credit_card => self.serializable_hash }
hash.to_json
end
|
#valida_numero_cartao ⇒ Object
34
35
36
37
38
39
|
# File 'lib/moip/models/billing_info.rb', line 34
def valida_numero_cartao
patterns.each do |pattern|
self.errors.add :number, I18n.t("moip.errors.invalid_card_number") and return if @number.to_s.match pattern
false
end
end
|
26
27
28
29
30
31
32
|
# File 'lib/moip/models/billing_info.rb', line 26
def validates_format_of_expiration_month
if self.expiration_month.to_s.match /[0-9]{2}/
true
else
self.errors.add :expiration_month, I18n.t("moip.errors.invalid_expiration_month")
end
end
|
18
19
20
21
22
23
24
|
# File 'lib/moip/models/billing_info.rb', line 18
def validates_format_of_expiration_year
if self.expiration_year.to_s.match /[0-9]{2}/
true
else
self.errors.add :expiration_year, I18n.t("moip.errors.invalid_expiration_year")
end
end
|
10
11
12
13
14
15
16
|
# File 'lib/moip/models/billing_info.rb', line 10
def validates_format_of_number
if self.number.to_s.match /[0-9]{16}/
true
else
self.errors.add :number, I18n.t("moip.errors.invalid_card_number")
end
end
|