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 +4 -4
- data/lib/pagarme/object.rb +10 -61
- data/lib/pagarme/transaction_common.rb +32 -62
- data/pagarme.gemspec +1 -1
- data/test/pagarme/transfer.rb +2 -8
- data/test/test_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6e36ef4830f648c47b317abce9664ab3de2ebfa
|
4
|
+
data.tar.gz: 3374729244ff9b5e795071bd81f0e76f88c4738b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07568f8f6bd486c9263970ed0ce0c3de27af4a7ed8c590311bd34a1875db22ad307fe2020495a6f125b97406d62c65fe92633195bfc6f481efb1316d686a337b
|
7
|
+
data.tar.gz: 09f5d8c2733a232dcb1e5be374fc97ad000b62034b613112345cecc091c1c26e02f4984e05553b6d6b124cd67529ba318ea84f9d19357f96d48262f58b8a2cdb
|
data/lib/pagarme/object.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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]
|
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
|
-
|
5
|
+
class TransactionCommon < Model
|
6
6
|
|
7
|
-
|
8
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
15
|
+
def create
|
16
|
+
check_card_object
|
17
|
+
super
|
18
|
+
end
|
46
19
|
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
73
|
-
end
|
43
|
+
end
|
74
44
|
end
|
data/pagarme.gemspec
CHANGED
@@ -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.
|
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}
|
data/test/pagarme/transfer.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
data/test/test_helper.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2015-07-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|