pagarme 1.2 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmE0M2Q2YmY0ZDcyNmNkZjcyMWIzYTA2NzhhM2NmZjJlODcwOTc2NQ==
4
+ Zjc2N2JjZjZhYWZhMTViNjViNDhlNmRiOGNlZjlkODM1OWY4MzNkNw==
5
5
  data.tar.gz: !binary |-
6
- ZDM3NzQyNDQ1NjhlZmFiNGIyMzQyNWI2Y2MyZDc1NmZjNzMwMTE2MQ==
6
+ YzEzNTNmYWY3NWQyZWRkYTMzODlkNjJhZjg5MjM1M2Q2ZjEwZTI3NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Njg1OTYyY2YxOGM4Y2QwMjE5N2QxNmMxZWFiMGEwNTQ0ZDU4MDc1MTk4NGVm
10
- MWUyYjViNTE1ZDRkNDU3M2ZlMmMwMjcyNmMzNDkyMDY4YWVhNDFhZDEwNGMy
11
- N2RiOTI4MzcwYTY0MjE2NTgyMDU2ZGMxNDFkNzJhYTZmOTNlMDQ=
9
+ M2VlMDYwMTIyZDA1MDk4ODdlNTg2ZmFhZjNjM2E2NGViYjcyY2YzNjEwYjMz
10
+ ZmU2OTYxMWEzZTg3Y2FhZDQxOTk2ZGRmZTM4YmRmZjUyYzA4NTQ0ZDc4ZDdh
11
+ ZTA2M2ZiNzcxNjM2YzMzMWRhNDNhNzJiMTc4NjA5NTQ2MjE0MjM=
12
12
  data.tar.gz: !binary |-
13
- MzlhYzhlNTE3Mjc4NzcwNmNhZmFjZTFmNDcyZDNlYjNjZDExYWYxOWZlMjgx
14
- NDcxZTNiMTI1NDhiZTY1ZmZkMjhiNDMzYjkwNmFmYjVmZmNiZmQ4ZWQ1Njg5
15
- MzcyMjY2OTk2OTExYjhiYzU1YjQ0NmIxNmFlYWYwMGNjODRlOGQ=
13
+ OTI1OTg5YzgzYjFhMmRlYTkxZTIyY2NjZWZmNTQwZGE5ZjY4ZWYzNjYwYmFm
14
+ M2I5MjhlYWEzZTMyM2E3MzZjY2FmZGM1ZTVlY2UzMjM2YzhjMmVkZDQ4MzU1
15
+ ZGViNjEzN2I1YWQwMWEwYTAwZDAyMTY2ZTM1YTlkYWZjYTUzZjU=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pagarme (1.1)
4
+ pagarme (1.2)
5
5
  multi_json
6
6
  rest-client
7
7
 
@@ -27,6 +27,7 @@ module PagarMe
27
27
  def save
28
28
  request = PagarMe::Request.new(self.url, 'PUT')
29
29
  request.parameters = self.unsaved_values
30
+ puts request.parameters.inspect
30
31
  response = request.run
31
32
  update(response)
32
33
  end
@@ -31,9 +31,6 @@ module PagarMe
31
31
  })
32
32
  error = nil
33
33
 
34
- puts self.class.encode(parameters)
35
-
36
-
37
34
  begin
