pagseguro_client 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +26 -4
- data/lib/pagseguro_client/base.rb +8 -0
- data/lib/pagseguro_client/generator.rb +13 -0
- data/lib/pagseguro_client/order.rb +3 -6
- data/lib/pagseguro_client/railtie.rb +7 -0
- data/lib/pagseguro_client/version.rb +1 -1
- data/lib/pagseguro_client.rb +1 -0
- data/spec/pagseguro_client/base_spec.rb +20 -4
- data/spec/support/config/boot.rb +3 -1
- data/spec/support/config/pagseguro.yml +1 -0
- data/spec/support/log/test.log +21 -0
- data/template/config.yml +12 -0
- data/templates/config.yml +16 -0
- metadata +6 -2
data/README.markdown
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
Este é um plugin do Ruby on Rails que permite utilizar o [PagSeguro](https://pagseguro.uol.com.br), gateway de pagamentos do [UOL](http://uol.com.br).
|
4
4
|
|
5
5
|
## Changelog
|
6
|
+
* Adicionado gerador para instalação da biblioteca em projetos Rails
|
7
|
+
* Adicionada opção para URL de retorno dinâmica
|
6
8
|
* Implementação parcial da [API de pagamentos](https://pagseguro.uol.com.br/v2/guia-de-integracao/api-de-pagamentos.html)
|
7
9
|
* Implementação parcial da [API de notificações](https://pagseguro.uol.com.br/v2/guia-de-integracao/notificacoes.html)
|
8
10
|
|
@@ -13,17 +15,22 @@ Este é um plugin do Ruby on Rails que permite utilizar o [PagSeguro](https://pa
|
|
13
15
|
Adicione a biblioteca ao arquivo Gemfile:
|
14
16
|
|
15
17
|
```ruby
|
16
|
-
gem 'pagseguro_client', git: "git://github.com/
|
18
|
+
gem 'pagseguro_client', git: "git://github.com/fknappe/pagseguro_client.git"
|
17
19
|
```
|
18
20
|
|
19
|
-
|
21
|
+
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
|
+
|
23
|
+
rails generate pagseguro_client:install
|
24
|
+
|
25
|
+
O arquivo de configuração gerado será parecido com isso:
|
20
26
|
|
21
27
|
```yaml
|
22
28
|
development: &development
|
23
29
|
ws_url: "http://localhost:4000"
|
24
30
|
ps_url: "http://localhost:4000"
|
31
|
+
return_to: "http://localhost:4000/successo"
|
25
32
|
email: matheustardivo@gmail.com
|
26
|
-
token: "
|
33
|
+
token: "tokenGeradoPeloPagseguro"
|
27
34
|
|
28
35
|
test:
|
29
36
|
<<: *development
|
@@ -31,11 +38,12 @@ test:
|
|
31
38
|
production:
|
32
39
|
ws_url: "https://ws.pagseguro.uol.com.br"
|
33
40
|
ps_url: "https://pagseguro.uol.com.br"
|
41
|
+
return_to: "http://www.sualoja.com.br/successo"
|
34
42
|
email: matheustardivo@gmail.com
|
35
43
|
token: "tokenGeradoPeloPagseguro"
|
36
44
|
```
|
37
45
|
|
38
|
-
Para realizar os
|
46
|
+
Para realizar os testes de integração da sua aplicação com o gateway, você pode usar um servidor de testes desenvolvido pelo próprio Pagseguro: [Pagseguro Server](https://github.com/carlosdelfino/PagSeguro-TestServer)
|
39
47
|
|
40
48
|
### Gerando a sua ordem de pagamento
|
41
49
|
|
@@ -60,7 +68,21 @@ Para realizar os seus testes você pode usar um servidor de testes do Pagseguro
|
|
60
68
|
|
61
69
|
Agora basta usar a url retornada para enviar o usuário para efetuar o pagamento no site do Pagseguro.
|
62
70
|
|
71
|
+
### Configurando opção para URL de retorno dinâmica
|
72
|
+
|
73
|
+
Para configurar uma URL de retorno dinâmica a sua aplicação Rails, basta adicionar ao arquivo pagseguro.yml a opção return_to com o endereço para retorno que você configurou na sua aplicação:
|
74
|
+
|
75
|
+
```yaml
|
76
|
+
production:
|
77
|
+
ws_url: "https://ws.pagseguro.uol.com.br"
|
78
|
+
ps_url: "https://pagseguro.uol.com.br"
|
79
|
+
return_to: "http://www.sualoja.com.br/sucesso"
|
80
|
+
email: matheustardivo@gmail.com
|
81
|
+
token: "tokenGeradoPeloPagseguro"
|
82
|
+
```
|
83
|
+
|
63
84
|
### Obtendo as notificações
|
85
|
+
|
64
86
|
```ruby
|
65
87
|
# No seu controller
|
66
88
|
def notificacao
|
@@ -23,6 +23,10 @@ module PagseguroClient
|
|
23
23
|
@@config[Rails.env]
|
24
24
|
end
|
25
25
|
|
26
|
+
def redirect?
|
27
|
+
config.has_key?("return_to")
|
28
|
+
end
|
29
|
+
|
26
30
|
def ws_url
|
27
31
|
config["ws_url"]
|
28
32
|
end
|
@@ -39,6 +43,10 @@ module PagseguroClient
|
|
39
43
|
config["email"]
|
40
44
|
end
|
41
45
|
|
46
|
+
def redirect_url
|
47
|
+
config["return_to"]
|
48
|
+
end
|
49
|
+
|
42
50
|
def checkout_url
|
43
51
|
"#{ws_url}/v2/checkout"
|
44
52
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "rails/generators/base"
|
2
|
+
|
3
|
+
module PagseguroClient
|
4
|
+
class InstallGenerator < ::Rails::Generators::Base
|
5
|
+
namespace "pagseguro_client:install"
|
6
|
+
|
7
|
+
source_root File.dirname(__FILE__) + "/../../templates"
|
8
|
+
|
9
|
+
def copy_configuration_file
|
10
|
+
copy_file "config.yml", "config/pagseguro.yml"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -18,12 +18,9 @@ module PagseguroClient
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def data
|
21
|
-
data = {
|
22
|
-
|
23
|
-
|
24
|
-
currency: "BRL",
|
25
|
-
reference: id
|
26
|
-
}
|
21
|
+
data = { email: PagseguroClient.email, token: PagseguroClient.token, currency: "BRL", reference: id }
|
22
|
+
data["redirectURL"] = PagseguroClient.redirect_url if PagseguroClient.redirect?
|
23
|
+
|
27
24
|
products.each_with_index do |item, index|
|
28
25
|
index += 1
|
29
26
|
data["itemId#{index}"] = item[:id]
|
data/lib/pagseguro_client.rb
CHANGED
@@ -1,11 +1,27 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Base" do
|
4
|
-
|
5
|
-
|
4
|
+
describe "checkout_url" do
|
5
|
+
it "should return the pagseguro checkout url" do
|
6
|
+
PagseguroClient.checkout_url.should == "#{PagseguroClient.ws_url}/v2/checkout"
|
7
|
+
end
|
6
8
|
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
describe "#payment_url" do
|
11
|
+
it "should return the pagseguro payment base url with the specified transaction code" do
|
12
|
+
PagseguroClient.payment_url("XPTO").should == "#{PagseguroClient.ws_url}/v2/checkout/payment.html?code=XPTO"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#notification_url" do
|
17
|
+
it "should return the pagseguro ws_url base url with specified transaction code" do
|
18
|
+
PagseguroClient.notification_url("XPTO").should == "#{PagseguroClient.ws_url}/v2/transactions/notifications/XPTO"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#redirect_url" do
|
23
|
+
it "should return the configured redirect_to URL" do
|
24
|
+
PagseguroClient.redirect_url.should == "#{PagseguroClient.redirect_url}"
|
25
|
+
end
|
10
26
|
end
|
11
27
|
end
|
data/spec/support/config/boot.rb
CHANGED
data/spec/support/log/test.log
CHANGED
@@ -0,0 +1,21 @@
|
|
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
ADDED
@@ -0,0 +1,12 @@
|
|
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
|
@@ -0,0 +1,16 @@
|
|
1
|
+
development: &development
|
2
|
+
ws_url: "http://localhost:4000"
|
3
|
+
ps_url: "http://localhost:4000"
|
4
|
+
return_to: "http://localhost:4000/successo"
|
5
|
+
email: matheustardivo@gmail.com
|
6
|
+
token: "tokenGeradoPeloPagseguro"
|
7
|
+
|
8
|
+
test:
|
9
|
+
<<: *development
|
10
|
+
|
11
|
+
production:
|
12
|
+
ws_url: "https://ws.pagseguro.uol.com.br"
|
13
|
+
ps_url: "https://pagseguro.uol.com.br"
|
14
|
+
return_to: "http://www.sualoja.com.br/successo"
|
15
|
+
email: matheustardivo@gmail.com
|
16
|
+
token: "tokenGeradoPeloPagseguro"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagseguro_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-rails
|
@@ -121,8 +121,10 @@ files:
|
|
121
121
|
- Rakefile
|
122
122
|
- lib/pagseguro_client.rb
|
123
123
|
- lib/pagseguro_client/base.rb
|
124
|
+
- lib/pagseguro_client/generator.rb
|
124
125
|
- lib/pagseguro_client/notification.rb
|
125
126
|
- lib/pagseguro_client/order.rb
|
127
|
+
- lib/pagseguro_client/railtie.rb
|
126
128
|
- lib/pagseguro_client/version.rb
|
127
129
|
- pagseguro_client.gemspec
|
128
130
|
- spec/pagseguro_client/base_spec.rb
|
@@ -137,6 +139,8 @@ files:
|
|
137
139
|
- spec/support/log/.gitkeep
|
138
140
|
- spec/support/log/test.log
|
139
141
|
- spec/support/notification.xml
|
142
|
+
- template/config.yml
|
143
|
+
- templates/config.yml
|
140
144
|
homepage: https://github.com/matheustardivo/pagseguro_client
|
141
145
|
licenses: []
|
142
146
|
post_install_message:
|