pagarme 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 44500eb2b6f419659836569ebed302b4ad53fdc2
4
- data.tar.gz: 9fd134b080deae4a281459288df9b4775f584bc5
5
- SHA512:
6
- metadata.gz: d9b3164829fee223d759a326148a7384408dc9755cfe652f0564c7c3947a8b90b3e0bb722490216d019440c5494429d9325fb501383582a1e39f7c49414fcd87
7
- data.tar.gz: b64dccc95beff0f54b9f0c708ad76fb74a78fca7df5b397b74faed2d3045735ec45178fbe9c1bdb6b79ff408fb3cafebaafcd21ea0117fa89966c9c3f00159c8
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDJiYjA5NzFmNzE0Mzc0MzQ1NzRkOTYzMDdmMzY1YmEyZDU2NzY1ZQ==
5
+ data.tar.gz: !binary |-
6
+ NzUzNjJmNWY1MGQwMDQ0ZGQ0ZTJiYzUxNTJkNzBhMzVhMjQyNjJhMw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NDI2NmJmOWMyNWY4YzdmNTgyNWFjZjRhMDQ1NGVlODA0N2I1ZjEyNTBhYzA4
10
+ NzEzNjJjNDZmODdlM2U4NmFlZjZhOTRhMDUxZjM4NmM2YzdjNzE2NTVlY2Ux
11
+ ZTMzZjNhNTdkYTY0N2IwMzI2NjlkZDQ1NDIyNjg2YjJmMGYyMmI=
12
+ data.tar.gz: !binary |-
13
+ MDY5YzAwMWNiNTY3MGIyOGY1YTc0ZTUzMzdjNmVlYWE0NDI0NDNmMTZkZjUx
14
+ YzRlMzg5ZDBmMmJiMTI0Y2U5ZWMzYWI3YjRhNGEzNmEyZjc4NzZiYjBmZDcz
15
+ NTY5ZDhhODRkM2JlMDM3ZjNjYWFlZDdmNWNlYWU5ZDJkOTA4NTE=
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
data/README.md CHANGED
@@ -1 +1,15 @@
1
- Pagar.me's API in Ruby.
1
+ ## pagarme-ruby
2
+
3
+ Pagar.me Ruby library
4
+
5
+ ## Documentation
6
+
7
+ * [API Guide](https://pagar.me/docs/apis/ruby/)
8
+
9
+ ## Code Status
10
+
11
+ [![Build Status](https://travis-ci.org/pagarme/pagarme-ruby.png)](https://travis-ci.org/pagarme/pagarme-ruby)
12
+
13
+ ## License
14
+
15
+ Pagar.me Ruby library is released under the [MIT License](http://www.opensource.org/licenses/MIT).
@@ -1,3 +1,4 @@
1
+ require 'digest/sha1'
1
2
  require 'pagarme/pagarme_object'
2
3
  require 'pagarme/util'
3
4
  require 'pagarme/model'
@@ -31,14 +32,10 @@ module PagarMe
31
32
  end
32
33
 
33
34
  def self.full_api_url(relative_path)
34
- "#{@@api_endpoint}/#{@@api_version}#{relative_path}"
35
+ "#{@@api_endpoint}/#{@@api_version}#{relative_path}"
35
36
  end
36
37
 
37
- def self.live
38
- @@live
39
- end
40
-
41
- def self.live=(live)
42
- @@live = live
38
+ def self.validate_fingerprint(id, fingerprint)
39
+ Digest::SHA1.hexdigest(id.to_s + "#" + @@api_key) == fingerprint
43
40
  end
44
41
  end
@@ -6,12 +6,11 @@ require File.join(File.dirname(__FILE__), '.', 'errors')
6
6
 
7
7
  module PagarMe
8
8
  class Request
9
- attr_accessor :path, :method, :parameters, :headers, :live
9
+ attr_accessor :path, :method, :parameters, :headers
10
10
 
11
- def initialize(path, method, live=PagarMe.live)
11
+ def initialize(path, method)
12
12
  self.path = path
13
13
  self.method = method
14
- self.live = live
15
14
  self.parameters = {}
16
15
  self.headers = {}
17
16
  end
@@ -25,13 +24,16 @@ module PagarMe
25
24
  raise PagarMeError.new("You need to configure a API key before performing requests.")
26
25
  end
27
26
 
28
- self.headers = self.live ? { 'X-Live' => '1' } : {}
27
+ self.headers = {}
29
28
 
30
29
  parameters = self.parameters.merge({
31
30
  :api_key => PagarMe.api_key
32
31
  })
33
32
  error = nil
34
33
 
34
+ puts self.class.encode(parameters)
35
+
36
+
35
37
  begin
36
38
  response = RestClient::Request.execute({
37
39
  :method => self.method,
@@ -14,7 +14,8 @@ module PagarMe
14
14
  :installments => self.installments,
15
15
  :card_hash => (self.payment_method == 'credit_card' ? self.card_hash : nil),
16
16
  :postback_url => self[:postback_url],
17
- :customer => (self.customer) ? self.customer.to_hash : nil
17
+ :customer => (self.customer) ? self.customer.to_hash : nil,
18
+ :metadata => self.metadata
18
19
  }
19
20
  end
20
21
 
@@ -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.0
7
+ spec.version = 1.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/pagarme.rb CHANGED
@@ -1,3 +1,12 @@
1
1
  require File.join(File.dirname(__FILE__), '.', 'lib/pagarme')
2
+ transaction = PagarMe::Transaction.new
3
+ transaction.card_number = "4901720080344448"
4
+ transaction.card_holder_name = "Jose da Silva"
5
+ transaction.card_expiration_month = "13" # o mês 13 é maior do que 12 (dezembro) -> parâmetro inválido!
6
+ transaction.card_expiration_year = "15"
7
+ transaction.card_cvv = "314"
8
+ transaction.amount = 1000
9
+
10
+ transaction.charge
2
11
 
3
12
 
@@ -25,5 +25,16 @@ module PagarMe
25
25
  end
26
26
  end
27
27
 
28
+
29
+ # should 'be able to pass metadata to subscription' do
30
+ # subscription = test_subscription
31
+ # subscription.metadata = {:event => {:event_name => "Evento 2 ", :id => 13}}
32
+ # subscription.create
33
+
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
38
+ # end
28
39
  end
29
40
  end
@@ -4,128 +4,139 @@ require_relative '../test_helper'
4
4
  module PagarMe
5
5
  class TransactionTest < Test::Unit::TestCase
6
6
  should 'be able to charge' do
7
- transaction = test_transaction
8
- assert transaction.status == 'local'
9
- transaction.charge
10
- assert transaction.status == 'paid'
11
- test_transaction_response(transaction)
7
+ transaction = test_transaction
8
+ assert transaction.status == 'local'
9
+ transaction.charge
10
+ assert transaction.status == 'paid'
11
+ test_transaction_response(transaction)
12
12
  end
13
13
 
14
14
  should 'be able to refund' do
15
- transaction = test_transaction
16
- transaction.charge
17
- test_transaction_response(transaction)
18
- transaction.refund
19
- assert transaction.status == 'refunded'
15
+ transaction = test_transaction
16
+ transaction.charge
17
+ test_transaction_response(transaction)
18
+ transaction.refund
19
+ assert transaction.status == 'refunded'
20
20
  end
21
21
 
22
22
  should 'be able to create transaciton with boleto' do
23
- transaction = PagarMe::Transaction.new({
24
- :payment_method => "boleto",
23
+ transaction = PagarMe::Transaction.new({
24
+ :payment_method => "boleto",
25
25
  :amount => "1000"
26
- })
27
- transaction.charge
26
+ })
27
+ transaction.charge
28
28
 
29
- assert transaction.payment_method == 'boleto'
30
- assert transaction.status == 'waiting_payment'
31
- assert transaction.amount.to_s == '1000'
29
+ assert transaction.payment_method == 'boleto'
30
+ assert transaction.status == 'waiting_payment'
31
+ assert transaction.amount.to_s == '1000'
32
+ end
33
+
34
+ should 'be able to send metadata' do
35
+ transaction = test_transaction
36
+ transaction.metadata = {event: {:name => "Evento foda", :id => 335}}
37
+ transaction.charge
38
+ assert transaction.metadata
39
+
40
+ transaction2 = PagarMe::Transaction.find_by_id(transaction.id)
41
+ assert transaction2.metadata.event.id.to_i == 335
42
+ assert transaction2.metadata.event.name == "Evento foda"
32
43
  end
33
44
 
34
45
  should 'be able to find a transaction' do
35
- transaction = test_transaction
36
- transaction.charge
37
- test_transaction_response(transaction)
46
+ transaction = test_transaction
47
+ transaction.charge
48
+ test_transaction_response(transaction)
38
49
 
39
- transaction_2 = PagarMe::Transaction.find_by_id(transaction.id)
40
- assert transaction_2.id == transaction.id
50
+ transaction_2 = PagarMe::Transaction.find_by_id(transaction.id)
51
+ assert transaction_2.id == transaction.id
41
52
  end
42
53
 
43
54
  should 'be able to create transaction with customer' do
44
- transaction = test_transaction_with_customer
45
- transaction.charge
46
- test_transaction_response(transaction)
47
- assert transaction.customer.class == Customer
48
- test_customer_response(transaction.customer)
55
+ transaction = test_transaction_with_customer
56
+ transaction.charge
57
+ test_transaction_response(transaction)
58
+ assert transaction.customer.class == Customer
59
+ test_customer_response(transaction.customer)
49
60
  end
50
61
 
51
62
  should 'be able to refund transaction with customer' do
52
- transaction = test_transaction_with_customer
53
- transaction.charge
54
- test_transaction_response(transaction)
55
- assert transaction.customer.class == Customer
56
- test_customer_response(transaction.customer)
57
- transaction.refund
58
-
59
- assert transaction.status == 'refunded'
63
+ transaction = test_transaction_with_customer
64
+ transaction.charge
65
+ test_transaction_response(transaction)
66
+ assert transaction.customer.class == Customer
67
+ test_customer_response(transaction.customer)
68
+ transaction.refund
69
+
70
+ assert transaction.status == 'refunded'
60
71
  end
61
72
 
62
73
  should 'should allow transactions with R$ amount' do
63
- transaction = test_transaction
64
- transaction.amount = 'R$ 10.00'
65
- transaction.charge
66
- assert transaction.amount == 1000
74
+ transaction = test_transaction
75
+ transaction.amount = 'R$ 10.00'
76
+ transaction.charge
77
+ assert transaction.amount == 1000
67
78
  end
68
79
 
69
80
  should 'validate invalid transaction' do
70
81
 
71
- #Test invalid card_number
72
- exception = assert_raises PagarMeError do
73
- transaction = PagarMe::Transaction.new({
74
- :amount => "1000",
75
- :card_number => '123456',
76
- :card_holder_name => "Jose da Silva",
77
- })
78
- transaction.charge
79
- end
80
- assert exception.errors.first.parameter_name == 'card_number'
81
-
82
- #Test missing card_holder_name
83
- exception = assert_raises PagarMeError do
84
- transaction = PagarMe::Transaction.new({
85
- :card_number => '4111111111111111',
86
- :amount => "1000",
87
- })
88
- transaction.charge
89
- end
90
- assert exception.errors.first.parameter_name == 'card_holder_name'
91
-
92
- #Test invalid expiracy month
93
- exception = assert_raises PagarMeError do
94
- transaction = PagarMe::Transaction.new({
95
- :card_number => '4111111111111111',
96
- :card_holder_name => "Jose da Silva",
97
- :amount => "1000",
98
- :card_expiracy_month => 15
99
- })
100
- transaction.charge
101
- end
102
- assert exception.errors.first.parameter_name == 'card_expiration_date'
103
-
104
- #Test invalid expiracy year
105
- exception = assert_raises PagarMeError do
106
- transaction = PagarMe::Transaction.new({
107
- :card_number => '4111111111111111',
108
- :card_holder_name => "Jose da Silva",
109
- :amount => "1000",
110
- :card_expiration_month => 12,
111
- :card_expiration_year => -1,
112
- })
113
- transaction.charge
114
- end
115
- assert exception.errors.first.parameter_name == 'card_expiration_date'
116
-
117
- #Test invalid expiracy year
118
- exception = assert_raises PagarMeError do
119
- transaction = PagarMe::Transaction.new({
120
- :card_number => '4111111111111111',
121
- :card_holder_name => "Jose da Silva",
122
- :amount => "1000",
123
- :card_expiration_month => 12,
124
- :card_expiration_year => 16,
125
- })
126
- transaction.charge
127
- end
128
- assert exception.errors.first.parameter_name == 'card_cvv'
82
+ #Test invalid card_number
83
+ exception = assert_raises PagarMeError do
84
+ transaction = PagarMe::Transaction.new({
85
+ :amount => "1000",
86
+ :card_number => '123456',
87
+ :card_holder_name => "Jose da Silva",
88
+ })
89
+ transaction.charge
90
+ end
91
+ assert exception.errors.first.parameter_name == 'card_number'
92
+
93
+ #Test missing card_holder_name
94
+ exception = assert_raises PagarMeError do
95
+ transaction = PagarMe::Transaction.new({
96
+ :card_number => '4111111111111111',
97
+ :amount => "1000",
98
+ })
99
+ transaction.charge
100
+ end
101
+ assert exception.errors.first.parameter_name == 'card_holder_name'
102
+
103
+ #Test invalid expiracy month
104
+ exception = assert_raises PagarMeError do
105
+ transaction = PagarMe::Transaction.new({
106
+ :card_number => '4111111111111111',
107
+ :card_holder_name => "Jose da Silva",
108
+ :amount => "1000",
109
+ :card_expiracy_month => 15
110
+ })
111
+ transaction.charge
112
+ end
113
+ assert exception.errors.first.parameter_name == 'card_expiration_date'
114
+
115
+ #Test invalid expiracy year
116
+ exception = assert_raises PagarMeError do
117
+ transaction = PagarMe::Transaction.new({
118
+ :card_number => '4111111111111111',
119
+ :card_holder_name => "Jose da Silva",
120
+ :amount => "1000",
121
+ :card_expiration_month => 12,
122
+ :card_expiration_year => -1,
123
+ })
124
+ transaction.charge
125
+ end
126
+ assert exception.errors.first.parameter_name == 'card_expiration_date'
127
+
128
+ #Test invalid expiracy year
129
+ exception = assert_raises PagarMeError do
130
+ transaction = PagarMe::Transaction.new({
131
+ :card_number => '4111111111111111',
132
+ :card_holder_name => "Jose da Silva",
133
+ :amount => "1000",
134
+ :card_expiration_month => 12,
135
+ :card_expiration_year => 16,
136
+ })
137
+ transaction.charge
138
+ end
139
+ assert exception.errors.first.parameter_name == 'card_cvv'
140
+ end
129
141
  end
130
142
  end
131
- end
@@ -51,58 +51,58 @@ end
51
51
 
52
52
  def test_transaction_with_customer(params = {})
53
53
  return PagarMe::Transaction.new({
54
- :amount => 1000,
55
- :card_number => '4901720080344448',
56
- :card_holder_name => "Jose da Silva",
57
- :card_expiration_month => 11,
58
- :card_expiration_year => "13",
59
- :card_cvv => 356,
60
- :customer => {
61
- :name => "Jose da Silva",
62
- :document_number => "36433809847",
63
- :email => "henrique@pagar.me",
64
- :address => {
65
- :street => 'Av. Brigadeiro Faria Lima',
66
- :neighborhood => 'Itaim bibi',
67
- :zipcode => '01452000',
68
- :street_number => 2941,
69
- },
70
- :phone => {
71
- :ddd => 12,
72
- :number => '981433533',
73
- },
74
- :sex => 'M',
75
- :born_at => '1970-10-11'
76
- }
54
+ :amount => 1000,
55
+ :card_number => '4901720080344448',
56
+ :card_holder_name => "Jose da Silva",
57
+ :card_expiration_month => 11,
58
+ :card_expiration_year => "14",
59
+ :card_cvv => 356,
60
+ :customer => {
61
+ :name => "Jose da Silva",
62
+ :document_number => "36433809847",
63
+ :email => "henrique@pagar.me",
64
+ :address => {
65
+ :street => 'Av. Brigadeiro Faria Lima',
66
+ :neighborhood => 'Itaim bibi',
67
+ :zipcode => '01452000',
68
+ :street_number => 2941,
69
+ },
70
+ :phone => {
71
+ :ddd => 12,
72
+ :number => '981433533',
73
+ },
74
+ :sex => 'M',
75
+ :born_at => '1970-10-11'
76
+ }
77
77
  }.merge(params))
78
78
  end
79
79
 
80
80
  def test_subscription_with_customer(params = {})
81
81
  return PagarMe::Subscription.new({
82
- :amount => 1000,
83
- :card_number => '4901720080344448',
84
- :card_holder_name => "Jose da silva",
85
- :card_expiration_month => 11,
86
- :card_expiration_year => 13,
87
- :card_cvv => 356,
88
- :customer_email => 'teste@teste.com',
89
- :customer => {
90
- :name => "Jose da Silva",
91
- :document_number => "36433809847",
92
- :email => "henrique@pagar.me",
93
- :address => {
94
- :street => 'Av. Brigadeiro Faria Lima',
95
- :neighborhood => 'Itaim bibi',
96
- :zipcode => '01452000',
97
- :street_number => 2941,
98
- } ,
99
- :phone => {
100
- :ddd => 12,
101
- :number => '981433533',
102
- } ,
103
- :sex => 'M',
104
- :born_at => '1970-10-11'
105
- }
82
+ :amount => 1000,
83
+ :card_number => '4901720080344448',
84
+ :card_holder_name => "Jose da silva",
85
+ :card_expiration_month => 11,
86
+ :card_expiration_year => 14,
87
+ :card_cvv => 356,
88
+ :customer_email => 'teste@teste.com',
89
+ :customer => {
90
+ :name => "Jose da Silva",
91
+ :document_number => "36433809847",
92
+ :email => "henrique@pagar.me",
93
+ :address => {
94
+ :street => 'Av. Brigadeiro Faria Lima',
95
+ :neighborhood => 'Itaim bibi',
96
+ :zipcode => '01452000',
97
+ :street_number => 2941,
98
+ } ,
99
+ :phone => {
100
+ :ddd => 12,
101
+ :number => '981444444',
102
+ } ,
103
+ :sex => 'M',
104
+ :born_at => '1970-10-11'
105
+ }
106
106
  }.merge(params))
107
107
  end
108
108
 
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.0'
4
+ version: '1.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: 2013-11-22 00:00:00.000000000 Z
12
+ date: 2014-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -29,14 +29,14 @@ dependencies:
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ! '>='
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ! '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
@@ -57,42 +57,42 @@ dependencies:
57
57
  name: test-unit
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - '>='
60
+ - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rest-client
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - '>='
74
+ - - ! '>='
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - '>='
81
+ - - ! '>='
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: multi_json
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - '>='
88
+ - - ! '>='
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - '>='
95
+ - - ! '>='
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  description: Pagar.me's ruby gem
@@ -104,6 +104,7 @@ extensions: []
104
104
  extra_rdoc_files: []
105
105
  files:
106
106
  - .gitignore
107
+ - .travis.yml
107
108
  - Gemfile
108
109
  - Gemfile.lock
109
110
  - README.md
@@ -137,17 +138,17 @@ require_paths:
137
138
  - lib
138
139
  required_ruby_version: !ruby/object:Gem::Requirement
139
140
  requirements:
140
- - - '>='
141
+ - - ! '>='
141
142
  - !ruby/object:Gem::Version
142
143
  version: '0'
143
144
  required_rubygems_version: !ruby/object:Gem::Requirement
144
145
  requirements:
145
- - - '>='
146
+ - - ! '>='
146
147
  - !ruby/object:Gem::Version
147
148
  version: '0'
148
149
  requirements: []
149
150
  rubyforge_project:
150
- rubygems_version: 2.0.3
151
+ rubygems_version: 2.0.7
151
152
  signing_key:
152
153
  specification_version: 4
153
154
  summary: Allows integration with Pagar.me