pagseguro-transparente 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +34 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +89 -0
  6. data/README.md +79 -0
  7. data/Rakefile +5 -0
  8. data/coverage/.last_run.json +5 -0
  9. data/coverage/.resultset.json +1665 -0
  10. data/coverage/assets/0.8.0/application.css +799 -0
  11. data/coverage/assets/0.8.0/application.js +1559 -0
  12. data/coverage/assets/0.8.0/colorbox/border.png +0 -0
  13. data/coverage/assets/0.8.0/colorbox/controls.png +0 -0
  14. data/coverage/assets/0.8.0/colorbox/loading.gif +0 -0
  15. data/coverage/assets/0.8.0/colorbox/loading_background.png +0 -0
  16. data/coverage/assets/0.8.0/favicon_green.png +0 -0
  17. data/coverage/assets/0.8.0/favicon_red.png +0 -0
  18. data/coverage/assets/0.8.0/favicon_yellow.png +0 -0
  19. data/coverage/assets/0.8.0/loading.gif +0 -0
  20. data/coverage/assets/0.8.0/magnify.png +0 -0
  21. data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  22. data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  23. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  24. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  25. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  26. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  27. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  28. data/coverage/assets/0.8.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  29. data/coverage/assets/0.8.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  30. data/coverage/assets/0.8.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  31. data/coverage/assets/0.8.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  32. data/coverage/assets/0.8.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  33. data/coverage/assets/0.8.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  34. data/coverage/index.html +10198 -0
  35. data/lib/pagseguro/address.rb +46 -0
  36. data/lib/pagseguro/bank.rb +15 -0
  37. data/lib/pagseguro/credit_card.rb +23 -0
  38. data/lib/pagseguro/document.rb +20 -0
  39. data/lib/pagseguro/exceptions.rb +22 -0
  40. data/lib/pagseguro/holder.rb +24 -0
  41. data/lib/pagseguro/installment.rb +17 -0
  42. data/lib/pagseguro/item.rb +29 -0
  43. data/lib/pagseguro/items.rb +16 -0
  44. data/lib/pagseguro/notification/address.rb +43 -0
  45. data/lib/pagseguro/notification/item.rb +14 -0
  46. data/lib/pagseguro/notification/items.rb +18 -0
  47. data/lib/pagseguro/notification/payment_method.rb +19 -0
  48. data/lib/pagseguro/notification/phone.rb +19 -0
  49. data/lib/pagseguro/notification/sender.rb +23 -0
  50. data/lib/pagseguro/notification/shipping.rb +23 -0
  51. data/lib/pagseguro/notification.rb +82 -0
  52. data/lib/pagseguro/phone.rb +21 -0
  53. data/lib/pagseguro/request.rb +21 -0
  54. data/lib/pagseguro/sender.rb +28 -0
  55. data/lib/pagseguro/session/response.rb +15 -0
  56. data/lib/pagseguro/session.rb +7 -0
  57. data/lib/pagseguro/shipping.rb +23 -0
  58. data/lib/pagseguro/transaction/serializer.rb +158 -0
  59. data/lib/pagseguro/transaction.rb +91 -0
  60. data/lib/pagseguro/version.rb +3 -0
  61. data/lib/pagseguro-transparente.rb +1 -0
  62. data/lib/pagseguro.rb +54 -0
  63. data/pagseguro-transparente.gemspec +34 -0
  64. data/spec/pagseguro/address_spec.rb +35 -0
  65. data/spec/pagseguro/bank_spec.rb +17 -0
  66. data/spec/pagseguro/credit_card_spec.rb +18 -0
  67. data/spec/pagseguro/document_spec.rb +18 -0
  68. data/spec/pagseguro/holder_spec.rb +18 -0
  69. data/spec/pagseguro/installment_spec.rb +14 -0
  70. data/spec/pagseguro/item_spec.rb +28 -0
  71. data/spec/pagseguro/items_spec.rb +13 -0
  72. data/spec/pagseguro/notification/address_spec.rb +33 -0
  73. data/spec/pagseguro/notification/item_spec.rb +15 -0
  74. data/spec/pagseguro/notification/items_spec.rb +31 -0
  75. data/spec/pagseguro/notification/payment_method_spec.rb +21 -0
  76. data/spec/pagseguro/notification/phone_spec.rb +21 -0
  77. data/spec/pagseguro/notification/sender_spec.rb +26 -0
  78. data/spec/pagseguro/notification/shipping_spec.rb +22 -0
  79. data/spec/pagseguro/notification_spec.rb +45 -0
  80. data/spec/pagseguro/pagseguro_spec.rb +23 -0
  81. data/spec/pagseguro/phone_spec.rb +19 -0
  82. data/spec/pagseguro/sender_spec.rb +20 -0
  83. data/spec/pagseguro/session/response_spec.rb +17 -0
  84. data/spec/pagseguro/session_spec.rb +23 -0
  85. data/spec/pagseguro/shipping_spec.rb +22 -0
  86. data/spec/pagseguro/transaction/serializer_spec.rb +131 -0
  87. data/spec/pagseguro/transaction_spec.rb +91 -0
  88. data/spec/spec_helper.rb +16 -0
  89. metadata +311 -0
@@ -0,0 +1,46 @@
1
+ module PagSeguro
2
+ class Address
3
+ include ActiveModel::Validations
4
+ validates_presence_of :postal_code, :street, :number
5
+ validates_presence_of :district, :city, :state, :country
6
+
7
+ validates_length_of :country, is: 3
8
+ validates_length_of :state, is: 2
9
+ validates_length_of :postal_code, is: 8
10
+ # Set the postal_code.
11
+ # 8 digit number represeting a valid CEP i.e 01452002
12
+ attr_accessor :postal_code
13
+
14
+ # Set the street name.
15
+ attr_accessor :street
16
+
17
+ # Set the number.
18
+ attr_accessor :number
19
+
20
+ # Get the complement.
21
+ attr_accessor :complement
22
+
23
+ # Get the district.
24
+ attr_accessor :district
25
+
26
+ # Get the city.
27
+ attr_accessor :city
28
+
29
+ # Get the state.
30
+ attr_accessor :state
31
+
32
+ # Get the country.
33
+ attr_accessor :country
34
+
35
+ def initialize(options = {})
36
+ @country = "BRA"
37
+ @postal_code = options[:postal_code]
38
+ @street = options[:street]
39
+ @number = options[:number]
40
+ @complement = options[:complement]
41
+ @district = options[:district]
42
+ @city = options[:city]
43
+ @state = options[:state]
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,15 @@
1
+ module PagSeguro
2
+ class Bank
3
+ include ActiveModel::Validations
4
+
5
+ validates_presence_of :name
6
+ validates_inclusion_of :name, in: %w(bradesco itau bancodobrasil banrisul hsbc)
7
+ # Set the bank name
8
+ # Should be a valid bank: bradesco, itau, bancodobrasil, banrisul ou hsbc
9
+ attr_accessor :name
10
+
11
+ def initialize(name)
12
+ @name = name
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module PagSeguro
2
+ class CreditCard
3
+ include ActiveModel::Validations
4
+
5
+ validates_presence_of :token, :installment, :holder, :billing_address
6
+
7
+ # Set the token that represents the credit card.
8
+ attr_accessor :token
9
+
10
+ # Set the CPF document.
11
+ attr_accessor :installment
12
+
13
+ # Get the sender phone.
14
+ attr_accessor :holder
15
+
16
+ # Get the sender phone.
17
+ attr_accessor :billing_address
18
+
19
+ def initialize(token)
20
+ @token = token
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ module PagSeguro
2
+ class Document
3
+ include ActiveModel::Validations
4
+
5
+ validates_presence_of :type, :value
6
+
7
+ # Set the document type
8
+ # Only CPF is acceptable
9
+ attr_accessor :type
10
+
11
+ # Set the document number.
12
+ # Must have 7-9 numbers.
13
+ attr_accessor :value
14
+
15
+ def initialize(value)
16
+ @type = 'CPF'
17
+ @value = value
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ module PagSeguro
2
+
3
+ class InvalidTransaction < StandardError; end
4
+
5
+ class InvalidShipping < StandardError; end
6
+
7
+ class InvalidItem < StandardError; end
8
+
9
+ class InvalidSender < StandardError; end
10
+
11
+ class InvalidPhone < StandardError; end
12
+
13
+ class InvalidBank < StandardError; end
14
+
15
+ class InvalidCreditCard < StandardError; end
16
+
17
+ class InvalidInstallment < StandardError; end
18
+
19
+ class InvalidHolder < StandardError; end
20
+
21
+ class InvalidAddress < StandardError; end
22
+ end
@@ -0,0 +1,24 @@
1
+ module PagSeguro
2
+ class Holder
3
+ include ActiveModel::Validations
4
+
5
+ validates_presence_of :name, :birthdate, :document, :phone
6
+
7
+ # Set the credit card holder name.
8
+ attr_accessor :name
9
+
10
+ # Set the credit card holder bithdate.
11
+ attr_accessor :birthdate
12
+
13
+ # Set the credit card holder document.
14
+ attr_accessor :document
15
+
16
+ # Get the sender phone.
17
+ attr_accessor :phone
18
+
19
+ def initialize(name, birthdate)
20
+ @name = name
21
+ @birthdate = birthdate
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ module PagSeguro
2
+ class Installment
3
+ include ActiveModel::Validations
4
+ validates_presence_of :quantity, :value
5
+
6
+ # Set the total of installments
7
+ attr_accessor :quantity
8
+
9
+ # Set the installment value.
10
+ attr_accessor :value
11
+
12
+ def initialize(quantity, value)
13
+ @quantity = quantity
14
+ @value = value
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ module PagSeguro
2
+ class Item
3
+ include ActiveModel::Validations
4
+
5
+ validates_presence_of :id, :description, :amount, :quantity
6
+ validates_numericality_of :amount, :quantity, greater_than: 0
7
+ validates_numericality_of :quantity, only_integer: true
8
+
9
+ # Set the product identifier, such as SKU.
10
+ attr_accessor :id
11
+
12
+ # Set the product description.
13
+ attr_accessor :description
14
+
15
+ # Set the amount per unit.
16
+ attr_accessor :amount
17
+
18
+ # Set the quantity.
19
+ # Defaults to 1.
20
+ attr_accessor :quantity
21
+
22
+ def initialize(id, description, amount, quantity = 1)
23
+ @id = id
24
+ @description = description
25
+ @amount = amount
26
+ @quantity = quantity
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ module PagSeguro
2
+ class Items
3
+ extend Forwardable
4
+ include Enumerable
5
+
6
+ def_delegators :@store, :size, :clear, :empty?, :any?, :each
7
+
8
+ def initialize
9
+ @store = []
10
+ end
11
+
12
+ def <<(item)
13
+ @store << item
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,43 @@
1
+ module PagSeguro
2
+ class Notification
3
+ class Address
4
+ attr_reader :address
5
+
6
+ def initialize(address)
7
+ @address = address
8
+ end
9
+
10
+ def street
11
+ address['street']
12
+ end
13
+
14
+ def number
15
+ address['number']
16
+ end
17
+
18
+ def complement
19
+ address['complement']
20
+ end
21
+
22
+ def district
23
+ address['district']
24
+ end
25
+
26
+ def postal_code
27
+ address['postalCode']
28
+ end
29
+
30
+ def city
31
+ address['city']
32
+ end
33
+
34
+ def state
35
+ address['state']
36
+ end
37
+
38
+ def country
39
+ address['country']
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,14 @@
1
+ module PagSeguro
2
+ class Notification
3
+ class Item
4
+ attr_accessor :id, :description, :quantity, :amount
5
+
6
+ def initialize(id, description, quantity, amount)
7
+ @id = id
8
+ @description = description
9
+ @quantity = quantity
10
+ @amount = amount
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module PagSeguro
2
+ class Notification
3
+ class Items
4
+ attr_reader :count
5
+
6
+ def initialize(store, count)
7
+ @store = store
8
+ @count = count
9
+ end
10
+
11
+ def items
12
+ @store['item'].map do |i|
13
+ Item.new(i['id'], i['description'], i['quantity'], i['amount'])
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ module PagSeguro
2
+ class Notification
3
+ class PaymentMethod
4
+ attr_reader :payment_method
5
+
6
+ def initialize(payment_method)
7
+ @payment_method = payment_method
8
+ end
9
+
10
+ def payment_type
11
+ payment_method['type']
12
+ end
13
+
14
+ def payment_code
15
+ payment_method['code']
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module PagSeguro
2
+ class Notification
3
+ class Phone
4
+ attr_reader :phone
5
+
6
+ def initialize(phone)
7
+ @phone = phone
8
+ end
9
+
10
+ def area_code
11
+ phone['areaCode']
12
+ end
13
+
14
+ def number
15
+ phone['number']
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module PagSeguro
2
+ class Notification
3
+ class Sender
4
+ attr_reader :sender
5
+
6
+ def initialize(sender)
7
+ @sender = sender
8
+ end
9
+
10
+ def name
11
+ sender['name']
12
+ end
13
+
14
+ def email
15
+ sender['email']
16
+ end
17
+
18
+ def phone
19
+ Phone.new(sender['phone'])
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module PagSeguro
2
+ class Notification
3
+ class Shipping
4
+ attr_reader :shipping
5
+
6
+ def initialize(shipping)
7
+ @shipping = shipping
8
+ end
9
+
10
+ def address
11
+ Address.new(shipping['address'])
12
+ end
13
+
14
+ def type
15
+ shipping['type']
16
+ end
17
+
18
+ def cost
19
+ shipping['cost']
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,82 @@
1
+ module PagSeguro
2
+ class Notification
3
+ attr_reader :response
4
+
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def date
10
+ transaction['date']
11
+ end
12
+
13
+ def last_event_date
14
+ transaction['lastEventDate']
15
+ end
16
+
17
+ def code
18
+ transaction['code']
19
+ end
20
+
21
+ def reference
22
+ transaction['reference']
23
+ end
24
+
25
+ def type
26
+ transaction['type']
27
+ end
28
+
29
+ def status
30
+ transaction['status']
31
+ end
32
+
33
+ def payment_method
34
+ PaymentMethod.new(transaction['paymentMethod'])
35
+ end
36
+
37
+ def payment_link
38
+ transaction['paymentLink']
39
+ end
40
+
41
+ def gross_amount
42
+ transaction['grossAmount']
43
+ end
44
+
45
+ def discount_amount
46
+ transaction['discountAmount']
47
+ end
48
+
49
+ def fee_amount
50
+ transaction['feeAmount']
51
+ end
52
+
53
+ def net_amount
54
+ transaction['netAmount']
55
+ end
56
+
57
+ def extra_amount
58
+ transaction['extraAmount']
59
+ end
60
+
61
+ def installment_count
62
+ transaction['installmentCount']
63
+ end
64
+
65
+ def items
66
+ Items.new(transaction['paymentMethod'], transaction['itemCount'])
67
+ end
68
+
69
+ def sender
70
+ Sender.new(transaction['sender'])
71
+ end
72
+
73
+ def shipping
74
+ Shipping.new(transaction['shipping'])
75
+ end
76
+
77
+ private
78
+ def transaction
79
+ response['transaction']
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,21 @@
1
+ module PagSeguro
2
+ class Phone
3
+ include ActiveModel::Validations
4
+
5
+ validates_presence_of :area_code, :number
6
+ validates_length_of :area_code, is: 2
7
+ validates_length_of :number, in: 7..9
8
+
9
+ # Set the area code.
10
+ attr_accessor :area_code
11
+
12
+ # Set the phone number.
13
+ # Must have 7-9 numbers.
14
+ attr_accessor :number
15
+
16
+ def initialize(area_code, number)
17
+ @area_code = area_code
18
+ @number = number
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'httparty'
2
+
3
+ module PagSeguro
4
+ class Request
5
+ include HTTParty
6
+ debug_output $stderr
7
+
8
+ base_uri "https://ws.pagseguro.uol.com.br/v2/"
9
+
10
+ def get(path, options = {})
11
+ self.class.get(path, options)
12
+ end
13
+
14
+ def post(path, params = {})
15
+ options = { body: { email: PagSeguro.email, token: PagSeguro.token} }
16
+ options[:body].merge!(params)
17
+ response = self.class.post(path, options)
18
+ response.parsed_response
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ module PagSeguro
2
+ class Sender
3
+ include ActiveModel::Validations
4
+
5
+ validates_presence_of :email, :name, :hash_id, :document, :phone
6
+
7
+ # Set the sender e-mail.
8
+ attr_accessor :email
9
+
10
+ # Set the sender name.
11
+ attr_accessor :name
12
+
13
+ # Set the hash identifier.
14
+ attr_accessor :hash_id
15
+
16
+ # Set the CPF document.
17
+ attr_accessor :document
18
+
19
+ # Get the sender phone.
20
+ attr_accessor :phone
21
+
22
+ def initialize(options = {})
23
+ @email = options[:email]
24
+ @name = options[:name]
25
+ @hash_id = options[:hash_id]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module PagSeguro
2
+ class Session
3
+ class Response
4
+ attr_reader :response
5
+
6
+ def initialize(response)
7
+ @response = response
8
+ end
9
+
10
+ def id
11
+ @id ||= response['session']['id']
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module PagSeguro
2
+ class Session < Request
3
+ def create
4
+ Response.new post('/sessions')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ module PagSeguro
2
+ class Shipping
3
+ include ActiveModel::Validations
4
+
5
+ validates_presence_of :address
6
+ validates_inclusion_of :type_id, in: %w( 1 2 3 ), allow_blank: true
7
+ validates_numericality_of :cost, greater_than: 0
8
+
9
+ # Set the shipping type
10
+ attr_accessor :type_id
11
+
12
+ # Set the credit card holder bithdate.
13
+ attr_accessor :cost
14
+
15
+ # Get the sender address.
16
+ attr_accessor :address
17
+
18
+ def initialize(type_id = nil, cost = nil)
19
+ @type_id = type_id
20
+ @cost = cost
21
+ end
22
+ end
23
+ end