pagseguro_client 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pagseguro_client/base.rb +11 -3
- data/lib/pagseguro_client/notification.rb +23 -20
- data/lib/pagseguro_client/order.rb +7 -7
- data/lib/pagseguro_client/version.rb +1 -1
- data/pagseguro_client.gemspec +2 -2
- data/spec/pagseguro_client/base_spec.rb +11 -0
- data/spec/pagseguro_client/notification_spec.rb +14 -2
- data/spec/pagseguro_client/order_spec.rb +38 -30
- data/spec/support/config/routes.rb +0 -2
- metadata +49 -26
- data/.rbenv-gemsets +0 -1
- data/spec/support/app/models/account.rb +0 -2
- data/spec/support/app/models/user.rb +0 -3
- data/spec/support/app/views/dashboard/index.erb +0 -0
- data/spec/support/app/views/session/new.erb +0 -0
@@ -22,19 +22,27 @@ module PagseguroClient
|
|
22
22
|
|
23
23
|
@@config[Rails.env]
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def base_url
|
27
27
|
config["base_url"]
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def token
|
31
31
|
config["token"]
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def email
|
35
35
|
config["email"]
|
36
36
|
end
|
37
37
|
|
38
|
+
def payment_url(code)
|
39
|
+
"#{base_url}/v2/checkout/payment.html?code=#{code}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def notification_url(code)
|
43
|
+
"#{base_url}/v2/transactions/notifications/#{code}"
|
44
|
+
end
|
45
|
+
|
38
46
|
class MissingEnvironmentError < StandardError; end
|
39
47
|
class MissingConfigurationError < StandardError; end
|
40
48
|
end
|
@@ -9,7 +9,7 @@ module PagseguroClient
|
|
9
9
|
4 => :pagseguro,
|
10
10
|
5 => :oi_paggo
|
11
11
|
}
|
12
|
-
|
12
|
+
|
13
13
|
STATUS = {
|
14
14
|
1 => :pending,
|
15
15
|
2 => :verifying,
|
@@ -18,38 +18,41 @@ module PagseguroClient
|
|
18
18
|
6 => :refunded,
|
19
19
|
7 => :canceled
|
20
20
|
}
|
21
|
-
|
22
|
-
attr_accessor :code, :order_id, :
|
23
|
-
|
21
|
+
|
22
|
+
attr_accessor :code, :order_id, :status, :payment_method
|
23
|
+
|
24
24
|
def initialize(attributes = {})
|
25
25
|
attributes.each do |name, value|
|
26
26
|
send("#{name}=", value)
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
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
|
+
|
30
45
|
def self.retrieve(code)
|
31
|
-
response = RestClient.get(
|
46
|
+
response = RestClient.get(PagseguroClient.notification_url(code),
|
32
47
|
{
|
33
48
|
params: {
|
34
|
-
email: PagseguroClient.email,
|
49
|
+
email: PagseguroClient.email,
|
35
50
|
token: PagseguroClient.token
|
36
51
|
}
|
37
52
|
}
|
38
53
|
)
|
39
54
|
|
40
|
-
|
41
|
-
order_id = doc.xpath("//reference").text
|
42
|
-
order_code = doc.xpath("//code").text
|
43
|
-
status = doc.xpath("//status").text.to_i
|
44
|
-
payment_method = doc.xpath("//paymentMethod/type").text.to_i
|
45
|
-
|
46
|
-
Notification.new(
|
47
|
-
code: code,
|
48
|
-
order_id: order_id,
|
49
|
-
order_code: order_code,
|
50
|
-
status: STATUS[status],
|
51
|
-
payment_method: PAYMENT_METHOD[payment_method]
|
52
|
-
)
|
55
|
+
create_by_xml(response.body)
|
53
56
|
end
|
54
57
|
end
|
55
58
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module PagseguroClient
|
2
2
|
class Order
|
3
|
-
|
3
|
+
|
4
4
|
attr_accessor :id, :products
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(order_id)
|
7
7
|
self.id = order_id
|
8
8
|
self.products = []
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
# The allowed values are:
|
12
12
|
# - id (Required. Should match the product in your database)
|
13
13
|
# - description (Required. Identifies the product)
|
@@ -16,7 +16,7 @@ module PagseguroClient
|
|
16
16
|
def add(options)
|
17
17
|
products.push(options)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def data
|
21
21
|
data = {
|
22
22
|
email: PagseguroClient.email,
|
@@ -31,10 +31,10 @@ module PagseguroClient
|
|
31
31
|
data["itemAmount#{index}"] = item[:amount]
|
32
32
|
data["itemQuantity#{index}"] = item[:quantity] || 1
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
data
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
# Send a new payment request to Pagseguro
|
39
39
|
# Returns the URL to redirect your user to complete the payment in Pagseguro
|
40
40
|
def send_request
|
@@ -45,7 +45,7 @@ module PagseguroClient
|
|
45
45
|
|
46
46
|
{
|
47
47
|
code: code,
|
48
|
-
url:
|
48
|
+
url: PagseguroClient.payment_url(code)
|
49
49
|
}
|
50
50
|
end
|
51
51
|
end
|
data/pagseguro_client.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = PagseguroClient::VERSION
|
8
8
|
s.authors = ["Matheus Tardivo"]
|
9
9
|
s.email = ["matheustardivo@gmail.com"]
|
10
|
-
s.homepage = ""
|
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
|
13
13
|
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_development_dependency "rspec-rails" , "~> 2.
|
21
|
+
s.add_development_dependency "rspec-rails" , "~> 2.9"
|
22
22
|
s.add_development_dependency "rails" , "~> 3.2"
|
23
23
|
s.add_development_dependency "rake" , "~> 0.9"
|
24
24
|
s.add_development_dependency "sqlite3" , "~> 1.3"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Base" do
|
4
|
+
it "should return the payment url" do
|
5
|
+
PagseguroClient.payment_url("XPTO").should == "#{PagseguroClient.base_url}/v2/checkout/payment.html?code=XPTO"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return the notification url" do
|
9
|
+
PagseguroClient.notification_url("XPTO").should == "#{PagseguroClient.base_url}/v2/transactions/notifications/XPTO"
|
10
|
+
end
|
11
|
+
end
|
@@ -1,5 +1,17 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module PagseguroClient
|
4
|
+
describe Notification do
|
5
|
+
context "parse notification xml" do
|
6
|
+
subject {
|
7
|
+
Notification.create_by_xml(File.read("spec/support/notification.xml"))
|
8
|
+
}
|
9
|
+
|
10
|
+
# attr_accessor :code, :order_id, :status, :payment_method
|
11
|
+
its(:code) { should == "9E884542-81B3-4419-9A75-BCC6FB495EF1" }
|
12
|
+
its(:order_id) { should == "REF1234" }
|
13
|
+
its(:status) { should == :approved }
|
14
|
+
its(:payment_method) { should == :credit_card }
|
15
|
+
end
|
16
|
+
end
|
5
17
|
end
|
@@ -1,34 +1,42 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
order
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
order
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
3
|
+
module PagseguroClient
|
4
|
+
describe Order do
|
5
|
+
|
6
|
+
context "order with id" do
|
7
|
+
subject {
|
8
|
+
Order.new("ABCDEF")
|
9
|
+
}
|
10
|
+
|
11
|
+
its(:id) { should == "ABCDEF" }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "order with attributes and products" do
|
15
|
+
subject {
|
16
|
+
order = Order.new("John Doe")
|
17
|
+
order.add(id: "1", description: "Description", amount: 199)
|
18
|
+
order
|
19
|
+
}
|
20
|
+
|
21
|
+
it "should add product" do
|
22
|
+
subject.products.should_not be_empty
|
23
|
+
subject.products.size.should == 1
|
24
|
+
subject.products.first[:id].should == "1"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should set order product data" do
|
28
|
+
subject.add(id: "2", description: "Description", amount: 199)
|
29
|
+
subject.add(id: "3", description: "Description", amount: 199)
|
30
|
+
|
31
|
+
data = subject.data
|
32
|
+
data.keys.include?("itemId1").should be_true
|
33
|
+
data.keys.include?("itemId2").should be_true
|
34
|
+
data.keys.include?("itemId3").should be_true
|
35
|
+
|
36
|
+
data["itemId1"].should == "1"
|
37
|
+
data["itemId2"].should == "2"
|
38
|
+
data["itemId3"].should == "3"
|
39
|
+
end
|
40
|
+
end
|
32
41
|
end
|
33
|
-
|
34
42
|
end
|
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,27 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-rails
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '2.
|
21
|
+
version: '2.9'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.9'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rails
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '3.2'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.2'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rake
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0.9'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: sqlite3
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ~>
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '1.3'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.3'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: nokogiri
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ~>
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '1.5'
|
66
86
|
type: :runtime
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.5'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: rest-client
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ~>
|
@@ -76,7 +101,12 @@ dependencies:
|
|
76
101
|
version: '1.6'
|
77
102
|
type: :runtime
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.6'
|
80
110
|
description: The library to access the new services from Pagseguro (v2)
|
81
111
|
email:
|
82
112
|
- matheustardivo@gmail.com
|
@@ -85,7 +115,6 @@ extensions: []
|
|
85
115
|
extra_rdoc_files: []
|
86
116
|
files:
|
87
117
|
- .gitignore
|
88
|
-
- .rbenv-gemsets
|
89
118
|
- .rspec
|
90
119
|
- Gemfile
|
91
120
|
- README.markdown
|
@@ -96,14 +125,11 @@ files:
|
|
96
125
|
- lib/pagseguro_client/order.rb
|
97
126
|
- lib/pagseguro_client/version.rb
|
98
127
|
- pagseguro_client.gemspec
|
128
|
+
- spec/pagseguro_client/base_spec.rb
|
99
129
|
- spec/pagseguro_client/notification_spec.rb
|
100
130
|
- spec/pagseguro_client/order_spec.rb
|
101
131
|
- spec/spec_helper.rb
|
102
132
|
- spec/support/app/controllers/application_controller.rb
|
103
|
-
- spec/support/app/models/account.rb
|
104
|
-
- spec/support/app/models/user.rb
|
105
|
-
- spec/support/app/views/dashboard/index.erb
|
106
|
-
- spec/support/app/views/session/new.erb
|
107
133
|
- spec/support/config/boot.rb
|
108
134
|
- spec/support/config/database.yml
|
109
135
|
- spec/support/config/pagseguro.yml
|
@@ -111,7 +137,7 @@ files:
|
|
111
137
|
- spec/support/log/.gitkeep
|
112
138
|
- spec/support/log/test.log
|
113
139
|
- spec/support/notification.xml
|
114
|
-
homepage:
|
140
|
+
homepage: https://github.com/matheustardivo/pagseguro_client
|
115
141
|
licenses: []
|
116
142
|
post_install_message:
|
117
143
|
rdoc_options: []
|
@@ -131,19 +157,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
157
|
version: '0'
|
132
158
|
requirements: []
|
133
159
|
rubyforge_project: pagseguro_client
|
134
|
-
rubygems_version: 1.8.
|
160
|
+
rubygems_version: 1.8.23
|
135
161
|
signing_key:
|
136
162
|
specification_version: 3
|
137
163
|
summary: The library to access the new services from Pagseguro (v2)
|
138
164
|
test_files:
|
165
|
+
- spec/pagseguro_client/base_spec.rb
|
139
166
|
- spec/pagseguro_client/notification_spec.rb
|
140
167
|
- spec/pagseguro_client/order_spec.rb
|
141
168
|
- spec/spec_helper.rb
|
142
169
|
- spec/support/app/controllers/application_controller.rb
|
143
|
-
- spec/support/app/models/account.rb
|
144
|
-
- spec/support/app/models/user.rb
|
145
|
-
- spec/support/app/views/dashboard/index.erb
|
146
|
-
- spec/support/app/views/session/new.erb
|
147
170
|
- spec/support/config/boot.rb
|
148
171
|
- spec/support/config/database.yml
|
149
172
|
- spec/support/config/pagseguro.yml
|
data/.rbenv-gemsets
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
pagseguro_client
|
File without changes
|
File without changes
|