pagarme 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7b1442209801ec8fcb0668b9214acf904843def
4
- data.tar.gz: 1261b41b3c65366a9c04042786fba0df24d521d2
3
+ metadata.gz: f6e36ef4830f648c47b317abce9664ab3de2ebfa
4
+ data.tar.gz: 3374729244ff9b5e795071bd81f0e76f88c4738b
5
5
  SHA512:
6
- metadata.gz: 0f9274f464816545b0df3bb3f3660fab2d4010a9cbe65806ec77eae730bf0b4a6bfb2f26205265b858e6612b8bfe56f1638ef644c343c4a97e69d384f6eeb1ba
7
- data.tar.gz: b7962c5cd4a27f760822c3abf63c3df8c8d779ebfb061545ae0c1c2b9d0c3464a952f27a019d78012ac2158ee9b3c9783790d609c87f19a64a473ab2a4c25527
6
+ metadata.gz: 07568f8f6bd486c9263970ed0ce0c3de27af4a7ed8c590311bd34a1875db22ad307fe2020495a6f125b97406d62c65fe92633195bfc6f481efb1316d686a337b
7
+ data.tar.gz: 09f5d8c2733a232dcb1e5be374fc97ad000b62034b613112345cecc091c1c26e02f4984e05553b6d6b124cd67529ba318ea84f9d19357f96d48262f58b8a2cdb
@@ -22,20 +22,9 @@ module PagarMe
22
22
  end
23
23
 
24
24
  def update(attributes)
25
- removed = Set.new(@attributes.keys - attributes.keys)
26
- added = Set.new(attributes.keys - @attributes.keys)
27
-
28
- instance_eval do
29
- remove_attribute(removed)
30
- add_attribute(added)
31
- end
32
-
33
- removed.each do |key|
34
- @attributes.delete(key)
35
- @unsaved_values.delete(key)
36
- end
37
-
38
25
  attributes.each do |key, value|
26
+ key = key.to_s
27
+
39
28
  @attributes[key] = Util.convert_to_pagarme_object(value)
40
29
  @unsaved_values.delete(key)
41
30
  end
@@ -76,58 +65,18 @@ module PagarMe
76
65
 
77
66
  protected
78
67
 
79
- def metaclass
80
- class << self; self; end
81
- end
82
-
83
- def remove_attribute(keys)
84
- metaclass.instance_eval do
85
- keys.each do |key|
86
- key_sym = :"#{key}="
87
-
88
- if !@@existing_methods.include?(key)
89
- remove_method(key) if method_defined?(key)
90
- end
91
-
92
- remove_method(key_sym) if method_defined?(key_sym)
93
- end
94
- end
95
- end
96
-
97
- def add_attribute(keys)
98
- metaclass.instance_eval do
99
- keys.each do |key|
100
- key_set = "#{key}="
101
-
102
- if method_defined?(key)
103
- @@existing_methods.push(key)
104
- else
105
- define_method(key) { @attributes[key] }
106
- end
107
-
108
- define_method(key_set) do |value|
109
- @attributes[key] = value
110
- @unsaved_values.add(key)
111
- end
112
- end
113
- end
114
- end
115
-
116
68
  def method_missing(name, *args)
117
- if name.to_s.end_with?('=')
118
- attr = name.to_s[0...-1].to_sym
119
- add_attribute([attr])
120
-
121
- begin
122
- m = method(name)
123
- rescue NameError
124
- raise NoMethodError.new("O atributo #{name} nao e permitido.")
125
- end
69
+ name = name.to_s
126
70
 
127
- m.call *args
71
+ if name.end_with?('=')
72
+ attribute_name = name[0...-1]
73
+
74
+ @attributes[attribute_name] = args[0]
75
+ @unsaved_values.add(attribute_name)
128
76
  else
129
- @attributes[name] if @attributes.has_key?(name)
77
+ @attributes[name] || nil
130
78
  end
131
79
  end
132
80
  end
133
81
  end
82
+
@@ -2,73 +2,43 @@
2
2
  require File.join(File.dirname(__FILE__), '..', 'pagarme')
3
3
 
4
4
  module PagarMe
5
- class TransactionCommon < Model
5
+ class TransactionCommon < Model
6
6
 
7
- def initialize(response = {})
8
- super(response)
9
- self.payment_method = 'credit_card' unless self.payment_method
10
- self.installments = 1 unless self.installments
11
- self.status = 'local' unless self.status
12
- end
13
-
14
- def create
15
- check_card_object
16
- clear_card_data
17
- super
18
- end
19
-
20
- def save
21
- check_card_object
22
- clear_card_data
23
- super
24
- end
25
-
26
- def card_data_parameters
27
- {
28
- :card_number => self.card_number,
29
- :card_holder_name => self.card_holder_name,
30
- :card_expiration_date => "#{self.card_expiration_month}#{self.card_expiration_year}",
31
- :card_cvv => self.card_cvv
32
- }
33
- end
7
+ def initialize(response = {})
8
+ super(response)
34
9
 
