pagarme 1.9.5 → 1.9.6

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: 8e0e00753c649eaab912a05e42c3761d7a64e714
4
- data.tar.gz: 04c7e8a5d52b5d22bf0fa6a02031771984e2f6f8
3
+ metadata.gz: 5cd543f3e64ed61f404f6278c9bca1b74b216601
4
+ data.tar.gz: 7e7bbab3994f861d6dea16952aac5ad1701ac442
5
5
  SHA512:
6
- metadata.gz: 7135b0716c80d52da03da0f219f075de72b4f334098549051675e0826d6f9047217fcbee1bf4bae6c54aedfc295edeb53d9b41c77f2f0a3789476a0cac29eaa7
7
- data.tar.gz: b9188fa4cd9b690754bffe96abf9e66daf8a99f3975e32ca4a277732959e57e85bfd32afadb74ba57729e5c4a99998d1ab7ba2d6eda60221eb5e9c66138a3e19
6
+ metadata.gz: d08104c2256b4007d2638607e8505b7dd780cf60a29bd3a821b92b3ae41574efbaf387674f4c537941f6226ab5d6be77160e4d07c47b4b0d1ec418b9fcdb239a
7
+ data.tar.gz: 4148ea215f0ac10197485d45b5a2a326ddae91f33cd0486dd6af4eac0edac96ad4bede64bc654a55804ee2d37cdf4b7568733f9d9b675ac865519422110e8bf5
data/Rakefile CHANGED
@@ -2,11 +2,18 @@ require "bundler/gem_tasks"
2
2
 
3
3
  task :default => [:all]
4
4
 
5
- task :test do
5
+ task :test, :test_file do |t, args|
6
6
  ret = true
7
- Dir["test/**/*.rb"].each do |f|
7
+ test_file = args[:test_file]
8
+
9
+ if args[:test_file]
10
+ f = "test/pagarme/#{args[:test_file]}.rb"
11
+ ret = ret && ruby(f, '')
12
+ else
13
+ Dir["test/**/*.rb"].each do |f|
8
14
  ret = ret && ruby(f, '')
9
15
  end
16
+ end
10
17
  end
11
18
 
12
19
  task :all do
@@ -8,12 +8,12 @@ module PagarMe
8
8
  #init @attributes - which are the attributes in the object
9
9
  @attributes = {}
10
10
 
11
- # filters - which are the filters that will be called when appropriate , such as before_set
12
- @filters = {}
13
-
14
11
  # Values that were changed in the object but weren't saved
15
12
  @unsaved_values = Set.new
16
13
 
14
+ # Methods that already existed
15
+ @@existing_methods = Array.new
16
+
17
17
  #Update object
18
18
  update(response)
19
19
  end
@@ -90,7 +90,9 @@ module PagarMe
90
90
  metaclass.instance_eval do
91
91
  keys.each do |key|
92
92
  key_sym = :"#{key}="
93
- remove_method(key) if method_defined?(key)
93
+ if !@@existing_methods.include?(key)
94
+ remove_method(key) if method_defined?(key)
95
+ end
94
96
  remove_method(key_sym) if method_defined?(key_sym)
95
97
  end
96
98
  end
@@ -100,29 +102,19 @@ module PagarMe
100
102
  metaclass.instance_eval do
101
103
  keys.each do |key|
102
104
  key_set = "#{key}="
103
- define_method(key) { @attributes[key] }
105
+ if method_defined?(key)
106
+ @@existing_methods.push(key)
107
+ else
108
+ define_method(key) { @attributes[key] }
109
+ end
104
110
  define_method(key_set) do |value|
105
- if @filters[key]
106
- @filters[key].each do |meth|
107
- if methods.include?(meth)
108
- @attributes[key] = method(meth).call(value)
111
+ @attributes[key] = value
109
112
  @unsaved_values.add(key)
110
- end
111
- end
112
- else
113
- @attributes[key] = value
114
- @unsaved_values.add(key)
115
- end
116
113
  end
117
114
  end
118
115
  end
119
116
  end
120
117
 
121
- def before_set_filter(attribute, method)
122
- @filters[attribute.to_sym] = Array.new unless @filters[attribute.to_sym]
123
- @filters[attribute.to_sym] << method.to_sym
124
- end
125
-
126
118
  def method_missing(name, *args)
127
119
  if name.to_s.end_with?('=')
128
120
  attr = name.to_s[0...-1].to_sym
@@ -2,55 +2,5 @@
2
2
 
3
3
  module PagarMe
4
4
  class Plan < Model
5
- def initialize(response = {})
6
- super
7
- before_set_filter :amount, :format_amount
8
- end
9
-
10
- def create
11
- validate
12
- super
13
- end
14
-
15
- def save
16
- raise PagarMeError.new('O plano precisa estar criado para poder ser atualizado!', 'internal_error') unless self.id
17
- super
18
- end
19
-
20
- def format_amount(amount)
21
- if amount.kind_of?(String)
22
- value = amount.gsub(/\./, "")
23
- value = value.strip
24
- value = value.match(/\d+/)[0]
25
- amount = value
26
- end
27
- amount
28
- end
29
-
30
- private
31
-
32
- def validate
33
- error = PagarMeError.new
34
- if !self[:amount] || self.amount.to_i <= 0
35
- error.errors << PagarMeError.new('Valor invalido', 'amount')
36
- end
37
- if !self[:days] || self.days.to_i <= 0
38
- error.errors << PagarMeError.new('Numero de dias invalido', 'days')
39
- end
40
- if !self[:name] || self.name.length <= 0
41
- error.errors << PagarMeError.new('Nome invalido', 'name')
42
- end
43
- if self[:trial_days] && self.trial_days.to_i < 0
44
- error.errors << PagarMeError.new('Dias de teste invalido', 'trial_days')
45
- end
46
-
47
- if(error.errors.any?)
48
- error.message = error.errors.map {|e| e.message}
49
- error.message = error.message.join(',')
50
- raise error
51
- else
52
- nil
53
- end
54
- end
55
5
  end
56
6
  end
@@ -30,6 +30,7 @@ module PagarMe
30
30
  :api_key => PagarMe.api_key
31
31
  })
32
32
  error = nil
33
+ # puts parameters.inspect
33
34
 
34
35
  begin
35
36
  response = RestClient::Request.execute({
@@ -16,8 +16,16 @@ module PagarMe
16
16
  create
17
17
  end
18
18
 
19
- def refund
19
+ def capture(params={})
20
+ request = PagarMe::Request.new(self.url + '/capture', 'POST')
21
+ request.parameters.merge!(params)
22
+ response = request.run
23
+ update(response)
24
+ end
25
+
26
+ def refund(params={})
20
27
  request = PagarMe::Request.new(self.url + '/refund', 'POST')
28
+ request.parameters.merge!(params)
21
29
  response = request.run
22
30
  update(response)
23
31
  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 = "1.9.5"
7
+ spec.version = "1.9.6"
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}
@@ -29,13 +29,6 @@ module PagarMe
29
29
  end
30
30
  end
31
31
 
32
- should 'be able to create with unformatted amount' do
33
- plan = test_plan
34
- plan.amount = 'R$ 10.00'
35
- plan.create
36
- assert plan.amount == 1000
37
- end
38
-
39
32
  should 'validate plan' do
40
33
  exception = assert_raises PagarMeError do
41
34
  plan = Plan.new({
@@ -61,6 +61,31 @@ module PagarMe
61
61
  assert transaction_2.id == transaction.id
62
62
  end
63
63
 
64
+ should 'accept parameters on the refund' do
65
+ transaction = PagarMe::Transaction.new({
66
+ :payment_method => 'boleto',
67
+ :amount => '1000'
68
+ })
69
+
70
+ transaction2 = PagarMe::Transaction.new({
71
+ :payment_method => 'boleto',
72
+ :amount => '1000',
73
+ :postback_url => 'http://url.com/postback'
74
+ })
75
+
76
+ transaction.charge
77
+ transaction2.charge
78
+
79
+ transaction.status = 'paid'
80
+ transaction.save
81
+
82
+ transaction2.status = 'paid'
83
+ transaction2.save
84
+
85
+ transaction.refund({:bank_account => {:bank_code => '399', :agencia => '1234', :conta => '1234567', :conta_dv => '1', :legal_name => 'Jose da silva', :document_number => '68782915423'}})
86
+ assert transaction.status == 'pending_refund'
87
+ end
88
+
64
89
  should 'be able to create transaction with customer' do
65
90
  transaction = test_transaction_with_customer
66
91
  transaction.charge
@@ -82,6 +107,15 @@ module PagarMe
82
107
  assert transaction.status == 'refunded'
83
108
  end
84
109
 
110
+ should 'be able to capture a transaction and pass an amount' do
111
+ transaction = test_transaction({:capture => false})
112
+ transaction.charge
113
+ assert transaction.status == 'authorized'
114
+ transaction.capture({:amount => 1000})
115
+ assert transaction.status == 'paid'
116
+ assert transaction.amount == 1000
117
+ end
118
+
85
119
  should 'validate invalid transaction' do
86
120
 
87
121
  #Test invalid card_number
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: 1.9.5
4
+ version: 1.9.6
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: 2014-09-19 00:00:00.000000000 Z
12
+ date: 2014-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler