pagseguro-oficial 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +9 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE-2.0.txt +177 -0
  7. data/README.md +320 -0
  8. data/Rakefile +5 -0
  9. data/examples/abandoned_transactions.rb +26 -0
  10. data/examples/boot.rb +9 -0
  11. data/examples/invalid_transaction_by_notification_code.rb +9 -0
  12. data/examples/payment_request.rb +49 -0
  13. data/examples/transaction_by_notification_code.rb +5 -0
  14. data/examples/transactions_by_date.rb +23 -0
  15. data/lib/pagseguro/address.rb +40 -0
  16. data/lib/pagseguro/errors.rb +28 -0
  17. data/lib/pagseguro/exceptions.rb +3 -0
  18. data/lib/pagseguro/extensions/ensure_type.rb +9 -0
  19. data/lib/pagseguro/extensions/mass_assignment.rb +11 -0
  20. data/lib/pagseguro/item.rb +30 -0
  21. data/lib/pagseguro/items.rb +27 -0
  22. data/lib/pagseguro/notification.rb +21 -0
  23. data/lib/pagseguro/payment_method.rb +38 -0
  24. data/lib/pagseguro/payment_request/response.rb +30 -0
  25. data/lib/pagseguro/payment_request/serializer.rb +91 -0
  26. data/lib/pagseguro/payment_request.rb +96 -0
  27. data/lib/pagseguro/payment_status.rb +33 -0
  28. data/lib/pagseguro/phone.rb +12 -0
  29. data/lib/pagseguro/report.rb +124 -0
  30. data/lib/pagseguro/request.rb +78 -0
  31. data/lib/pagseguro/sender.rb +23 -0
  32. data/lib/pagseguro/shipping.rb +57 -0
  33. data/lib/pagseguro/transaction/response.rb +12 -0
  34. data/lib/pagseguro/transaction/serializer.rb +115 -0
  35. data/lib/pagseguro/transaction.rb +167 -0
  36. data/lib/pagseguro/version.rb +3 -0
  37. data/lib/pagseguro-oficial.rb +1 -0
  38. data/lib/pagseguro.rb +94 -0
  39. data/locales/pt-BR.yml +115 -0
  40. data/pagseguro-oficial.gemspec +32 -0
  41. data/spec/fixtures/by_date/success.xml +85 -0
  42. data/spec/fixtures/invalid_code.xml +7 -0
  43. data/spec/fixtures/payment_request/failure.xml +7 -0
  44. data/spec/fixtures/payment_request/success.xml +5 -0
  45. data/spec/fixtures/transactions/additional.xml +53 -0
  46. data/spec/fixtures/transactions/success.xml +53 -0
  47. data/spec/pagseguro/address_spec.rb +17 -0
  48. data/spec/pagseguro/errors_spec.rb +91 -0
  49. data/spec/pagseguro/item_spec.rb +20 -0
  50. data/spec/pagseguro/items_spec.rb +56 -0
  51. data/spec/pagseguro/notification_spec.rb +18 -0
  52. data/spec/pagseguro/pagseguro_spec.rb +54 -0
  53. data/spec/pagseguro/payment_method_spec.rb +41 -0
  54. data/spec/pagseguro/payment_request/response_spec.rb +24 -0
  55. data/spec/pagseguro/payment_request/serializer_spec.rb +142 -0
  56. data/spec/pagseguro/payment_request_spec.rb +107 -0
  57. data/spec/pagseguro/payment_status_spec.rb +24 -0
  58. data/spec/pagseguro/phone_spec.rb +6 -0
  59. data/spec/pagseguro/request_spec.rb +75 -0
  60. data/spec/pagseguro/sender_spec.rb +9 -0
  61. data/spec/pagseguro/shipping_spec.rb +40 -0
  62. data/spec/pagseguro/transaction/serializer_spec.rb +61 -0
  63. data/spec/pagseguro/transaction_spec.rb +118 -0
  64. data/spec/spec_helper.rb +29 -0
  65. data/spec/support/ensure_type_macro.rb +17 -0
  66. data/spec/support/mass_assignment_macro.rb +11 -0
  67. metadata +289 -0
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ require "./lib/pagseguro/version"
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.required_ruby_version = ">= 1.9.3"
6
+ spec.name = "pagseguro-oficial"
7
+ spec.version = PagSeguro::VERSION
8
+ spec.authors = ["Nando Vieira"]
9
+ spec.email = ["fnando.vieira@gmail.com"]
10
+ spec.description = "Biblioteca oficial de integração PagSeguro em Ruby"
11
+ spec.summary = spec.description
12
+ spec.homepage = "http://www.pagseguro.com.br"
13
+ spec.license = "ASL"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "aitch", ">= 0.2.1"
21
+ spec.add_dependency "nokogiri"
22
+ spec.add_dependency "i18n"
23
+ spec.add_dependency "json"
24
+
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "autotest-standalone"
29
+ spec.add_development_dependency "test_notifier"
30
+ spec.add_development_dependency "simplecov"
31
+ spec.add_development_dependency "fakeweb"
32
+ end
@@ -0,0 +1,85 @@
1
+ <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
2
+ <transactionSearchResult>
3
+ <date>2013-05-29T07:55:26.000-03:00</date>
4
+ <transactions>
5
+ <transaction>
6
+ <date>2013-05-24T15:42:39.000-03:00</date>
7
+ <code>6853CD06-562E-4D9C-9427-75BFADBCEA0D</code>
8
+ <type>1</type>
9
+ <status>3</status>
10
+ <paymentMethod>
11
+ <type>1</type>
12
+ </paymentMethod>
13
+ <grossAmount>450.00</grossAmount>
14
+ <discountAmount>0.00</discountAmount>
15
+ <feeAmount>29.20</feeAmount>
16
+ <netAmount>420.80</netAmount>
17
+ <extraAmount>0.00</extraAmount>
18
+ <lastEventDate>2013-05-24T15:44:27.000-03:00</lastEventDate>
19
+ </transaction>
20
+ <transaction>
21
+ <date>2013-05-24T15:10:59.000-03:00</date>
22
+ <code>DE9F09F9-BC1C-459A-A3A9-9D4B9D8FA663</code>
23
+ <type>1</type>
24
+ <status>3</status>
25
+ <paymentMethod>
26
+ <type>1</type>
27
+ </paymentMethod>
28
+ <grossAmount>550.00</grossAmount>
29
+ <discountAmount>0.00</discountAmount>
30
+ <feeAmount>35.60</feeAmount>
31
+ <netAmount>514.40</netAmount>
32
+ <extraAmount>0.00</extraAmount>
33
+ <lastEventDate>2013-05-24T15:12:06.000-03:00</lastEventDate>
34
+ </transaction>
35
+ <transaction>
36
+ <date>2013-05-16T09:40:14.000-03:00</date>
37
+ <code>AF469F9E-4C87-47B9-ACF5-0678037483E1</code>
38
+ <type>1</type>
39
+ <status>3</status>
40
+ <paymentMethod>
41
+ <type>1</type>
42
+ </paymentMethod>
43
+ <grossAmount>520.00</grossAmount>
44
+ <discountAmount>0.00</discountAmount>
45
+ <feeAmount>33.68</feeAmount>
46
+ <netAmount>486.32</netAmount>
47
+ <extraAmount>0.00</extraAmount>
48
+ <lastEventDate>2013-05-16T09:42:53.000-03:00</lastEventDate>
49
+ </transaction>
50
+ <transaction>
51
+ <date>2013-05-09T01:21:24.000-03:00</date>
52
+ <code>52BBF866-1EE3-486A-AA11-C08C00375BDF</code>
53
+ <type>1</type>
54
+ <status>7</status>
55
+ <cancellationSource>EXTERNAL</cancellationSource>
56
+ <paymentMethod>
57
+ <type>1</type>
58
+ </paymentMethod>
59
+ <grossAmount>520.00</grossAmount>
60
+ <discountAmount>0.00</discountAmount>
61
+ <feeAmount>33.68</feeAmount>
62
+ <netAmount>486.32</netAmount>
63
+ <extraAmount>0.00</extraAmount>
64
+ <lastEventDate>2013-05-09T01:22:20.000-03:00</lastEventDate>
65
+ </transaction>
66
+ <transaction>
67
+ <date>2013-05-06T19:45:39.000-03:00</date>
68
+ <code>5E68D3A7-AB57-4C0E-B29F-1901AF497BA9</code>
69
+ <type>1</type>
70
+ <status>4</status>
71
+ <paymentMethod>
72
+ <type>1</type>
73
+ </paymentMethod>
74
+ <grossAmount>500.00</grossAmount>
75
+ <discountAmount>0.00</discountAmount>
76
+ <feeAmount>32.40</feeAmount>
77
+ <netAmount>467.60</netAmount>
78
+ <extraAmount>0.00</extraAmount>
79
+ <lastEventDate>2013-05-20T19:57:57.000-03:00</lastEventDate>
80
+ </transaction>
81
+ </transactions>
82
+ <resultsInThisPage>5</resultsInThisPage>
83
+ <currentPage>1</currentPage>
84
+ <totalPages>1</totalPages>
85
+ </transactionSearchResult>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
2
+ <errors>
3
+ <error>
4
+ <code>13001</code>
5
+ <message>invalid notification code value: 999769-79C052C05280-55542D9FBB33-4AB2D0</message>
6
+ </error>
7
+ </errors>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
2
+ <errors>
3
+ <error>
4
+ <code>11024</code>
5
+ <message>Items invalid quantity.</message>
6
+ </error>
7
+ </errors>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="ISO-8859-1"?>
2
+ <checkout>
3
+ <code>8CF4BE7DCECEF0F004A6DFA0A8243412</code>
4
+ <date>2010-12-02T10:11:28.000-02:00</date>
5
+ </checkout>
@@ -0,0 +1,53 @@
1
+ <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
2
+ <transaction>
3
+ <date>2013-05-01T01:40:27.000-03:00</date>
4
+ <code>667A3914-4F9F-4705-0EB6-CA6FA0DF8A19</code>
5
+ <reference>REF1234</reference>
6
+ <type>1</type>
7
+ <status>1</status>
8
+ <lastEventDate>2013-05-01T01:41:20.000-03:00</lastEventDate>
9
+ <cancellationSource>PagSeguro</cancellationSource>
10
+ <escrowEndDate>2013-06-01T01:41:20.000-03:00</escrowEndDate>
11
+ <paymentMethod>
12
+ <type>2</type>
13
+ <code>202</code>
14
+ </paymentMethod>
15
+ <paymentLink>https://pagseguro.uol.com.br/checkout/imprimeBoleto.jhtml?code=667D39144F9F47059FB6CA6FA0DF8A20</paymentLink>
16
+ <grossAmount>459.50</grossAmount>
17
+ <discountAmount>0.00</discountAmount>
18
+ <feeAmount>13.73</feeAmount>
19
+ <netAmount>445.77</netAmount>
20
+ <extraAmount>0.00</extraAmount>
21
+ <installmentCount>1</installmentCount>
22
+ <itemCount>1</itemCount>
23
+ <items>
24
+ <item>
25
+ <id>1234</id>
26
+ <description>Some product</description>
27
+ <quantity>1</quantity>
28
+ <amount>459.50</amount>
29
+ </item>
30
+ </items>
31
+ <sender>
32
+ <name>JOHN DOE</name>
33
+ <email>john@example.com</email>
34
+ <phone>
35
+ <areaCode>11</areaCode>
36
+ <number>12345678</number>
37
+ </phone>
38
+ </sender>
39
+ <shipping>
40
+ <address>
41
+ <street>AV. BRIG. FARIA LIMA</street>
42
+ <number>1384</number>
43
+ <complement>5 ANDAR</complement>
44
+ <district>JARDIM PAULISTANO</district>
45
+ <city>SAO PAULO</city>
46
+ <state>SP</state>
47
+ <country>BRA</country>
48
+ <postalCode>01452002</postalCode>
49
+ </address>
50
+ <type>2</type>
51
+ <cost>0.00</cost>
52
+ </shipping>
53
+ </transaction>
@@ -0,0 +1,53 @@
1
+ <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
2
+ <transaction>
3
+ <date>2013-05-01T01:40:27.000-03:00</date>
4
+ <code>667A3914-4F9F-4705-0EB6-CA6FA0DF8A19</code>
5
+ <reference>REF1234</reference>
6
+ <type>1</type>
7
+ <status>1</status>
8
+ <lastEventDate>2013-05-01T01:41:20.000-03:00</lastEventDate>
9
+ <!-- <cancellationSource>PagSeguro</cancellationSource> -->
10
+ <!-- <escrowEndDate>2013-06-01T01:41:20.000-03:00</escrowEndDate> -->
11
+ <paymentMethod>
12
+ <type>2</type>
13
+ <code>202</code>
14
+ </paymentMethod>
15
+ <paymentLink>https://pagseguro.uol.com.br/checkout/imprimeBoleto.jhtml?code=667D39144F9F47059FB6CA6FA0DF8A20</paymentLink>
16
+ <grossAmount>459.50</grossAmount>
17
+ <discountAmount>0.00</discountAmount>
18
+ <feeAmount>13.73</feeAmount>
19
+ <netAmount>445.77</netAmount>
20
+ <extraAmount>0.00</extraAmount>
21
+ <installmentCount>1</installmentCount>
22
+ <itemCount>1</itemCount>
23
+ <items>
24
+ <item>
25
+ <id>1234</id>
26
+ <description>Some product</description>
27
+ <quantity>1</quantity>
28
+ <amount>459.50</amount>
29
+ </item>
30
+ </items>
31
+ <sender>
32
+ <name>JOHN DOE</name>
33
+ <email>john@example.com</email>
34
+ <phone>
35
+ <areaCode>11</areaCode>
36
+ <number>12345678</number>
37
+ </phone>
38
+ </sender>
39
+ <shipping>
40
+ <address>
41
+ <street>AV. BRIG. FARIA LIMA</street>
42
+ <number>1384</number>
43
+ <complement>5 ANDAR</complement>
44
+ <district>JARDIM PAULISTANO</district>
45
+ <city>SAO PAULO</city>
46
+ <state>SP</state>
47
+ <country>BRA</country>
48
+ <postalCode>01452002</postalCode>
49
+ </address>
50
+ <type>2</type>
51
+ <cost>0.00</cost>
52
+ </shipping>
53
+ </transaction>
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Address do
4
+ it_assigns_attribute :street
5
+ it_assigns_attribute :number
6
+ it_assigns_attribute :complement
7
+ it_assigns_attribute :district
8
+ it_assigns_attribute :city
9
+ it_assigns_attribute :state
10
+ it_assigns_attribute :country
11
+ it_assigns_attribute :postal_code
12
+
13
+ it "sets default country" do
14
+ address = PagSeguro::Address.new
15
+ expect(address.country).to eql("BRA")
16
+ end
17
+ end
@@ -0,0 +1,91 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "spec_helper"
3
+
4
+ describe PagSeguro::Errors do
5
+ let(:response) { double }
6
+
7
+ context "when have no response" do
8
+ it "returns errors" do
9
+ errors = PagSeguro::Errors.new
10
+ expect(errors).to be_empty
11
+ end
12
+ end
13
+
14
+ context "when unauthorized" do
15
+ subject(:errors) { PagSeguro::Errors.new(response) }
16
+
17
+ before do
18
+ response.stub unauthorized?: true, bad_request?: false
19
+ end
20
+
21
+ it { should_not be_empty }
22
+ it { should include(I18n.t("pagseguro.errors.unauthorized")) }
23
+ end
24
+
25
+ context "when message can't be translated" do
26
+ let(:error) {
27
+ <<-XML
28
+ <errors>
29
+ <error>
30
+ <code>1234</code>
31
+ <message>Sample message</message>
32
+ </error>
33
+ </errors>
34
+ XML
35
+ }
36
+
37
+ let(:xml) { Nokogiri::XML(error) }
38
+ subject(:errors) { PagSeguro::Errors.new(response) }
39
+
40
+ before do
41
+ response.stub data: xml, unauthorized?: false, bad_request?: true
42
+ end
43
+
44
+ it { expect(errors).to include("Sample message") }
45
+ end
46
+
47
+ context "when message can be translated" do
48
+ let(:error) {
49
+ <<-XML
50
+ <errors>
51
+ <error>
52
+ <code>10001</code>
53
+ <message>Sample message</message>
54
+ </error>
55
+ </errors>
56
+ XML
57
+ }
58
+
59
+ let(:xml) { Nokogiri::XML(error) }
60
+ subject(:errors) { PagSeguro::Errors.new(response) }
61
+
62
+ before do
63
+ response.stub data: xml, unauthorized?: false, bad_request?: true
64
+ end
65
+
66
+ it { expect(errors).to include("O parâmetro email deve ser informado.") }
67
+ end
68
+
69
+ context "when returning 404 status" do
70
+ let(:error) {
71
+ <<-XML
72
+ <?xml version="1.0" encoding="UTF-8"?>
73
+ <errors>
74
+ <error>
75
+ <code>Malformed request XML: {0}.</code>
76
+ <message>Malformed request XML: XML document structures must start and end within the same entity..</message>
77
+ </error>
78
+ </errors>
79
+ XML
80
+ }
81
+
82
+ let(:xml) { Nokogiri::XML(error) }
83
+ subject(:errors) { PagSeguro::Errors.new(response) }
84
+
85
+ before do
86
+ response.stub data: xml, unauthorized?: false, bad_request?: true
87
+ end
88
+
89
+ it { expect(errors).to include("Malformed request XML: XML document structures must start and end within the same entity..") }
90
+ end
91
+ end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Item do
4
+ it_assigns_attribute :id
5
+ it_assigns_attribute :description
6
+ it_assigns_attribute :amount
7
+ it_assigns_attribute :quantity
8
+ it_assigns_attribute :weight
9
+ it_assigns_attribute :shipping_cost
10
+
11
+ it "sets default quantity" do
12
+ item = PagSeguro::Item.new
13
+ expect(item.quantity).to eql(1)
14
+ end
15
+
16
+ it "sets default weight" do
17
+ item = PagSeguro::Item.new
18
+ expect(item.weight).to be_zero
19
+ end
20
+ end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Items do
4
+ it "implements #each" do
5
+ expect(PagSeguro::Items.new).to respond_to(:each)
6
+ end
7
+
8
+ it "implements #any" do
9
+ expect(PagSeguro::Items.new).to respond_to(:any?)
10
+ end
11
+
12
+ it "includes Enumerable" do
13
+ expect(PagSeguro::Items.included_modules).to include(Enumerable)
14
+ end
15
+
16
+ it "sets item" do
17
+ item = PagSeguro::Item.new
18
+ items = PagSeguro::Items.new
19
+ items << item
20
+
21
+ expect(items.size).to eql(1)
22
+ expect(items).to include(item)
23
+ end
24
+
25
+ it "sets item from Hash" do
26
+ item = PagSeguro::Item.new(id: 1234)
27
+
28
+ PagSeguro::Item
29
+ .should_receive(:new)
30
+ .with({id: 1234})
31
+ .and_return(item)
32
+
33
+ items = PagSeguro::Items.new
34
+ items << {id: 1234}
35
+
36
+ expect(items).to include(item)
37
+ end
38
+
39
+ it "increases quantity when adding duplicated item" do
40
+ item = PagSeguro::Item.new(id: 1234)
41
+ items = PagSeguro::Items.new
42
+ items << item
43
+ items << item
44
+
45
+ expect(items.size).to eql(1)
46
+ expect(item.quantity).to eql(2)
47
+ end
48
+
49
+ it "empties items" do
50
+ items = PagSeguro::Items.new
51
+ items << {id: 1234}
52
+ items.clear
53
+
54
+ expect(items).to be_empty
55
+ end
56
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe PagSeguro::Notification do
4
+ it_assigns_attribute :code
5
+ it_assigns_attribute :type
6
+
7
+ it "detects notification as transaction" do
8
+ expect(PagSeguro::Notification.new(type: "transaction")).to be_transaction
9
+ end
10
+
11
+ it "fetches transaction by its notificationCode" do
12
+ PagSeguro::Transaction
13
+ .should_receive(:find_by_notification_code)
14
+ .with("CODE")
15
+
16
+ PagSeguro::Notification.new(code: "CODE").transaction
17
+ end
18
+ end