35
- def generate_card_hash
36
- request = PagarMe::Request.new("/transactions/card_hash_key", 'GET')
37
- response = request.run
38
-
39
- public_key = OpenSSL::PKey::RSA.new(response['public_key'])
40
- ret = "#{response['id']}_#{Base64.strict_encode64(public_key.public_encrypt(card_data_parameters.to_params))}"
41
- end
10
+ self.payment_method ||= 'credit_card'
11
+ self.installments ||= 1
12
+ self.status ||= 'local'
13
+ end
42
14
 
43
- def should_generate_card_hash
44
- true
45
- end
15
+ def create
16
+ check_card_object
17
+ super
18
+ end
46
19
 
47
- private
48
- def check_card_object
49
- if self.card
50
- if self.card.id
51
- self.card_id = self.card.id
52
- else
53
- self.card_number = self.card.card_number
54
- self.card_holder_name = self.card.card_holder_name
55
- self.card_expiration_year = self.card.card_expiration_year
56
- self.card_expiration_month = self.card.card_expiration_month
57
- self.card_cvv = self.card.card_cvv
58
- end
59
- self.card = nil
20
+ def save
21
+ check_card_object
22
+ super
60
23
  end
61
- end
62
24
 
63
- def clear_card_data
64
- if self.should_generate_card_hash
65
- self.card_hash = generate_card_hash unless self.card_hash || self.card_id
66
- self.card_number = nil
67
- self.card_holder_name = nil
68
- self.card_expiration_year = nil
69
- self.card_expiration_month = nil
70
- self.card_cvv = nil
25
+ private
26
+
27
+ def check_card_object
28
+ if self.card
29
+ if self.card.id
30
+ self.card_id = self.card.id
31
+ else
32
+ self.card_number = self.card.card_number
33
+ self.card_holder_name = self.card.card_holder_name
34
+ self.card_expiration_year = self.card.card_expiration_year
35
+ self.card_expiration_month = self.card.card_expiration_month
36
+ self.card_cvv = self.card.card_cvv
37
+ end
38
+ self.card = nil
39
+ end
40
+
41
+ self.card_expiration_date ||= "#{self.card_expiration_month}#{self.card_expiration_year}"
71
42
  end
72
- end
73
- end
43
+ end
74
44
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "pagarme"
7
- spec.version = "2.0.0"
7
+ spec.version = "2.0.1"
8
8
  spec.authors = ["Pedro Franceschi", "Henrique Dubugras"]
9
9
  spec.email = ["pedrohfranceschi@gmail.com", "henrique@pagar.me"]
10
10
  spec.description = %q{Pagar.me's ruby gem}
@@ -4,22 +4,17 @@ require_relative '../test_helper'
4
4
  module PagarMe
5
5
  class TransferTest < Test::Unit::TestCase
6
6
  should 'be able to create a transfer' do
7
- bank_account = test_bank_account
8
- bank_account.create
9
- transfer = test_transfer(bank_account_id: bank_account.id)
7
+ transfer = test_transfer
10
8
  transfer.create
11
9
 
12
10
  assert transfer.id != nil
13
11
  assert transfer.fee != nil
14
12
  assert transfer.object == "transfer"
15
13
  assert %w(doc credito_em_conta ted).include?(transfer.type)
16
- assert transfer.bank_account.id.to_i == bank_account.id.to_i
17
14
  end
18
15
 
19
16
  should 'be able to find with id' do
20
- bank_account = test_bank_account
21
- bank_account.create
22
- transfer_r = test_transfer(bank_account_id: bank_account.id)
17
+ transfer_r = test_transfer
23
18
  transfer_r.create
24
19
 
25
20
  transfer = PagarMe::Transfer.find_by_id transfer_r.id
@@ -28,7 +23,6 @@ module PagarMe
28
23
  assert transfer.fee != nil
29
24
  assert transfer.object == "transfer"
30
25
  assert %w(doc credito_em_conta ted).include?(transfer.type)
31
- assert transfer.bank_account.id.to_i == bank_account.id.to_i
32
26
  end
33
27
  end
34
28
  end
@@ -61,7 +61,7 @@ def test_bank_account(params = {})
61
61
  :conta => '23398',
62
62
  :conta_dv => '9',
63
63
  :legal_name => 'foo bar loem',
64
- :document_number => '111.111.111-11'
64
+ :document_number => '00000000000000'
65
65
  }.merge(params))
66
66
  end
67
67
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagarme
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Franceschi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-15 00:00:00.000000000 Z
12
+ date: 2015-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler