pag_seguro 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -43,7 +43,29 @@ O método checkout_payment_url envia as informações de `payment` ao PagSeguro
43
43
 
44
44
  Além dos items presentes no exemplo acima, é possível configurar `payment.sender` (com informações do usuário que está efetuando a compra), `payment.shipping` ( com as informações de endereço ), entre outras opções (para mais exemplos, olhe o arquivo spec/integration/checkout_spec.rb). Em especial, o attributo `payment.id` deve ser utilizado para referenciar um pagamento único no seu sistema.
45
45
 
46
- Com exceção do atributo response (que é utilizado para armazenar a resposta enviada pelo PagSeguro), todos os outros atributos podem ser inicialidos em formato hash na inicialização do `PagSeguro::Payment`:
46
+ Segue um exemplo mais completo do uso da api de pagamentos:
47
+
48
+ payment = PagSeguro::Payment.new(EMAIL, TOKEN)
49
+
50
+ payment.items = [
51
+ PagSeguro::Item.new(id: 25, description: "A Bic Pen", amount: "1.50", quantity: "4", shipping_cost: "1.00", weight: 10),
52
+ PagSeguro::Item.new(id: 17, description: "A pipe", amount: "3.00", quantity: "89")
53
+ ]
54
+
55
+ payment.sender = PagSeguro::Sender.new(name: "Stefano Diem Benatti", email: "stefano@heavenstudio.com.br", phone_ddd: "11", phone_number: "93430994")
56
+ payment.shipping = PagSeguro::Shipping.new(
57
+ type: PagSeguro::Shipping::SEDEX,
58
+ state: "SP",
59
+ city: "São Paulo", postal_code: "05363000",
60
+ district: "Jd. PoliPoli",
61
+ street: "Av. Otacilio Tomanik",
62
+ number: "775",
63
+ complement: "apto. 92")
64
+
65
+ redirect_to_url = payment.checkout_payment_url
66
+
67
+
68
+ Com exceção do atributo response (que é utilizado para armazenar a resposta enviada pelo PagSeguro), todos os outros atributos podem ser inicializados em formato hash na inicialização do `PagSeguro::Payment`:
47
69
 
48
70
  payment = PagSeguro::Payment.new(EMAIL, TOKEN, id: 2, items: [ PagSeguro::Item.new(id: 17, description: "A pipe", amount: "3.00", quantity: "89") ], extra_amount: '1.00' )
49
71
 
@@ -51,10 +73,10 @@ Com exceção do atributo response (que é utilizado para armazenar a resposta e
51
73
 
52
74
  As notificações de alteração no status da compra no PagSeguro serão enviadas para a URL que tiver configurado na Notificação de transações (vide Instalação). Obs.: Até o momento o PagSeguro não permite configurar uma url dinâmica para envio das notificação ( e apenas permite uma url por conta ), então provavelemente será necessário que crie uma conta diferente no PagSeguro para cada sistema que desenvolver.
53
75
 
54
- O código da notificação é enviado pelo PagSeguro através do parâmentro `notificationCode` em uma requisição do tipo POST ( lembre-se de adicionar uma rota post respectiva ). Segue um exemplo de uso da notificação em uma aplicação rails:
76
+ O código da notificação é enviado pelo PagSeguro através do parâmentro `notificationCode` em uma requisição do tipo POST. Segue um exemplo de uso da notificação em uma aplicação rails (este exemplo supõe a existência de um `resources :notifications` em suas rotas, e um modelo `Invoice` responsável pelos pagamentos):
55
77
 
56
- class PagSeguroNotificationController < ApplicationController
57
- def parse_notification
78
+ class NotificationsController < ApplicationController
79
+ def create
58
80
  EMAIL = "seu_email_cadastrado@nopagseguro.com.br"
59
81
  TOKEN = "SEU_TOKEN_GERADO_NO_PAG_SEGURO"
60
82
  NOTIFICATION_CODE = params(:notificationCode)
@@ -95,4 +117,4 @@ Permitir realizar [consultas de transações](https://pagseguro.uol.com.br/v2/gu
95
117
 
96
118
  ## Sobre
97
119
 
98
- Desenvolvida por [Stefano Diem Benatti](mailto:stefano.diem@gmail.com)
120
+ Desenvolvida por [Stefano Diem Benatti](mailto:stefano@heavenstudio.com.br)
@@ -14,7 +14,7 @@ module PagSeguro
14
14
  @token = token unless token.nil?
15
15
  @id = options[:id]
16
16
  @sender = options[:sender] || Sender.new
17
- @shipping = options[:shipping] || Shipping.new
17
+ @shipping = options[:shipping]
18
18
  @items = options[:items] || []
19
19
  @extra_amount = options[:extra_amount]
20
20
  @redirect_url = options[:redirect_url]
@@ -1,3 +1,3 @@
1
1
  module PagSeguro
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -100,9 +100,19 @@ describe PagSeguro::Payment do
100
100
  @xml = Nokogiri::XML(@payment.checkout_xml)
101
101
  end
102
102
 
103
- it "should have shipping type" do
104
- @xml_without_shipping_info.css("checkout shipping type").first.content.to_i.should == PagSeguro::Shipping::UNIDENTIFIED
105
- @xml.css("checkout shipping type").first.content.to_i.should == 2
103
+ it "should not have any shipping info unless shipping is provided" do
104
+ @xml_without_shipping_info.css("checkout shipping").should be_empty
105
+ @xml.css("checkout shipping").should_not be_empty
106
+ end
107
+
108
+ it "should have a default shipping type of UNINDENTIFIED" do
109
+ @payment.shipping = PagSeguro::Shipping.new
110
+ xml_with_empty_shipping = Nokogiri::XML(@payment.checkout_xml)
111
+ xml_with_empty_shipping.css("checkout shipping type").first.content.to_i.should == PagSeguro::Shipping::UNIDENTIFIED
112
+ end
113
+
114
+ it "should allow to set a different shipping type" do
115
+ @xml.css("checkout shipping type").first.content.to_i.should == PagSeguro::Shipping::SEDEX
106
116
  end
107
117
 
108
118
  it "should have state" do
@@ -115,7 +125,7 @@ describe PagSeguro::Payment do
115
125
  @xml.css("checkout shipping address city").first.content.should == "São Paulo"
116
126
  end
117
127
 
118
- it "should have posta code" do
128
+ it "should have postal code" do
119
129
  @xml_without_shipping_info.css("checkout shipping address postalCode").should be_empty
120
130
  @xml.css("checkout shipping address postalCode").first.content.should == "05363000"
121
131
  end
@@ -10,7 +10,15 @@ def create_valid_payment
10
10
  PagSeguro::Item.new(id: 17, description: "A pipe", amount: "3.00", quantity: "89")
11
11
  ]
12
12
  payment.sender = PagSeguro::Sender.new(name: "Stefano Diem Benatti", email: "stefano@heavenstudio.com.br", phone_ddd: "11", phone_number: "93430994")
13
- payment.shipping = PagSeguro::Shipping.new(type: PagSeguro::Shipping::SEDEX, state: "SP", city: "São Paulo", postal_code: "05363000", district: "Jd. PoliPoli", street: "Av. Otacilio Tomanik", number: "775", complement: "apto. 92")
13
+ payment.shipping = PagSeguro::Shipping.new(
14
+ type: PagSeguro::Shipping::SEDEX,
15
+ state: "SP",
16
+ city: "São Paulo",
17
+ postal_code: "05363000",
18
+ district: "Jd. PoliPoli",
19
+ street: "Av. Otacilio Tomanik",
20
+ number: "775",
21
+ complement: "apto. 92")
14
22
  payment
15
23
  end
16
24
 
@@ -1,3 +1,3 @@
1
- email: billing@heavenstudio.com.br
2
- token: F4D44C5CE6BD4BD78E5CF5424A65A0D5
1
+ email: seu_email_cadastrado@nopagseguro.com.br
2
+ token: SEU_TOKEN_GERADO_NO_PAG_SEGURO
3
3
  notification_code: SEU_CODIGO_DE_NOTIFICACAO
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pag_seguro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-22 00:00:00.000000000 Z
12
+ date: 2012-03-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &2156484940 !ruby/object:Gem::Requirement
16
+ requirement: &2152275040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156484940
24
+ version_requirements: *2152275040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: haml
27
- requirement: &2156484480 !ruby/object:Gem::Requirement
27
+ requirement: &2164268940 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156484480
35
+ version_requirements: *2164268940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &2156484060 !ruby/object:Gem::Requirement
38
+ requirement: &2164268080 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2156484060
46
+ version_requirements: *2164268080
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rest-client
49
- requirement: &2156483560 !ruby/object:Gem::Requirement
49
+ requirement: &2164266920 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 1.6.7
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2156483560
57
+ version_requirements: *2164266920
58
58
  description:
59
59
  email:
60
60
  - stefano.diem@gmail.com