38
35
  response = RestClient::Request.execute({
39
36
  :method => self.method,
@@ -4,22 +4,22 @@ require File.join(File.dirname(__FILE__), '..', 'pagarme')
4
4
  module PagarMe
5
5
  class Subscription < TransactionCommon
6
6
 
7
- def to_hash
8
- {
9
- :amount => self.amount,
10
- :payment_method => self.payment_method,
11
- :installments => self.installments,
12
- :card_hash => (self.payment_method == 'credit_card' ? self.card_hash : nil),
13
- :postback_url => self.postback_url,
14
- :customer_email => self.customer_email,
15
- :customer => (self.customer) ? self.customer.to_hash : nil,
16
- :plan_id => (self.plan) ? self.plan.id : nil
17
- }
18
- end
19
7
 
20
8
  def create
21
- validation_error = self.card_hash ? nil : validate
22
- self.card_hash = generate_card_hash unless self.card_hash
9
+ if self.plan
10
+ self.plan_id = plan.id
11
+ end
12
+
13
+ self.plan = nil
14
+ super
15
+ end
16
+
17
+ def save
18
+ if self.plan
19
+ self.plan_id = plan.id
20
+ end
21
+
22
+ self.plan = nil
23
23
  super
24
24
  end
25
25
 
@@ -5,24 +5,8 @@ require File.join(File.dirname(__FILE__), '..', 'pagarme')
5
5
 
6
6
  module PagarMe
7
7
  class Transaction < TransactionCommon
8
- # server requests methods
9
-
10
- def to_hash
11
- {
12
- :amount => self.amount,
13
- :payment_method => self.payment_method,
14
- :installments => self.installments,
15
- :card_hash => (self.payment_method == 'credit_card' ? self.card_hash : nil),
16
- :postback_url => self[:postback_url],
17
- :customer => (self.customer) ? self.customer.to_hash : nil,
18
- :metadata => self.metadata
19
- }
20
- end
21
-
22
8
  def charge
23
- validation_error = self[:card_hash] ? nil : validate
24
- self.card_hash = generate_card_hash unless self[:card_hash]
25
- create
9
+ create
26
10
  end
27
11
 
28
12
  def refund
@@ -12,6 +12,21 @@ module PagarMe
12
12
  before_set_filter :amount, :format_amount
13
13
  end
14
14
 
15
+ def create
16
+ validation_error = self.card_hash ? nil : validate
17
+ self.card_hash = generate_card_hash unless self.card_hash
18
+ unset_creditcard_information
19
+ super
20
+ end
21
+
22
+ def unset_creditcard_information
23
+ self.card_number = nil
24
+ self.card_holder_name = nil
25
+ self.card_expiration_year = nil
26
+ self.card_expiration_month = nil
27
+ self.card_cvv = nil
28
+ end
29
+
15
30
  def is_valid_credit_card(card)
16
31
  s1 = s2 = 0
17
32
  card.to_s.reverse.chars.each_slice(2) do |odd, even|
@@ -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.2
7
+ spec.version = 1.3
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}
@@ -25,16 +25,47 @@ module PagarMe
25
25
  end
26
26
  end
27
27
 
28
-
29
- # should 'be able to pass metadata to subscription' do
28
+ should 'be able to change plans' do
29
+ subscription = test_subscription
30
+ plan = test_plan
31
+ plan.create
32
+
33
+ plan2 = PagarMe::Plan.new({
34
+ :name => "Plano Silver",
35
+ :days => 30,
36
+ :amount => 3000
37
+ });
38
+ plan2.create
39
+
40
+ subscription.plan = plan
41
+ subscription.create
42
+
43
+ assert subscription.plan.id == plan.id
44
+ subscription.plan = plan2
45
+ subscription.save
46
+
47
+ assert subscription.plan.id == plan2.id
48
+ end
49
+
50
+ # should 'be able to change from a plan with trial to a plan without trial' do
30
51
  # subscription = test_subscription
31
- # subscription.metadata = {:event => {:event_name => "Evento 2 ", :id => 13}}
52
+ # plan = test_plan
53
+ # plan.create
54
+
55
+ # plan2 = test_plan
56
+ # plan2.trial_days = nil
57
+
58
+ # subscription.plan = plan
32
59
  # subscription.create
33
60
 
34
- # subscription2 = PagarMe::Subscription.find_by_id(subscription.id)
35
- # assert subscription2.id == subscription.id
36
- # assert subscription2.metadata.event.event_name == 'Evento 2'
37
- # assert subscription2.metadata.event.id == 13
61
+ # assert subscription.plan_id == plan.id
62
+
63
+ # subscription.plan = plan2
64
+ # subscription.save
65
+
66
+ # assert subscription.plan_id == plan2.id
67
+ # p = PagarMe::Plan.find_by_id(subscription.plan_id)
68
+ # assert p.trial_days == nil
38
69
  # end
39
70
  end
40
71
  end
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.2'
4
+ version: '1.3'
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-01-21 00:00:00.000000000 Z
12
+ date: 2014-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler