pagseguro_client 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,8 @@
1
1
  *.gem
2
+ *.log
3
+
2
4
  .bundle
5
+ .rbenv-gemsets
6
+
3
7
  Gemfile.lock
4
8
  pkg/*
data/README.markdown CHANGED
@@ -7,6 +7,8 @@ Este é um plugin do Ruby on Rails que permite utilizar o [PagSeguro](https://pa
7
7
  * Adicionada opção para URL de retorno dinâmica
8
8
  * Implementação parcial da [API de pagamentos](https://pagseguro.uol.com.br/v2/guia-de-integracao/api-de-pagamentos.html)
9
9
  * Implementação parcial da [API de notificações](https://pagseguro.uol.com.br/v2/guia-de-integracao/notificacoes.html)
10
+ * Implementação parcial da [API de
11
+ transações](https://pagseguro.uol.com.br/v2/guia-de-integracao/consulta-de-transacoes-por-codigo.html)
10
12
 
11
13
  ## Como usar
12
14
 
@@ -15,14 +17,14 @@ Este é um plugin do Ruby on Rails que permite utilizar o [PagSeguro](https://pa
15
17
  Adicione a biblioteca ao arquivo Gemfile:
16
18
 
17
19
  ```ruby
18
- gem 'pagseguro_client', git: "git://github.com/fknappe/pagseguro_client.git"
20
+ gem 'pagseguro_client'
19
21
  ```
20
22
 
21
23
  Depois de realizar a instalação da biblioteca, você precisará gerar o arquivo de configuração, que deve residir em config/pagseguro.yml. Para gerar o arquivo a partir de um modelo execute
22
24
 
23
25
  rails generate pagseguro_client:install
24
26
 
25
- O arquivo de configuração gerado será parecido com isso:
27
+ O arquivo de configuração gerado será parecido com isso:
26
28
 
27
29
  ```yaml
28
30
  development: &development
@@ -101,6 +103,28 @@ O objeto `notification` possui os seguintes métodos:
101
103
  * `PagseguroClient::Notification#order_id`: Código da sua ordem de pagamento
102
104
  * `PagseguroClient::Notification#status`: Status da ordem de pagamento atual
103
105
  * `PagseguroClient::Notification#payment_method`: Método utilizado para o pagamento
106
+ * `PagseguroClient::Notification#client`: Dados do comprador
107
+ * `PagseguroClient::Notification#address`: Endereço do comprador
108
+
109
+ ### Consultando Transações
110
+
111
+ ```ruby
112
+ # No seu controller
113
+ def complete
114
+
115
+ @transaction = PagseguroClient::Transaction.retrieve(params[:transaction_id_])
116
+ # Seu código para utilizar a transaction
117
+ end
118
+ ```
119
+
120
+ O objeto `transaction` possui os seguintes métodos:
121
+
122
+ * `PagseguroClient::Transaction#code`: Código da notificação
123
+ * `PagseguroClient::Transaction#order_id`: Código da sua ordem de pagamento
124
+ * `PagseguroClient::Transaction#status`: Status da ordem de pagamento atual
125
+ * `PagseguroClient::Transaction#payment_method`: Método utilizado para o pagamento
126
+ * `PagseguroClient::Transaction#client`: Dados do comprador
127
+ * `PagseguroClient::Transaction#address`: Endereço do comprador
104
128
 
105
129
  #### Métodos de pagamento
106
130
 
@@ -121,6 +145,8 @@ O objeto `notification` possui os seguintes métodos:
121
145
 
122
146
  ## Autor
123
147
  Matheus Tardivo (<http://matheustardivo.com>)
148
+ Raphael Costa (<http://raphaelcosta.net>)
149
+ André Kupkovski (<http://kupkovski.github.com>)
124
150
 
125
151
  ## Licença:
126
152
 
@@ -2,6 +2,7 @@ require "nokogiri"
2
2
  require "rest-client"
3
3
 
4
4
  require "pagseguro_client/base"
5
+ require "pagseguro_client/transaction"
5
6
  require "pagseguro_client/notification"
6
7
  require "pagseguro_client/order"
7
8
  require "pagseguro_client/railtie"
@@ -58,6 +58,10 @@ module PagseguroClient
58
58
  def notification_url(code)
59
59
  "#{ws_url}/v2/transactions/notifications/#{code}"
60
60
  end
61
+
62
+ def transaction_url(code)
63
+ "#{ws_url}/v2/transactions/#{code}"
64
+ end
61
65
 
62
66
  class MissingEnvironmentError < StandardError; end
63
67
  class MissingConfigurationError < StandardError; end
@@ -1,58 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module PagseguroClient
4
- class Notification
5
- PAYMENT_METHOD = {
6
- 1 => :credit_card,
7
- 2 => :invoice,
8
- 3 => :online_transfer,
9
- 4 => :pagseguro,
10
- 5 => :oi_paggo
11
- }
12
-
13
- STATUS = {
14
- 1 => :pending,
15
- 2 => :verifying,
16
- 3 => :approved,
17
- 4 => :available,
18
- 6 => :refunded,
19
- 7 => :canceled
20
- }
21
-
22
- attr_accessor :code, :order_id, :status, :payment_method
23
-
24
- def initialize(attributes = {})
25
- attributes.each do |name, value|
26
- send("#{name}=", value)
27
- end
28
- end
29
-
30
- def self.create_by_xml(xml)
31
- doc = Nokogiri::XML(xml)
32
- code = doc.xpath("//transaction/code").text
33
- order_id = doc.xpath("//reference").text
34
- status = doc.xpath("//status").text.to_i
35
- payment_method = doc.xpath("//paymentMethod/type").text.to_i
36
-
37
- notification = Notification.new(
38
- code: code,
39
- order_id: order_id,
40
- status: STATUS[status],
41
- payment_method: PAYMENT_METHOD[payment_method]
42
- )
43
- end
44
-
45
- def self.retrieve(code)
46
- response = RestClient.get(PagseguroClient.notification_url(code),
47
- {
48
- params: {
49
- email: PagseguroClient.email,
50
- token: PagseguroClient.token
51
- }
52
- }
53
- )
54
-
55
- create_by_xml(response.body)
4
+ class Notification < Transaction
5
+ def self.url(code)
6
+ PagseguroClient.notification_url(code)
56
7
  end
57
8
  end
58
- end
9
+ end
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+ module PagseguroClient
3
+ class Transaction
4
+ PAYMENT_METHOD = {
5
+ 1 => :credit_card,
6
+ 2 => :invoice,
7
+ 3 => :online_transfer,
8
+ 4 => :pagseguro,
9
+ 5 => :oi_paggo
10
+ }
11
+
12
+ STATUS = {
13
+ 1 => :pending,
14
+ 2 => :verifying,
15
+ 3 => :approved,
16
+ 4 => :available,
17
+ 6 => :refunded,
18
+ 7 => :canceled
19
+ }
20
+
21
+ attr_accessor :code, :order_id, :status, :payment_method, :last_event_date, :sender, :address
22
+
23
+ def initialize(attributes = {})
24
+ attributes.each do |name, value|
25
+ send("#{name}=", value)
26
+ end
27
+ end
28
+
29
+ def self.create_by_xml(xml)
30
+ doc = Nokogiri::XML(xml, nil , 'UTF-8')
31
+ code = doc.xpath("//transaction/code").text
32
+ order_id = doc.xpath("//reference").text
33
+ status = doc.xpath("//status").text.to_i
34
+ payment_method = doc.xpath("//paymentMethod/type").text.to_i
35
+ last_event_date = doc.xpath("//transaction/lastEventDate").text
36
+ email = doc.xpath("//transaction/sender/email").text
37
+ name = doc.xpath("//transaction/sender/name").text
38
+ phone = {
39
+ area_code: doc.xpath("//transaction/sender/phone/areaCode").text,
40
+ number: doc.xpath("//transaction/sender/phone/number").text
41
+ }
42
+ address = {
43
+ country: doc.xpath("//transaction/shipping/address/country").text,
44
+ state: doc.xpath("//transaction/shipping/address/state").text,
45
+ city: doc.xpath("//transaction/shipping/address/city").text,
46
+ postal_code: doc.xpath("//transaction/shipping/address/postalCode").text,
47
+ district: doc.xpath("//transaction/shipping/address/district").text,
48
+ street: doc.xpath("//transaction/shipping/address/street").text,
49
+ number: doc.xpath("//transaction/shipping/address/number").text,
50
+ complement: doc.xpath("//transaction/shipping/address/complement").text
51
+ }
52
+
53
+ transaction = Transaction.new(
54
+ code: code,
55
+ order_id: order_id,
56
+ status: STATUS[status],
57
+ payment_method: PAYMENT_METHOD[payment_method],
58
+ sender: {
59
+ name: name,
60
+ email: email,
61
+ phone: phone
62
+ },
63
+ address: address,
64
+ last_event_date: last_event_date
65
+ )
66
+ end
67
+
68
+ def self.url(code)
69
+ PagseguroClient.transaction_url(code)
70
+ end
71
+
72
+ def self.retrieve(code)
73
+ response = RestClient.get(url(code),
74
+ {
75
+ params: {
76
+ email: PagseguroClient.email,
77
+ token: PagseguroClient.token
78
+ }
79
+ }
80
+ )
81
+
82
+ create_by_xml(response.body)
83
+ end
84
+ end
85
+ end
@@ -1,3 +1,3 @@
1
1
  module PagseguroClient
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -5,8 +5,8 @@ require "pagseguro_client/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "pagseguro_client"
7
7
  s.version = PagseguroClient::VERSION
8
- s.authors = ["Matheus Tardivo"]
9
- s.email = ["matheustardivo@gmail.com"]
8
+ s.authors = ["Matheus Tardivo", "Raphael Costa", "André Kupkovski"]
9
+ s.email = ["matheustardivo@gmail.com", "raphael@raphaelcosta.net", "kupkovski@gmail.com"]
10
10
  s.homepage = "https://github.com/matheustardivo/pagseguro_client"
11
11
  s.summary = %q{The library to access the new services from Pagseguro (v2)}
12
12
  s.description = s.summary
@@ -1,17 +1,21 @@
1
+ #encoding: utf-8
1
2
  require "spec_helper"
2
3
 
3
4
  module PagseguroClient
4
- describe Notification do
5
- context "parse notification xml" do
5
+ describe Transaction do
6
+ context "parse transaction xml" do
6
7
  subject {
7
- Notification.create_by_xml(File.read("spec/support/notification.xml"))
8
+ Transaction.create_by_xml(File.read("spec/support/notification.xml"))
8
9
  }
9
-
10
- # attr_accessor :code, :order_id, :status, :payment_method
10
+
11
11
  its(:code) { should == "9E884542-81B3-4419-9A75-BCC6FB495EF1" }
12
12
  its(:order_id) { should == "REF1234" }
13
13
  its(:status) { should == :approved }
14
14
  its(:payment_method) { should == :credit_card }
15
+ its(:last_event_date) { should == '2011-02-15T17:39:14.000-03:00' }
16
+ its(:sender) {
17
+ should == { name: 'José Comprador', email: 'comprador@uol.com.br', phone: { area_code: '11', number: '56273440'}}
18
+ }
15
19
  end
16
20
  end
17
21
  end
@@ -5,6 +5,7 @@
5
5
  <reference>REF1234</reference>
6
6
  <type>1</type>
7
7
  <status>3</status>
8
+ <lastEventDate>2011-02-15T17:39:14.000-03:00</lastEventDate>
8
9
  <paymentMethod>
9
10
  <type>1</type>
10
11
  <code>101</code>
metadata CHANGED
@@ -1,15 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagseguro_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matheus Tardivo
9
+ - Raphael Costa
10
+ - André Kupkovski
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
12
- date: 2012-08-26 00:00:00.000000000 Z
14
+ date: 2013-01-08 00:00:00.000000000 Z
13
15
  dependencies:
14
16
  - !ruby/object:Gem::Dependency
15
17
  name: rspec-rails
@@ -110,6 +112,8 @@ dependencies:
110
112
  description: The library to access the new services from Pagseguro (v2)
111
113
  email:
112
114
  - matheustardivo@gmail.com
115
+ - raphael@raphaelcosta.net
116
+ - kupkovski@gmail.com
113
117
  executables: []
114
118
  extensions: []
115
119
  extra_rdoc_files: []
@@ -125,6 +129,7 @@ files:
125
129
  - lib/pagseguro_client/notification.rb
126
130
  - lib/pagseguro_client/order.rb
127
131
  - lib/pagseguro_client/railtie.rb
132
+ - lib/pagseguro_client/transaction.rb
128
133
  - lib/pagseguro_client/version.rb
129
134
  - pagseguro_client.gemspec
130
135
  - spec/pagseguro_client/base_spec.rb
@@ -137,9 +142,7 @@ files:
137
142
  - spec/support/config/pagseguro.yml
138
143
  - spec/support/config/routes.rb
139
144
  - spec/support/log/.gitkeep
140
- - spec/support/log/test.log
141
145
  - spec/support/notification.xml
142
- - template/config.yml
143
146
  - templates/config.yml
144
147
  homepage: https://github.com/matheustardivo/pagseguro_client
145
148
  licenses: []
@@ -176,5 +179,4 @@ test_files:
176
179
  - spec/support/config/pagseguro.yml
177
180
  - spec/support/config/routes.rb
178
181
  - spec/support/log/.gitkeep
179
- - spec/support/log/test.log
180
182
  - spec/support/notification.xml
@@ -1,21 +0,0 @@
1
- Connecting to database specified by database.yml
2
- Connecting to database specified by database.yml
3
- Connecting to database specified by database.yml
4
- Connecting to database specified by database.yml
5
- Connecting to database specified by database.yml
6
- Connecting to database specified by database.yml
7
- Connecting to database specified by database.yml
8
- Connecting to database specified by database.yml
9
- Connecting to database specified by database.yml
10
- Connecting to database specified by database.yml
11
- Connecting to database specified by database.yml
12
- Connecting to database specified by database.yml
13
- Connecting to database specified by database.yml
14
- Connecting to database specified by database.yml
15
- Connecting to database specified by database.yml
16
- Connecting to database specified by database.yml
17
- Connecting to database specified by database.yml
18
- Connecting to database specified by database.yml
19
- Connecting to database specified by database.yml
20
- Connecting to database specified by database.yml
21
- Connecting to database specified by database.yml
data/template/config.yml DELETED
@@ -1,12 +0,0 @@
1
- development: &development
2
- ws_url: "http://localhost:4000"
3
- ps_url: "http://localhost:4000"
4
- return_to: "http://localhost:4000/success"
5
- email: your-email@pagseguro.com
6
- token: "your-pagseguro-key-here"
7
-
8
- test:
9
- <<: *development
10
-
11
- production:
12
- <<: *development